Skip to content

Commit 0f2b02c

Browse files
authored
Merge pull request #202 from NASA-AMMOS/debug-color-callback
DebugTilesRenderer: Add 'getDebugColor' function
2 parents f42b101 + a33a87f commit 0f2b02c

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,14 @@ maxDebugDistance = - 1 : Number
574574

575575
The distance value that represents white when rendering with `DISTANCE` [colorMode](#colorMode). If `maxDebugDistance` is `-1` then the radius of the tile set is used.
576576

577+
### .getDebugColor
578+
579+
```js
580+
getDebugColor : ( val : Number, target : Color ) => void
581+
```
582+
583+
The function used to map a [0, 1] value to a color for debug visualizations. By default the color is mapped from black to white.
584+
577585
## PriorityQueue
578586

579587
Piority-sorted queue to prioritize file downloads and parsing.

src/three/DebugTilesRenderer.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ export class DebugTilesRenderer extends TilesRenderer {
1616
displayBoxBounds : Boolean;
1717
displaySphereBounds : Boolean;
1818
colorMode : ColorMode;
19-
20-
/** Debug color min value, default 'black' */
21-
minDebugColor : Color;
22-
/** Debug color max value, default 'white' */
23-
maxDebugColor : Color;
2419

2520
maxDebugDepth : Number;
2621
maxDebugDistance : Number;
2722
maxDebugError : Number;
2823

24+
getDebugColor : ( val: Number, target: Color ) => void;
25+
2926
}

src/three/DebugTilesRenderer.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ export class DebugTilesRenderer extends TilesRenderer {
4141
this.maxDebugDepth = - 1;
4242
this.maxDebugDistance = - 1;
4343
this.maxDebugError = - 1;
44-
this.minDebugColor = new Color( 'black' );
45-
this.maxDebugColor = new Color( 'white' );
44+
45+
this.getDebugColor = ( value, target ) => {
46+
47+
target.setRGB( value, value, value );
48+
49+
};
4650

4751
this.extremeDebugDepth = - 1;
4852
this.extremeDebugError = - 1;
@@ -194,8 +198,6 @@ export class DebugTilesRenderer extends TilesRenderer {
194198

195199
}
196200

197-
const minDebugColor = this.minDebugColor;
198-
const maxDebugColor = this.maxDebugColor;
199201
const errorTarget = this.errorTarget;
200202
const colorMode = this.colorMode;
201203
const visibleTiles = this.visibleTiles;
@@ -263,14 +265,14 @@ export class DebugTilesRenderer extends TilesRenderer {
263265
case DEPTH: {
264266

265267
const val = tile.__depth / maxDepth;
266-
c.material.color.copy( minDebugColor ).lerpHSL( maxDebugColor, val );
268+
this.getDebugColor( val, c.material.color );
267269
break;
268270

269271
}
270272
case RELATIVE_DEPTH: {
271273

272274
const val = tile.__depthFromRenderedParent / maxDepth;
273-
c.material.color.copy( minDebugColor ).lerpHSL( maxDebugColor, val );
275+
this.getDebugColor( val, c.material.color );
274276
break;
275277

276278
}
@@ -283,7 +285,7 @@ export class DebugTilesRenderer extends TilesRenderer {
283285

284286
} else {
285287

286-
c.material.color.copy( minDebugColor ).lerpHSL( maxDebugColor, val );
288+
this.getDebugColor( val, c.material.color );
287289

288290
}
289291
break;
@@ -292,7 +294,7 @@ export class DebugTilesRenderer extends TilesRenderer {
292294
case GEOMETRIC_ERROR: {
293295

294296
const val = Math.min( tile.geometricError / maxError, 1 );
295-
c.material.color.copy( minDebugColor ).lerpHSL( maxDebugColor, val );
297+
this.getDebugColor( val, c.material.color );
296298
break;
297299

298300
}
@@ -301,19 +303,20 @@ export class DebugTilesRenderer extends TilesRenderer {
301303
// We don't update the distance if the geometric error is 0.0 so
302304
// it will always be black.
303305
const val = Math.min( tile.__distanceFromCamera / maxDistance, 1 );
304-
c.material.color.copy( minDebugColor ).lerpHSL( maxDebugColor, val );
306+
this.getDebugColor( val, c.material.color );
305307
break;
306308

307309
}
308310
case IS_LEAF: {
309311

310312
if ( ! tile.children || tile.children.length === 0 ) {
311313

312-
c.material.color.copy( maxDebugColor );
314+
this.getDebugColor( 1.0, c.material.color );
315+
313316

314317
} else {
315318

316-
c.material.color.set( minDebugColor );
319+
this.getDebugColor( 0.0, c.material.color );
317320

318321
}
319322
break;

0 commit comments

Comments
 (0)