99 IS_LEAF ,
1010 RANDOM_COLOR ,
1111 RANDOM_NODE_COLOR ,
12+ CUSTOM_COLOR_MODE
1213} from '../src/index.js' ;
1314import {
1415 Scene ,
@@ -27,6 +28,7 @@ import {
2728 TorusBufferGeometry ,
2829 OrthographicCamera ,
2930 sRGBEncoding ,
31+ Sphere ,
3032} from 'three' ;
3133import { FlyOrbitControls } from './FlyOrbitControls.js' ;
3234import { BufferGeometryUtils } from 'three/examples/jsm/utils/BufferGeometryUtils.js' ;
@@ -43,7 +45,7 @@ let camera, controls, scene, renderer, tiles, cameraHelper;
4345let thirdPersonCamera , thirdPersonRenderer , thirdPersonControls ;
4446let secondRenderer , secondCameraHelper , secondControls , secondCamera ;
4547let orthoCamera , orthoCameraHelper ;
46- let box ;
48+ let box , sphere ;
4749let raycaster , mouse , rayIntersect , lastHoveredElement ;
4850let offsetParent ;
4951let statsContainer , stats ;
@@ -102,6 +104,23 @@ function reinstantiateTiles() {
102104 tiles . manager . addHandler ( / \. g l t f $ / , loader ) ;
103105 offsetParent . add ( tiles . group ) ;
104106
107+ // Used with CUSTOM_COLOR_MODE
108+ tiles . customColorCallback = ( tile , object ) => {
109+
110+ const depthIsEven = tile . __depth % 2 === 0 ;
111+ const hex = depthIsEven ? 0xff0000 : 0xffffff ;
112+ object . traverse ( c => {
113+
114+ if ( c . isMesh ) {
115+
116+ c . material . color . set ( hex ) ;
117+
118+ }
119+
120+ } ) ;
121+
122+ } ;
123+
105124}
106125
107126function init ( ) {
@@ -190,6 +209,7 @@ function init() {
190209 scene . add ( ambLight ) ;
191210
192211 box = new Box3 ( ) ;
212+ sphere = new Sphere ( ) ;
193213
194214 offsetParent = new Group ( ) ;
195215 scene . add ( offsetParent ) ;
@@ -253,6 +273,7 @@ function init() {
253273 IS_LEAF ,
254274 RANDOM_COLOR ,
255275 RANDOM_NODE_COLOR ,
276+ CUSTOM_COLOR_MODE
256277
257278 } ) ;
258279 debug . open ( ) ;
@@ -497,6 +518,11 @@ function animate() {
497518 box . getCenter ( tiles . group . position ) ;
498519 tiles . group . position . multiplyScalar ( - 1 ) ;
499520
521+ } else if ( tiles . getBoundingSphere ( sphere ) ) {
522+
523+ tiles . group . position . copy ( sphere . center ) ;
524+ tiles . group . position . multiplyScalar ( - 1 ) ;
525+
500526 }
501527
502528 if ( parseFloat ( params . raycast ) !== NONE && lastHoveredElement !== null ) {
0 commit comments