Skip to content

Commit e6c7e8f

Browse files
authored
[Batch table] getDataForId and 3DTILES_batch_table_hierarchy support (#627)
* separate file for BatchTable * add getDataFromId method * add BatchTableHierarchy extension support * use batch table hierarchy extension in example
1 parent 8237b94 commit e6c7e8f

15 files changed

+322
-122
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,8 @@ if ( intersects.length ) {
286286
// Log the batch data
287287
const batchTable = batchTableObject.batchTable;
288288
const hoveredBatchid = batchidAttr.getX( face.a );
289-
const batchData = batchTable.getData( 'BatchTableKey' );
290-
if ( batchData ) {
291-
292-
console.log( batchData[ hoveredBatchid ] );
293-
294-
}
289+
const batchData = batchTable.getDataFromId( hoveredBatchid );
290+
console.log( batchData );
295291

296292
}
297293

example/b3dmExample.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function init() {
119119
scene.add( offsetGroup );
120120

121121
new B3DMLoader()
122-
.loadAsync( 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/main/1.0/TilesetWithRequestVolume/city/lr.b3dm' )
122+
.loadAsync( 'https://raw.githubusercontent.com/CesiumGS/cesium/main/Apps/SampleData/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tile.b3dm' )
123123
.then( res => {
124124

125125
console.log( res );
@@ -186,12 +186,25 @@ function onMouseMove( e ) {
186186
// Log the batch data
187187
const batchTable = batchTableObject.batchTable;
188188
hoveredBatchid = batchidAttr.getX( face.a );
189+
const batchData = batchTable.getDataFromId( hoveredBatchid );
189190

190191
infoEl.innerText =
191-
`_batchid : ${ hoveredBatchid }\n` +
192-
`Latitude : ${ batchTable.getData( 'Latitude' )[ hoveredBatchid ].toFixed( 3 ) }\n` +
193-
`Longitude : ${ batchTable.getData( 'Longitude' )[ hoveredBatchid ].toFixed( 3 ) }\n` +
194-
`Height : ${ batchTable.getData( 'Height' )[ hoveredBatchid ].toFixed( 3 ) }\n`;
192+
`_batchid : ${ hoveredBatchid }\n` +
193+
`Area : ${ batchData[ 'height' ].toFixed( 3 ) }\n` +
194+
`Height : ${ batchData[ 'height' ].toFixed( 3 ) }\n`;
195+
196+
const hierarchyData = batchData[ '3DTILES_batch_table_hierarchy' ];
197+
for ( const className in hierarchyData ) {
198+
199+
200+
for ( const instance in hierarchyData[ className ] ) {
201+
202+
infoEl.innerText +=
203+
`${ instance } : ${ hierarchyData[ className ][ instance ] }\n`;
204+
205+
}
206+
207+
}
195208

196209
}
197210

src/base/loaders/B3DMLoaderBase.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable';
1+
import { BatchTable } from '../../utilities/BatchTable';
2+
import { FeatureTable } from '../../utilities/FeatureTable';
23

34
export interface B3DMBaseResult {
45

src/base/loaders/B3DMLoaderBase.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// B3DM File Format
22
// https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/Batched3DModel/README.md
33

4-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable.js';
4+
import { BatchTable } from '../../utilities/BatchTable.js';
5+
import { FeatureTable } from '../../utilities/FeatureTable.js';
56
import { LoaderBase } from './LoaderBase.js';
67
import { readMagicBytes } from '../../utilities/readMagicBytes.js';
78

src/base/loaders/I3DMLoaderBase.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable';
1+
import { BatchTable } from '../../utilities/BatchTable';
2+
import { FeatureTable } from '../../utilities/FeatureTable';
23

34
export interface I3DMBaseResult {
45

src/base/loaders/I3DMLoaderBase.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// I3DM File Format
22
// https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/Instanced3DModel/README.md
33

4-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable.js';
4+
import { BatchTable } from '../../utilities/BatchTable.js';
5+
import { FeatureTable } from '../../utilities/FeatureTable.js';
56
import { arrayToString } from '../../utilities/arrayToString.js';
67
import { LoaderBase } from './LoaderBase.js';
78
import { readMagicBytes } from '../../utilities/readMagicBytes.js';

src/base/loaders/PNTSLoaderBase.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable';
1+
import { BatchTable } from '../../utilities/BatchTable';
2+
import { FeatureTable } from '../../utilities/FeatureTable';
23

34
export interface PNTSBaseResult {
45

src/base/loaders/PNTSLoaderBase.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// PNTS File Format
22
// https://github.com/CesiumGS/3d-tiles/blob/master/specification/TileFormats/PointCloud/README.md
33

4-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable.js';
4+
import { BatchTable } from '../../utilities/BatchTable.js';
5+
import { FeatureTable } from '../../utilities/FeatureTable.js';
56
import { readMagicBytes } from '../../utilities/readMagicBytes.js';
67
import { LoaderBase } from './LoaderBase.js';
78

src/three/loaders/B3DMLoader.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { B3DMBaseResult } from '../../base/loaders/B3DMLoaderBase';
2-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable';
2+
import { BatchTable } from '../../utilities/BatchTable';
3+
import { FeatureTable } from '../../utilities/FeatureTable';
34
import { LoadingManager, Group } from 'three';
45
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
56

src/three/loaders/I3DMLoader.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { I3DMBaseResult } from '../../base/loaders/I3DMLoaderBase';
2-
import { FeatureTable, BatchTable } from '../../utilities/FeatureTable';
2+
import { BatchTable } from '../../utilities/BatchTable';
3+
import { FeatureTable } from '../../utilities/FeatureTable';
34
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
45
import { Group, LoadingManager } from 'three';
56

0 commit comments

Comments
 (0)