-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Batch table]
getDataForId
and 3DTILES_batch_table_hierarchy
supp…
…ort (#627) * separate file for BatchTable * add getDataFromId method * add BatchTableHierarchy extension support * use batch table hierarchy extension in example
- Loading branch information
Showing
15 changed files
with
322 additions
and
122 deletions.
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export class BatchTable { | ||
|
||
constructor( | ||
buffer : ArrayBuffer, | ||
batchSize : Number, | ||
start : Number, | ||
headerLength : Number, | ||
binLength : Number | ||
); | ||
|
||
getKeys() : Array< String >; | ||
|
||
getDataFromId( | ||
id: Number, | ||
target?: Object | ||
) : Object; | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { BatchTableHierarchyExtension } from './BatchTableHierarchyExtension.js'; | ||
import { FeatureTable } from './FeatureTable.js'; | ||
|
||
export class BatchTable extends FeatureTable { | ||
|
||
constructor( buffer, batchSize, start, headerLength, binLength ) { | ||
|
||
super( buffer, start, headerLength, binLength ); | ||
this.batchSize = batchSize; | ||
|
||
this.extensions = {}; | ||
const extensions = this.header.extensions; | ||
if ( extensions ) { | ||
|
||
if ( extensions[ '3DTILES_batch_table_hierarchy' ] ) { | ||
|
||
this.extensions[ '3DTILES_batch_table_hierarchy' ] = new BatchTableHierarchyExtension( this ); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
getData( key, componentType = null, type = null ) { | ||
|
||
console.warn( 'BatchTable: BatchTable.getData is deprecated. Use BatchTable.getDataFromId instead.' ); | ||
return super.getData( key, this.batchSize, componentType, type ); | ||
|
||
} | ||
|
||
getDataFromId( id, target = {} ) { | ||
|
||
if ( id < 0 || id >= this.batchSize ) { | ||
|
||
throw new Error( `BatchTable: id value "${ id }" out of bounds for "${ this.batchSize }" features number.` ); | ||
|
||
} | ||
|
||
for ( const key of this.getKeys() ) { | ||
|
||
if ( key !== 'extensions' ) { | ||
|
||
target[ key ] = super.getData( key, this.batchSize )[ id ]; | ||
|
||
} | ||
|
||
} | ||
|
||
for ( const extensionName in this.extensions ) { | ||
|
||
const extension = this.extensions[ extensionName ]; | ||
|
||
if ( extension.getDataFromId instanceof Function ) { | ||
|
||
target[ extensionName ] = target[ extensionName ] || {}; | ||
extension.getDataFromId( id, target[ extensionName ] ); | ||
|
||
} | ||
|
||
} | ||
|
||
return target; | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { parseBinArray } from './FeatureTable.js'; | ||
|
||
export class BatchTableHierarchyExtension { | ||
|
||
constructor( batchTable ) { | ||
|
||
this.batchTable = batchTable; | ||
|
||
const extensionHeader = batchTable.header.extensions[ '3DTILES_batch_table_hierarchy' ]; | ||
|
||
this.classes = extensionHeader.classes; | ||
for ( const classDef of this.classes ) { | ||
|
||
const instances = classDef.instances; | ||
for ( const property in instances ) { | ||
|
||
classDef.instances[ property ] = this._parseProperty( instances[ property ], classDef.length, property ); | ||
|
||
} | ||
|
||
} | ||
|
||
this.instancesLength = extensionHeader.instancesLength; | ||
|
||
this.classIds = this._parseProperty( extensionHeader.classIds, this.instancesLength, 'classIds' ); | ||
|
||
if ( extensionHeader.parentCounts ) { | ||
|
||
this.parentCounts = this._parseProperty( extensionHeader.parentCounts, this.instancesLength, 'parentCounts' ); | ||
|
||
} else { | ||
|
||
this.parentCounts = new Array( this.instancesLength ).fill( 1 ); | ||
|
||
} | ||
|
||
if ( extensionHeader.parentIds ) { | ||
|
||
const parentIdsLength = this.parentCounts.reduce( ( a, b ) => a + b, 0 ); | ||
this.parentIds = this._parseProperty( extensionHeader.parentIds, parentIdsLength, 'parentIds' ); | ||
|
||
} else { | ||
|
||
this.parentIds = null; | ||
|
||
} | ||
|
||
this.instancesIds = []; | ||
const classCounter = {}; | ||
for ( const classId of this.classIds ) { | ||
|
||
classCounter[ classId ] = classCounter[ classId ] ?? 0; | ||
this.instancesIds.push( classCounter[ classId ] ); | ||
classCounter[ classId ] ++; | ||
|
||
} | ||
|
||
} | ||
|
||
_parseProperty( property, propertyLength, propertyName ) { | ||
|
||
if ( Array.isArray( property ) ) { | ||
|
||
return property; | ||
|
||
} else { | ||
|
||
const { buffer, binOffset } = this.batchTable; | ||
|
||
const byteOffset = property.byteOffset; | ||
const componentType = property.componentType || 'UNSIGNED_SHORT'; | ||
|
||
const arrayStart = binOffset + byteOffset; | ||
|
||
return parseBinArray( buffer, arrayStart, propertyLength, 'SCALAR', componentType, propertyName ); | ||
|
||
} | ||
|
||
} | ||
|
||
getDataFromId( id, target = {} ) { | ||
|
||
// Get properties inherited from parents | ||
|
||
const parentCount = this.parentCounts[ id ]; | ||
|
||
if ( this.parentIds && parentCount > 0 ) { | ||
|
||
let parentIdsOffset = 0; | ||
for ( let i = 0; i < id; i ++ ) { | ||
|
||
parentIdsOffset += this.parentCounts[ i ]; | ||
|
||
} | ||
|
||
for ( let i = 0; i < parentCount; i ++ ) { | ||
|
||
const parentId = this.parentIds[ parentIdsOffset + i ]; | ||
if ( parentId !== id ) { | ||
|
||
this.getDataFromId( parentId, target ); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
// Get properties proper to this instance | ||
|
||
const classId = this.classIds[ id ]; | ||
const instances = this.classes[ classId ].instances; | ||
const className = this.classes[ classId ].name; | ||
const instanceId = this.instancesIds[ id ]; | ||
|
||
for ( const key in instances ) { | ||
|
||
target[ className ] = target[ className ] || {}; | ||
target[ className ][ key ] = instances[ key ][ instanceId ]; | ||
|
||
} | ||
|
||
return target; | ||
|
||
} | ||
|
||
} |
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
Oops, something went wrong.