Skip to content

Commit 2b8b413

Browse files
committed
DebugTilesPlugin: Add mesh boundary to "box helpers"
1 parent 26f3d74 commit 2b8b413

1 file changed

Lines changed: 38 additions & 16 deletions

File tree

src/three/plugins/DebugTilesPlugin.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box3Helper, Group, MeshStandardMaterial, PointsMaterial, Sphere, Color, MeshBasicMaterial } from 'three';
1+
import { Box3Helper, Group, MeshStandardMaterial, PointsMaterial, Sphere, Color, MeshBasicMaterial, Mesh, BoxGeometry, DoubleSide } from 'three';
22
import { SphereHelper } from './objects/SphereHelper.js';
33
import { EllipsoidRegionLineHelper } from './objects/EllipsoidRegionHelper.js';
44
import { TraversalUtils } from '3d-tiles-renderer/core';
@@ -658,12 +658,23 @@ export class DebugTilesPlugin {
658658
boxHelperGroup.name = 'DebugTilesRenderer.boxHelperGroup';
659659
boxHelperGroup.matrix.copy( obb.transform );
660660
boxHelperGroup.matrixAutoUpdate = false;
661+
engineData.boxHelperGroup = boxHelperGroup;
661662

662663
const boxHelper = new Box3Helper( obb.box, getIndexedRandomColor( tile.internal.depth ) );
663664
boxHelper.raycast = emptyRaycast;
664665
boxHelperGroup.add( boxHelper );
665666

666-
engineData.boxHelperGroup = boxHelperGroup;
667+
const mesh = new Mesh( new BoxGeometry(), new MeshBasicMaterial( {
668+
color: getIndexedRandomColor( tile.internal.depth ),
669+
transparent: true,
670+
depthWrite: false,
671+
opacity: 0.05,
672+
side: DoubleSide,
673+
} ) );
674+
obb.box.getSize( mesh.scale );
675+
mesh.raycast = emptyRaycast;
676+
boxHelperGroup.add( mesh );
677+
667678

668679
if ( tiles.visibleTiles.has( tile ) && this.displayBoxBounds ) {
669680

@@ -717,25 +728,36 @@ export class DebugTilesPlugin {
717728

718729
}
719730

720-
_updateHelperMaterial( tile, material ) {
731+
_updateHelperMaterials( tile, group ) {
721732

722-
if ( tile.traversal.visible || ! this.displayParentBounds ) {
733+
group.traverse( c => {
723734

724-
material.opacity = 1;
735+
const { material } = c;
736+
if ( ! material ) {
725737

726-
} else {
738+
return;
727739

728-
material.opacity = 0.2;
740+
}
729741

730-
}
742+
if ( tile.traversal.visible || ! this.displayParentBounds ) {
731743

732-
const transparent = material.transparent;
733-
material.transparent = material.opacity < 1;
734-
if ( material.transparent !== transparent ) {
744+
material.opacity = c.isMesh ? 0.05 : 1;
735745

736-
material.needsUpdate = true;
746+
} else {
737747

738-
}
748+
material.opacity = c.isMesh ? 0.01 : 0.2;
749+
750+
}
751+
752+
const transparent = material.transparent;
753+
material.transparent = material.opacity < 1;
754+
if ( material.transparent !== transparent ) {
755+
756+
material.needsUpdate = true;
757+
758+
}
759+
760+
} );
739761

740762
}
741763

@@ -791,7 +813,7 @@ export class DebugTilesPlugin {
791813
boxGroup.add( boxHelperGroup );
792814
boxHelperGroup.updateMatrixWorld( true );
793815

794-
this._updateHelperMaterial( tile, boxHelperGroup.children[ 0 ].material );
816+
this._updateHelperMaterials( tile, boxHelperGroup );
795817

796818
}
797819

@@ -800,7 +822,7 @@ export class DebugTilesPlugin {
800822
sphereGroup.add( sphereHelper );
801823
sphereHelper.updateMatrixWorld( true );
802824

803-
this._updateHelperMaterial( tile, sphereHelper.material );
825+
this._updateHelperMaterials( tile, sphereHelper );
804826

805827
}
806828

@@ -809,7 +831,7 @@ export class DebugTilesPlugin {
809831
regionGroup.add( regionHelper );
810832
regionHelper.updateMatrixWorld( true );
811833

812-
this._updateHelperMaterial( tile, regionHelper.material );
834+
this._updateHelperMaterials( tile, regionHelper );
813835

814836
}
815837

0 commit comments

Comments
 (0)