Skip to content

Commit 63ea680

Browse files
authored
Move implicit tiling fields to an internal field (#1454)
* Move implicit tiling fields to an internal field * Renming * Change to implicitTilingData * copy -> clone * Simplify function arguments
1 parent 697d7d5 commit 63ea680

2 files changed

Lines changed: 65 additions & 54 deletions

File tree

src/core/plugins/ImplicitTilingPlugin.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ export class ImplicitTilingPlugin {
2121
tile.internal.hasUnrenderableContent = true;
2222
tile.internal.hasRenderableContent = false;
2323

24-
// Declare some properties
25-
tile.__subtreeIdx = 0; // Idx of the tile in its subtree
26-
tile.__implicitRoot = tile; // Keep this tile as an Implicit Root Tile
24+
tile.implicitTilingData = {
25+
// Keep this tile as an Implicit Root Tile
26+
root: tile,
2727

28-
// Coords of the tile
29-
tile.__x = 0;
30-
tile.__y = 0;
31-
tile.__z = 0;
32-
tile.__level = 0;
28+
// Idx of the tile in its subtree
29+
subtreeIdx: 0,
30+
31+
// Coords of the tile
32+
x: 0,
33+
y: 0,
34+
z: 0,
35+
level: 0,
36+
};
3337

3438
} else if ( /.subtree$/i.test( tile.content?.uri ) ) {
3539

@@ -59,10 +63,10 @@ export class ImplicitTilingPlugin {
5963
if ( tile && tile.implicitTiling ) {
6064

6165
const implicitUri = tile.implicitTiling.subtrees.uri
62-
.replace( '{level}', tile.__level )
63-
.replace( '{x}', tile.__x )
64-
.replace( '{y}', tile.__y )
65-
.replace( '{z}', tile.__z );
66+
.replace( '{level}', tile.implicitTilingData.level )
67+
.replace( '{x}', tile.implicitTilingData.x )
68+
.replace( '{y}', tile.implicitTilingData.y )
69+
.replace( '{z}', tile.implicitTilingData.z );
6670

6771
return new URL( implicitUri, tile.internal.basePath + '/' ).toString();
6872

src/core/plugins/SUBTREELoader.js

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LoaderBase, LoaderUtils } from '3d-tiles-renderer/core';
66

77
function isOctreeSubdivision( tile ) {
88

9-
return tile.__implicitRoot.implicitTiling.subdivisionScheme === 'OCTREE';
9+
return tile.implicitTilingData.root.implicitTiling.subdivisionScheme === 'OCTREE';
1010

1111
}
1212

@@ -16,18 +16,21 @@ function getBoundsDivider( tile ) {
1616

1717
}
1818

19-
function getSubtreeCoordinates( tile, parentTile ) {
19+
function getSubtreeCoordinates( parent, subtreeIdx ) {
2020

21-
if ( ! parentTile ) {
21+
if ( ! parent ) {
2222

2323
return [ 0, 0, 0 ];
2424

2525
}
2626

27-
const x = 2 * parentTile.__x + ( tile.__subtreeIdx % 2 );
28-
const y = 2 * parentTile.__y + ( Math.floor( tile.__subtreeIdx / 2 ) % 2 );
29-
const z = isOctreeSubdivision( tile ) ?
30-
2 * parentTile.__z + ( Math.floor( tile.__subtreeIdx / 4 ) % 2 ) : 0;
27+
const parentX = parent.implicitTilingData.x;
28+
const parentY = parent.implicitTilingData.y;
29+
const parentZ = parent.implicitTilingData.z;
30+
31+
const x = 2 * parentX + ( subtreeIdx % 2 );
32+
const y = 2 * parentY + ( Math.floor( subtreeIdx / 2 ) % 2 );
33+
const z = isOctreeSubdivision( parent ) ? 2 * parentZ + ( Math.floor( subtreeIdx / 4 ) % 2 ) : 0;
3134
return [ x, y, z ];
3235

3336
}
@@ -38,26 +41,30 @@ class SubtreeTile {
3841

3942
this.parent = parentTile;
4043
this.children = [];
41-
this.__level = parentTile.__level + 1;
42-
this.__implicitRoot = parentTile.__implicitRoot;
43-
// Index inside the tree
44-
this.__subtreeIdx = childMortonIndex;
45-
[ this.__x, this.__y, this.__z ] = getSubtreeCoordinates( this, parentTile );
44+
this.geometricError = 0;
45+
this.boundingVolume = null;
46+
47+
const [ x, y, z ] = getSubtreeCoordinates( parentTile, childMortonIndex );
48+
this.implicitTilingData = {
49+
level: parentTile.implicitTilingData.level + 1,
50+
root: parentTile.implicitTilingData.root,
51+
subtreeIdx: childMortonIndex,
52+
x, y, z,
53+
};
4654

4755
}
4856

49-
static copy( tile ) {
57+
static clone( tile ) {
5058

51-
const copyTile = {};
52-
copyTile.children = [];
53-
copyTile.__level = tile.__level;
54-
copyTile.__implicitRoot = tile.__implicitRoot;
55-
// Index inside the tree
56-
copyTile.__subtreeIdx = tile.__subtreeIdx;
57-
[ copyTile.__x, copyTile.__y, copyTile.__z ] = [ tile.__x, tile.__y, tile.__z ];
58-
copyTile.boundingVolume = tile.boundingVolume;
59-
copyTile.geometricError = tile.geometricError;
60-
return copyTile;
59+
return {
60+
parent: tile.parent,
61+
children: [],
62+
geometricError: tile.geometricError,
63+
boundingVolume: tile.boundingVolume,
64+
implicitTilingData: {
65+
...tile.implicitTilingData,
66+
},
67+
};
6168

6269
}
6370

@@ -69,7 +76,7 @@ export class SUBTREELoader extends LoaderBase {
6976

7077
super();
7178
this.tile = tile;
72-
this.rootTile = tile.__implicitRoot; // The implicit root tile
79+
this.rootTile = tile.implicitTilingData.root; // The implicit root tile
7380
this.workingPath = null;
7481

7582
}
@@ -533,7 +540,7 @@ export class SUBTREELoader extends LoaderBase {
533540
expandSubtree( subtreeRoot, subtree ) {
534541

535542
// TODO If multiple contents were supported then this tile could contain both renderable and un renderable content.
536-
const contentTile = SubtreeTile.copy( subtreeRoot );
543+
const contentTile = SubtreeTile.clone( subtreeRoot );
537544
// If the subtree root tile has content, then create a placeholder child with cloned parameters
538545
// Todo Multiple contents not handled, keep the first content found
539546
for ( let i = 0; subtree && i < subtree._contentAvailabilityBitstreams.length; i ++ ) {
@@ -718,12 +725,12 @@ export class SUBTREELoader extends LoaderBase {
718725
const maxX = region[ 2 ];
719726
const minY = region[ 1 ];
720727
const maxY = region[ 3 ];
721-
const sizeX = ( maxX - minX ) / Math.pow( 2, tile.__level );
722-
const sizeY = ( maxY - minY ) / Math.pow( 2, tile.__level );
723-
region[ 0 ] = minX + sizeX * tile.__x; //west
724-
region[ 2 ] = minX + sizeX * ( tile.__x + 1 ); //east
725-
region[ 1 ] = minY + sizeY * tile.__y; //south
726-
region[ 3 ] = minY + sizeY * ( tile.__y + 1 ); //north
728+
const sizeX = ( maxX - minX ) / Math.pow( 2, tile.implicitTilingData.level );
729+
const sizeY = ( maxY - minY ) / Math.pow( 2, tile.implicitTilingData.level );
730+
region[ 0 ] = minX + sizeX * tile.implicitTilingData.x; //west
731+
region[ 2 ] = minX + sizeX * ( tile.implicitTilingData.x + 1 ); //east
732+
region[ 1 ] = minY + sizeY * tile.implicitTilingData.y; //south
733+
region[ 3 ] = minY + sizeY * ( tile.implicitTilingData.y + 1 ); //north
727734
for ( let k = 0; k < 4; k ++ ) {
728735

729736
const coord = region[ k ];
@@ -744,9 +751,9 @@ export class SUBTREELoader extends LoaderBase {
744751

745752
const minZ = region[ 4 ];
746753
const maxZ = region[ 5 ];
747-
const sizeZ = ( maxZ - minZ ) / Math.pow( 2, tile.__level );
748-
region[ 4 ] = minZ + sizeZ * tile.__z; //minimum height
749-
region[ 5 ] = minZ + sizeZ * ( tile.__z + 1 ); //maximum height
754+
const sizeZ = ( maxZ - minZ ) / Math.pow( 2, tile.implicitTilingData.level );
755+
region[ 4 ] = minZ + sizeZ * tile.implicitTilingData.z; //minimum height
756+
region[ 5 ] = minZ + sizeZ * ( tile.implicitTilingData.z + 1 ); //maximum height
750757

751758
}
752759

@@ -761,8 +768,8 @@ export class SUBTREELoader extends LoaderBase {
761768
// 6-8: y axis direction and half length
762769
// 9-11: z axis direction and half length
763770
const box = [ ...this.rootTile.boundingVolume.box ];
764-
const cellSteps = 2 ** tile.__level - 1;
765-
const scale = Math.pow( 2, - tile.__level );
771+
const cellSteps = 2 ** tile.implicitTilingData.level - 1;
772+
const scale = Math.pow( 2, - tile.implicitTilingData.level );
766773
const axisNumber = isOctreeSubdivision( tile ) ? 3 : 2;
767774
for ( let i = 0; i < axisNumber; i ++ ) {
768775

@@ -775,7 +782,7 @@ export class SUBTREELoader extends LoaderBase {
775782
const y = box[ 3 + i * 3 + 1 ];
776783
const z = box[ 3 + i * 3 + 2 ];
777784
// adjust the center by the x, y and z axes
778-
const axisOffset = i === 0 ? tile.__x : ( i === 1 ? tile.__y : tile.__z );
785+
const axisOffset = i === 0 ? tile.implicitTilingData.x : ( i === 1 ? tile.implicitTilingData.y : tile.implicitTilingData.z );
779786
box[ 0 ] += 2 * x * ( - 0.5 * cellSteps + axisOffset );
780787
box[ 1 ] += 2 * y * ( - 0.5 * cellSteps + axisOffset );
781788
box[ 2 ] += 2 * z * ( - 0.5 * cellSteps + axisOffset );
@@ -797,7 +804,7 @@ export class SUBTREELoader extends LoaderBase {
797804
*/
798805
getGeometricError( tile ) {
799806

800-
return this.rootTile.geometricError / Math.pow( 2, tile.__level );
807+
return this.rootTile.geometricError / Math.pow( 2, tile.implicitTilingData.level );
801808

802809
}
803810

@@ -856,10 +863,10 @@ export class SUBTREELoader extends LoaderBase {
856863
*/
857864
parseImplicitURI( tile, uri ) {
858865

859-
uri = uri.replace( '{level}', tile.__level );
860-
uri = uri.replace( '{x}', tile.__x );
861-
uri = uri.replace( '{y}', tile.__y );
862-
uri = uri.replace( '{z}', tile.__z );
866+
uri = uri.replace( '{level}', tile.implicitTilingData.level );
867+
uri = uri.replace( '{x}', tile.implicitTilingData.x );
868+
uri = uri.replace( '{y}', tile.implicitTilingData.y );
869+
uri = uri.replace( '{z}', tile.implicitTilingData.z );
863870
return uri;
864871

865872
}

0 commit comments

Comments
 (0)