@@ -60,6 +60,8 @@ export class DebugTilesPlugin {
60
60
this . name = 'DEBUG_TILES_PLUGIN' ;
61
61
this . tiles = null ;
62
62
63
+ this . _enabled = true ;
64
+
63
65
this . extremeDebugDepth = - 1 ;
64
66
this . extremeDebugError = - 1 ;
65
67
this . boxGroup = null ;
@@ -84,6 +86,36 @@ export class DebugTilesPlugin {
84
86
85
87
}
86
88
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
+
87
119
// initialize the groups for displaying helpers, register events, and initialize existing tiles
88
120
init ( tiles ) {
89
121
@@ -109,31 +141,48 @@ export class DebugTilesPlugin {
109
141
// register events
110
142
this . _onLoadTileSetCB = ( ) => {
111
143
112
- this . _initExtremes ( ) ;
144
+ if ( this . enabled ) {
145
+
146
+ this . _initExtremes ( ) ;
147
+
148
+ }
113
149
114
150
} ;
115
151
116
152
this . _onLoadModelCB = ( { scene, tile } ) => {
117
153
118
- this . _onLoadModel ( scene , tile ) ;
154
+ if ( this . enabled ) {
155
+
156
+ this . _onLoadModel ( scene , tile ) ;
157
+
158
+ }
119
159
120
160
} ;
121
161
122
162
this . _onDisposeModelCB = ( { tile } ) => {
123
163
164
+ // Note that we want to cleanup memory even if the plugin is disabled.
124
165
this . _onDisposeModel ( tile ) ;
125
166
126
167
} ;
127
168
128
169
this . _onUpdateAfterCB = ( ) => {
129
170
130
- this . _onUpdateAfter ( ) ;
171
+ if ( this . enabled ) {
172
+
173
+ this . _onUpdateAfter ( ) ;
174
+
175
+ }
131
176
132
177
} ;
133
178
134
179
this . _onTileVisibilityChangeCB = ( { scene, tile, visible } ) => {
135
180
136
- this . _onTileVisibilityChange ( tile , visible ) ;
181
+ if ( this . enabled ) {
182
+
183
+ this . _onTileVisibilityChange ( tile , visible ) ;
184
+
185
+ }
137
186
138
187
} ;
139
188
@@ -143,6 +192,8 @@ export class DebugTilesPlugin {
143
192
tiles . addEventListener ( 'update-after' , this . _onUpdateAfterCB ) ;
144
193
tiles . addEventListener ( 'tile-visibility-change' , this . _onTileVisibilityChangeCB ) ;
145
194
195
+ this . _initExtremes ( ) ;
196
+
146
197
// initialize an already-loaded tiles
147
198
tiles . traverse ( tile => {
148
199
@@ -215,11 +266,19 @@ export class DebugTilesPlugin {
215
266
216
267
_initExtremes ( ) {
217
268
269
+ if ( ! ( this . tiles && this . tiles . root ) ) {
270
+
271
+ return ;
272
+
273
+ }
274
+
218
275
// initialize the extreme values of the hierarchy
219
276
let maxDepth = - 1 ;
220
277
let maxError = - 1 ;
221
278
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 ) => {
223
282
224
283
maxDepth = Math . max ( maxDepth , depth ) ;
225
284
maxError = Math . max ( maxError , tile . geometricError ) ;
0 commit comments