|
@@ -18,6 +18,7 @@ export const RELATIVE_DEPTH = 5;
|
|
export const IS_LEAF = 6;
|
|
export const IS_LEAF = 6;
|
|
export const RANDOM_COLOR = 7;
|
|
export const RANDOM_COLOR = 7;
|
|
export const RANDOM_NODE_COLOR = 8;
|
|
export const RANDOM_NODE_COLOR = 8;
|
|
|
|
+export const CUSTOM_COLOR_MODE = 9;
|
|
|
|
|
|
export class DebugTilesRenderer extends TilesRenderer {
|
|
export class DebugTilesRenderer extends TilesRenderer {
|
|
|
|
|
|
@@ -37,6 +38,7 @@ export class DebugTilesRenderer extends TilesRenderer {
|
|
this.displayBoxBounds = false;
|
|
this.displayBoxBounds = false;
|
|
this.displaySphereBounds = false;
|
|
this.displaySphereBounds = false;
|
|
this.colorMode = NONE;
|
|
this.colorMode = NONE;
|
|
|
|
+ this.customColorCallback = null;
|
|
this.boxGroup = boxGroup;
|
|
this.boxGroup = boxGroup;
|
|
this.sphereGroup = sphereGroup;
|
|
this.sphereGroup = sphereGroup;
|
|
this.maxDebugDepth = - 1;
|
|
this.maxDebugDepth = - 1;
|
|
@@ -351,6 +353,20 @@ export class DebugTilesRenderer extends TilesRenderer {
|
|
break;
|
|
break;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ case CUSTOM_COLOR_MODE: {
|
|
|
|
+
|
|
|
|
+ if ( this.customColorCallback ) {
|
|
|
|
+
|
|
|
|
+ this.customColorCallback( tile, c );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ console.warn( 'DebugTilesRenderer: customColorCallback not defined' );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -374,16 +390,33 @@ export class DebugTilesRenderer extends TilesRenderer {
|
|
|
|
|
|
if ( ! visible ) {
|
|
if ( ! visible ) {
|
|
|
|
|
|
- boxGroup.remove( boxHelperGroup );
|
|
|
|
- sphereGroup.remove( sphereHelper );
|
|
|
|
|
|
+ if ( boxHelperGroup ) {
|
|
|
|
+
|
|
|
|
+ boxGroup.remove( boxHelperGroup );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( sphereHelper ) {
|
|
|
|
+
|
|
|
|
+ sphereGroup.remove( sphereHelper );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- boxGroup.add( boxHelperGroup );
|
|
|
|
- boxHelperGroup.updateMatrixWorld( true );
|
|
|
|
|
|
+ if ( boxHelperGroup ) {
|
|
|
|
+
|
|
|
|
+ boxGroup.add( boxHelperGroup );
|
|
|
|
+ boxHelperGroup.updateMatrixWorld( true );
|
|
|
|
|
|
- sphereGroup.add( sphereHelper );
|
|
|
|
- sphereHelper.updateMatrixWorld( true );
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( sphereHelper ) {
|
|
|
|
+
|
|
|
|
+ sphereGroup.add( sphereHelper );
|
|
|
|
+ sphereHelper.updateMatrixWorld( true );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -399,40 +432,48 @@ export class DebugTilesRenderer extends TilesRenderer {
|
|
const scene = cached.scene;
|
|
const scene = cached.scene;
|
|
if ( scene ) {
|
|
if ( scene ) {
|
|
|
|
|
|
- const cachedBox = cached.box;
|
|
|
|
- const cachedBoxMat = cached.boxTransform;
|
|
|
|
|
|
+ if ( cached.box && cached.boxTransform ) {
|
|
|
|
|
|
- // Create debug bounding box
|
|
|
|
- // In some cases the bounding box may have a scale of 0 in one dimension resulting
|
|
|
|
- // in the NaNs in an extracted rotation so we disable matrix updates instead.
|
|
|
|
- const boxHelperGroup = new Group();
|
|
|
|
- boxHelperGroup.name = 'DebugTilesRenderer.boxHelperGroup';
|
|
|
|
- boxHelperGroup.matrix.copy( cachedBoxMat );
|
|
|
|
- boxHelperGroup.matrixAutoUpdate = false;
|
|
|
|
|
|
+ const cachedBox = cached.box;
|
|
|
|
+ const cachedBoxMat = cached.boxTransform;
|
|
|
|
|
|
- const boxHelper = new Box3Helper( cachedBox, getIndexedRandomColor( tile.__depth ) );
|
|
|
|
- boxHelper.raycast = emptyRaycast;
|
|
|
|
- boxHelperGroup.add( boxHelper );
|
|
|
|
|
|
+ // Create debug bounding box
|
|
|
|
+ // In some cases the bounding box may have a scale of 0 in one dimension resulting
|
|
|
|
+ // in the NaNs in an extracted rotation so we disable matrix updates instead.
|
|
|
|
+ const boxHelperGroup = new Group();
|
|
|
|
+ boxHelperGroup.name = 'DebugTilesRenderer.boxHelperGroup';
|
|
|
|
+ boxHelperGroup.matrix.copy( cachedBoxMat );
|
|
|
|
+ boxHelperGroup.matrixAutoUpdate = false;
|
|
|
|
|
|
- cached.boxHelperGroup = boxHelperGroup;
|
|
|
|
|
|
+ const boxHelper = new Box3Helper( cachedBox, getIndexedRandomColor( tile.__depth ) );
|
|
|
|
+ boxHelper.raycast = emptyRaycast;
|
|
|
|
+ boxHelperGroup.add( boxHelper );
|
|
|
|
|
|
- if ( this.visibleTiles.has( tile ) && this.displayBoxBounds ) {
|
|
|
|
|
|
+ cached.boxHelperGroup = boxHelperGroup;
|
|
|
|
|
|
- this.boxGroup.add( boxHelperGroup );
|
|
|
|
- boxHelperGroup.updateMatrixWorld( true );
|
|
|
|
|
|
+ if ( this.visibleTiles.has( tile ) && this.displayBoxBounds ) {
|
|
|
|
+
|
|
|
|
+ this.boxGroup.add( boxHelperGroup );
|
|
|
|
+ boxHelperGroup.updateMatrixWorld( true );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- // Create debugbounding sphere
|
|
|
|
- const cachedSphere = cached.sphere;
|
|
|
|
- const sphereHelper = new SphereHelper( cachedSphere );
|
|
|
|
- sphereHelper.raycast = emptyRaycast;
|
|
|
|
- cached.sphereHelper = sphereHelper;
|
|
|
|
|
|
+ if ( cached.sphere ) {
|
|
|
|
+
|
|
|
|
+ // Create debugbounding sphere
|
|
|
|
+ const cachedSphere = cached.sphere;
|
|
|
|
+ const sphereHelper = new SphereHelper( cachedSphere );
|
|
|
|
+ sphereHelper.raycast = emptyRaycast;
|
|
|
|
+ cached.sphereHelper = sphereHelper;
|
|
|
|
|
|
- if ( this.visibleTiles.has( tile ) && this.displaySphereBounds ) {
|
|
|
|
|
|
+ if ( this.visibleTiles.has( tile ) && this.displaySphereBounds ) {
|
|
|
|
|
|
- this.sphereGroup.add( sphereHelper );
|
|
|
|
- sphereHelper.updateMatrixWorld( true );
|
|
|
|
|
|
+ this.sphereGroup.add( sphereHelper );
|
|
|
|
+ sphereHelper.updateMatrixWorld( true );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -462,9 +503,13 @@ export class DebugTilesRenderer extends TilesRenderer {
|
|
if ( cached.boxHelperGroup ) {
|
|
if ( cached.boxHelperGroup ) {
|
|
|
|
|
|
cached.boxHelperGroup.children[ 0 ].geometry.dispose();
|
|
cached.boxHelperGroup.children[ 0 ].geometry.dispose();
|
|
- cached.sphereHelper.geometry.dispose();
|
|
|
|
-
|
|
|
|
delete cached.boxHelperGroup;
|
|
delete cached.boxHelperGroup;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( cached.sphereHelper ) {
|
|
|
|
+
|
|
|
|
+ cached.sphereHelper.geometry.dispose();
|
|
delete cached.sphereHelper;
|
|
delete cached.sphereHelper;
|
|
|
|
|
|
}
|
|
}
|