Skip to content

Commit

Permalink
feat(DebugTilesPlugin): allow toggling the plugin (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguimmara committed Dec 20, 2024
1 parent 2286da8 commit 4aa6430
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/plugins/three/DebugTilesPlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const RANDOM_NODE_COLOR: ColorMode;
export const CUSTOM_COLOR: ColorMode;
export class DebugTilesPlugin {

enabled: boolean;

displayBoxBounds : boolean;
displaySphereBounds : boolean;
displayRegionBounds : boolean;
Expand Down
57 changes: 50 additions & 7 deletions src/plugins/three/DebugTilesPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class DebugTilesPlugin {
this.name = 'DEBUG_TILES_PLUGIN';
this.tiles = null;

this._enabled = true;

this.extremeDebugDepth = - 1;
this.extremeDebugError = - 1;
this.boxGroup = null;
Expand All @@ -84,6 +86,33 @@ export class DebugTilesPlugin {

}

get enabled() {

return this._enabled;

}

set enabled(v) {

Check failure on line 95 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There must be a space after this paren

Check failure on line 95 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There must be a space before this paren

Check failure on line 95 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There must be a space after this paren

Check failure on line 95 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There must be a space before this paren

if (v !== this._enabled) {

Check failure on line 97 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There must be a space after this paren

Check failure on line 97 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There must be a space before this paren

Check failure on line 97 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There must be a space after this paren

Check failure on line 97 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There must be a space before this paren

this._enabled = v;

if (this._enabled) {

Check failure on line 101 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There must be a space after this paren

Check failure on line 101 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There must be a space before this paren

Check failure on line 101 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There must be a space after this paren

Check failure on line 101 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There must be a space before this paren

this._initExtremes();
this._initializeExistingTiles();

} else {

this._removeHelpers();

}

}

}

// initialize the groups for displaying helpers, register events, and initialize existing tiles
init( tiles ) {

Expand Down Expand Up @@ -143,8 +172,14 @@ export class DebugTilesPlugin {
tiles.addEventListener( 'update-after', this._onUpdateAfterCB );
tiles.addEventListener( 'tile-visibility-change', this._onTileVisibilityChangeCB );

this._initExtremes();
this._initializeExistingTiles();

}

_initializeExistingTiles() {

Check failure on line 180 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Block must be padded by blank lines

Check failure on line 180 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Block must be padded by blank lines
// initialize an already-loaded tiles
tiles.traverse( tile => {
this.tiles.traverse( tile => {

if ( tile.cached.scene ) {

Expand All @@ -154,7 +189,7 @@ export class DebugTilesPlugin {

} );

tiles.visibleTiles.forEach( tile => {
this.tiles.visibleTiles.forEach( tile => {

this._onTileVisibilityChange( tile, true );

Expand Down Expand Up @@ -214,6 +249,9 @@ export class DebugTilesPlugin {
}

_initExtremes() {

Check failure on line 251 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Block must be padded by blank lines

Check failure on line 251 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Block must be padded by blank lines
if ( !this.tiles || !this.tiles.root ) {

Check failure on line 252 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unary operator '!' must be followed by whitespace

Check failure on line 252 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unary operator '!' must be followed by whitespace

Check failure on line 252 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unary operator '!' must be followed by whitespace

Check failure on line 252 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unary operator '!' must be followed by whitespace
return;
}

// initialize the extreme values of the hierarchy
let maxDepth = - 1;
Expand Down Expand Up @@ -646,6 +684,15 @@ export class DebugTilesPlugin {

}

_removeHelpers() {
// dispose of all helper objects
tiles.traverse( tile => {

Check warning on line 689 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'tiles' is not defined

Check warning on line 689 in src/plugins/three/DebugTilesPlugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'tiles' is not defined

this._onDisposeModel( tile );

} );
}

dispose() {

const tiles = this.tiles;
Expand All @@ -659,11 +706,7 @@ export class DebugTilesPlugin {
this._onUpdateAfter();

// dispose of all helper objects
tiles.traverse( tile => {

this._onDisposeModel( tile );

} );
this._removeHelpers();

this.boxGroup.removeFromParent();
this.sphereGroup.removeFromParent();
Expand Down

0 comments on commit 4aa6430

Please sign in to comment.