Procházet zdrojové kódy

[debug] - add new mode to example, revert r/g for DEPTH, minor pr comments

Dave Buchhofer před 4 roky
rodič
revize
68b122eb9a
3 změnil soubory, kde provedl 16 přidání a 19 odebrání
  1. 2 0
      example/index.js
  2. 3 4
      src/three/DebugTilesRenderer.js
  3. 11 15
      src/three/utilities.js

+ 2 - 0
example/index.js

@@ -8,6 +8,7 @@ import {
 	RELATIVE_DEPTH,
 	IS_LEAF,
 	RANDOM_COLOR,
+	RANDOM_NODE_COLOR,
 } from '../src/index.js';
 import {
 	Scene,
@@ -251,6 +252,7 @@ function init() {
 		RELATIVE_DEPTH,
 		IS_LEAF,
 		RANDOM_COLOR,
+		RANDOM_NODE_COLOR,
 
 	} );
 	debug.open();

+ 3 - 4
src/three/DebugTilesRenderer.js

@@ -3,7 +3,7 @@ import { getIndexedRandomColor } from './utilities.js';
 import { TilesRenderer } from './TilesRenderer.js';
 import { SphereHelper } from './SphereHelper.js';
 
-export const ORIGINAL_MATERIAL = Symbol( 'ORIGINAL_MATERIAL' );
+const ORIGINAL_MATERIAL = Symbol( 'ORIGINAL_MATERIAL' );
 const HAS_RANDOM_COLOR = Symbol( 'HAS_RANDOM_COLOR' );
 
 function emptyRaycast() {}
@@ -250,8 +250,7 @@ export class DebugTilesRenderer extends TilesRenderer {
 						case DEPTH: {
 
 							const val = tile.__depth / maxDepth;
-							/** map higher depth values to red, lower to green, lerping by hue */
-							c.material.color.setHSL( MathUtils.mapLinear( val, 0, 1, 0.9, 0.1 ), 1, 0.5 );
+							c.material.color.setRGB( val, val, val );
 							break;
 
 						}
@@ -271,7 +270,7 @@ export class DebugTilesRenderer extends TilesRenderer {
 
 							} else {
 
-								/** map higher error values to red, lower to green, lerping by hue */
+								// map higher depth values to red, lower to green, lerping by hue
 								c.material.color.setHSL( MathUtils.mapLinear( val, 0, 1, 0.43, 0 ), 1, 0.5 );
 
 							}

+ 11 - 15
src/three/utilities.js

@@ -1,23 +1,19 @@
 import { Color } from 'three';
 
-/** Return a consistant random color for an index */
-export const getIndexedRandomColor = ( () => {
+const colors = {};
 
-	const colors = {};
+// Return a consistant random color for an index
+export function getIndexedRandomColor( index ) {
 
-	return ( index ) => {
+	if ( ! colors[ index ] ) {
 
-		if ( ! colors[ index ] ) {
+		const h = Math.random();
+		const s = 0.5 + Math.random() * 0.5;
+		const l = 0.375 + Math.random() * 0.25;
 
-			const h = Math.random();
-			const s = 0.5 + Math.random() * 0.5;
-			const l = 0.375 + Math.random() * 0.25;
+		colors[ index ] = new Color().setHSL( h, s, l );
 
-			colors[ index ] = new Color().setHSL( h, s, l );
+	}
+	return colors[ index ];
 
-		}
-		return colors[ index ];
-
-	};
-
-} )();
+}