Skip to content

Commit 7e6ae37

Browse files
committed
feat(DebugTilesPlugin): allow toggling the plugin (#647)
1 parent a25a729 commit 7e6ae37

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

src/plugins/three/DebugTilesPlugin.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const RANDOM_NODE_COLOR: ColorMode;
1414
export const CUSTOM_COLOR: ColorMode;
1515
export class DebugTilesPlugin {
1616

17+
enabled: boolean;
18+
1719
displayBoxBounds : boolean;
1820
displaySphereBounds : boolean;
1921
displayRegionBounds : boolean;

src/plugins/three/DebugTilesPlugin.js

+64-5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export class DebugTilesPlugin {
6060
this.name = 'DEBUG_TILES_PLUGIN';
6161
this.tiles = null;
6262

63+
this._enabled = true;
64+
6365
this.extremeDebugDepth = - 1;
6466
this.extremeDebugError = - 1;
6567
this.boxGroup = null;
@@ -84,6 +86,36 @@ export class DebugTilesPlugin {
8486

8587
}
8688

89+
get enabled() {
90+
91+
return this._enabled;
92+
93+
}
94+
95+
set enabled( v ) {
96+
97+
if ( v !== this._enabled ) {
98+
99+
this._enabled = v;
100+
101+
if ( this._enabled ) {
102+
103+
if ( this.tiles ) {
104+
105+
this.init( this.tiles );
106+
107+
}
108+
109+
} else {
110+
111+
this.dispose();
112+
113+
}
114+
115+
}
116+
117+
}
118+
87119
// initialize the groups for displaying helpers, register events, and initialize existing tiles
88120
init( tiles ) {
89121

@@ -109,31 +141,48 @@ export class DebugTilesPlugin {
109141
// register events
110142
this._onLoadTileSetCB = () => {
111143

112-
this._initExtremes();
144+
if ( this.enabled ) {
145+
146+
this._initExtremes();
147+
148+
}
113149

114150
};
115151

116152
this._onLoadModelCB = ( { scene, tile } ) => {
117153

118-
this._onLoadModel( scene, tile );
154+
if ( this.enabled ) {
155+
156+
this._onLoadModel( scene, tile );
157+
158+
}
119159

120160
};
121161

122162
this._onDisposeModelCB = ( { tile } ) => {
123163

164+
// Note that we want to cleanup memory even if the plugin is disabled.
124165
this._onDisposeModel( tile );
125166

126167
};
127168

128169
this._onUpdateAfterCB = () => {
129170

130-
this._onUpdateAfter();
171+
if ( this.enabled ) {
172+
173+
this._onUpdateAfter();
174+
175+
}
131176

132177
};
133178

134179
this._onTileVisibilityChangeCB = ( { scene, tile, visible } ) => {
135180

136-
this._onTileVisibilityChange( tile, visible );
181+
if ( this.enabled ) {
182+
183+
this._onTileVisibilityChange( tile, visible );
184+
185+
}
137186

138187
};
139188

@@ -143,6 +192,8 @@ export class DebugTilesPlugin {
143192
tiles.addEventListener( 'update-after', this._onUpdateAfterCB );
144193
tiles.addEventListener( 'tile-visibility-change', this._onTileVisibilityChangeCB );
145194

195+
this._initExtremes();
196+
146197
// initialize an already-loaded tiles
147198
tiles.traverse( tile => {
148199

@@ -215,11 +266,19 @@ export class DebugTilesPlugin {
215266

216267
_initExtremes() {
217268

269+
if ( ! ( this.tiles && this.tiles.root ) ) {
270+
271+
return;
272+
273+
}
274+
218275
// initialize the extreme values of the hierarchy
219276
let maxDepth = - 1;
220277
let maxError = - 1;
221278

222-
traverseSet( this.tiles.root, null, ( tile, parent, depth ) => {
279+
// Note that we are not using this.tiles.traverse()
280+
// as we don't want to pay the cost of preprocessing tiles.
281+
traverseSet( this.tiles.root, null, ( tile, _, depth ) => {
223282

224283
maxDepth = Math.max( maxDepth, depth );
225284
maxError = Math.max( maxError, tile.geometricError );

0 commit comments

Comments
 (0)