-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Draco PNTS proposal alternative #329
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b1670ec
support draco
Gmadges b00fdac
Merge branch 'master' into PNTS-draco-support
Gmadges 5d1a656
update readme
Gmadges 4cd6fed
fix lint
Gmadges a8fa727
clearer name
Gmadges c8bcfc5
Consolidate draco changes to PNTSLoader
gkjohnson 1a227bd
Update dts
gkjohnson 1f69a92
Fixes
gkjohnson 2a1077c
Final fixes?
gkjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,21 @@ const tilesRenderer = new TilesRenderer( './path/to/tileset.json' ); | |
tilesRenderer.manager.addHandler( /\.gltf$/, loader ); | ||
``` | ||
|
||
Adding support for DRACO decompression within the PNTS files. | ||
|
||
```js | ||
|
||
// Note the DRACO compression files need to be supplied via an explicit source. | ||
// We use unpkg here but in practice should be provided by the application. | ||
const dracoLoader = new DRACOLoader(); | ||
dracoLoader.setDecoderPath( 'https://unpkg.com/[email protected]/examples/js/libs/draco/gltf/' ); | ||
|
||
|
||
const tilesRenderer = new TilesRenderer( './path/to/tileset.json' ); | ||
tilesRenderer.manager.addHandler( /\.drc$/, loader ); | ||
``` | ||
|
||
|
||
## Loading from Cesium Ion | ||
|
||
Loading from Cesium Ion requires some extra fetching of the ion url endpoint, as well as a temporary bearer access token. A full example is found in the ionExample.js file in the examples folder. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
import { PNTSLoaderBase } from '../base/PNTSLoaderBase.js'; | ||
import { Points, PointsMaterial, BufferGeometry, BufferAttribute, DefaultLoadingManager } from 'three'; | ||
import { | ||
Points, | ||
PointsMaterial, | ||
BufferGeometry, | ||
BufferAttribute, | ||
DefaultLoadingManager, | ||
} from 'three'; | ||
|
||
const DRACO_ATTRIBUTE_MAP = { | ||
RGB: 'color', | ||
POSITION: 'position', | ||
}; | ||
|
||
export class PNTSLoader extends PNTSLoaderBase { | ||
|
||
|
@@ -12,68 +23,115 @@ export class PNTSLoader extends PNTSLoaderBase { | |
|
||
parse( buffer ) { | ||
|
||
return super | ||
.parse( buffer ) | ||
.then( result => { | ||
return super.parse( buffer ).then( async ( result ) => { | ||
|
||
const { featureTable } = result; | ||
const { featureTable } = result; | ||
|
||
const POINTS_LENGTH = featureTable.getData( 'POINTS_LENGTH' ); | ||
const POSITION = featureTable.getData( 'POSITION', POINTS_LENGTH, 'FLOAT', 'VEC3' ); | ||
const RGB = featureTable.getData( 'RGB', POINTS_LENGTH, 'UNSIGNED_BYTE', 'VEC3' ); | ||
const material = new PointsMaterial(); | ||
const extensions = featureTable.header.extensions; | ||
let geometry; | ||
|
||
// handle loading the draco data | ||
if ( extensions && extensions[ '3DTILES_draco_point_compression' ] ) { | ||
|
||
const { byteOffset, byteLength, properties } = extensions[ '3DTILES_draco_point_compression' ]; | ||
const dracoLoader = this.manager.getHandler( 'draco.drc' ); | ||
if ( dracoLoader == null ) { | ||
|
||
throw new Error( 'PNTSLoader: dracoLoader not available.' ); | ||
|
||
} | ||
|
||
[ | ||
'QUANTIZED_VOLUME_OFFSET', | ||
'QUANTIZED_VOLUME_SCALE', | ||
'CONSTANT_RGBA', | ||
'BATCH_LENGTH', | ||
'POSITION_QUANTIZED', | ||
'RGBA', | ||
'RGB565', | ||
'NORMAL', | ||
'NORMAL_OCT16P', | ||
].forEach( feature => { | ||
// map PNTS keys to draco types | ||
const attributeIDs = {}; | ||
for ( const key in properties ) { | ||
|
||
if ( feature in featureTable.header ) { | ||
if ( key in DRACO_ATTRIBUTE_MAP && key in properties ) { | ||
|
||
console.warn( `PNTSLoader: Unsupported FeatureTable feature "${ feature }" detected.` ); | ||
const mappedKey = DRACO_ATTRIBUTE_MAP[ key ]; | ||
attributeIDs[ mappedKey ] = properties[ key ]; | ||
|
||
} | ||
|
||
} ); | ||
} | ||
|
||
// decode the geometry | ||
const taskConfig = { | ||
attributeIDs, | ||
attributeTypes: { | ||
position: 'Float32Array', | ||
color: 'Uint8Array', | ||
}, | ||
useUniqueIDs: true, | ||
}; | ||
|
||
const buffer = featureTable.getDracoBuffer( byteOffset, byteLength ); | ||
geometry = await dracoLoader.decodeGeometry( buffer, taskConfig ); | ||
geometry.copy( dracoGeometry ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This copy isn't required anymore |
||
if ( geometry.attributes.color ) { | ||
|
||
const geometry = new BufferGeometry(); | ||
geometry.setAttribute( 'position', new BufferAttribute( POSITION, 3, false ) ); | ||
material.vertexColors = true; | ||
|
||
} | ||
|
||
const material = new PointsMaterial(); | ||
material.size = 2; | ||
material.sizeAttenuation = false; | ||
} else { | ||
|
||
// handle non compressed case | ||
const POINTS_LENGTH = featureTable.getData( 'POINTS_LENGTH' ); | ||
const POSITION = featureTable.getData( 'POSITION', POINTS_LENGTH, 'FLOAT', 'VEC3' ); | ||
const RGB = featureTable.getData( 'RGB', POINTS_LENGTH, 'UNSIGNED_BYTE', 'VEC3' ); | ||
|
||
geometry = new BufferGeometry(); | ||
geometry.setAttribute( 'position', new BufferAttribute( POSITION, 3, false ) ); | ||
if ( RGB !== null ) { | ||
|
||
geometry.setAttribute( 'color', new BufferAttribute( RGB, 3, true ) ); | ||
material.vertexColors = true; | ||
|
||
} | ||
|
||
const object = new Points( geometry, material ); | ||
result.scene = object; | ||
result.scene.featureTable = featureTable; | ||
} | ||
|
||
const rtcCenter = featureTable.getData( 'RTC_CENTER' ); | ||
[ | ||
'QUANTIZED_VOLUME_OFFSET', | ||
'QUANTIZED_VOLUME_SCALE', | ||
'CONSTANT_RGBA', | ||
'BATCH_LENGTH', | ||
'POSITION_QUANTIZED', | ||
'RGBA', | ||
'RGB565', | ||
'NORMAL', | ||
'NORMAL_OCT16P', | ||
].forEach( ( feature ) => { | ||
|
||
if ( rtcCenter ) { | ||
if ( feature in featureTable.header ) { | ||
|
||
result.scene.position.x += rtcCenter[ 0 ]; | ||
result.scene.position.y += rtcCenter[ 1 ]; | ||
result.scene.position.z += rtcCenter[ 2 ]; | ||
console.warn( | ||
`PNTSLoader: Unsupported FeatureTable feature "${feature}" detected.` | ||
); | ||
|
||
} | ||
|
||
return result; | ||
|
||
} ); | ||
|
||
const object = new Points( geometry, material ); | ||
result.scene = object; | ||
result.scene.featureTable = featureTable; | ||
|
||
const rtcCenter = featureTable.getData( 'RTC_CENTER' ); | ||
|
||
if ( rtcCenter ) { | ||
|
||
result.scene.position.x += rtcCenter[ 0 ]; | ||
result.scene.position.y += rtcCenter[ 1 ]; | ||
result.scene.position.z += rtcCenter[ 2 ]; | ||
|
||
} | ||
|
||
return result; | ||
|
||
} ); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDracoBuffer
->getBuffer