From 84d21a0d04e9f73277ed04647d4911966c7310fd Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sat, 18 May 2024 17:10:48 +0900 Subject: [PATCH 1/2] BatchedMesh: default color to white --- src/objects/BatchedMesh.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/objects/BatchedMesh.js b/src/objects/BatchedMesh.js index ff490419e5b2aa..fad29a45061898 100644 --- a/src/objects/BatchedMesh.js +++ b/src/objects/BatchedMesh.js @@ -10,6 +10,7 @@ import { Box3 } from '../math/Box3.js'; import { Sphere } from '../math/Sphere.js'; import { Frustum } from '../math/Frustum.js'; import { Vector3 } from '../math/Vector3.js'; +import { Color } from '../math/Color.js'; function sortOpaque( a, b ) { @@ -72,6 +73,7 @@ const ID_ATTR_NAME = 'batchId'; const _matrix = /*@__PURE__*/ new Matrix4(); const _invMatrixWorld = /*@__PURE__*/ new Matrix4(); const _identityMatrix = /*@__PURE__*/ new Matrix4(); +const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 ); const _projScreenMatrix = /*@__PURE__*/ new Matrix4(); const _frustum = /*@__PURE__*/ new Frustum(); const _box = /*@__PURE__*/ new Box3(); @@ -193,7 +195,8 @@ class BatchedMesh extends Mesh { let size = Math.sqrt( this._maxGeometryCount ); size = Math.ceil( size ); - const colorsArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel + // 4 floats per RGBA pixel initialized to opaque white + const colorsArray = new Float32Array( size * size * 4 ).fill( 1 ); const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType ); colorsTexture.colorSpace = ColorManagement.workingColorSpace; @@ -434,6 +437,7 @@ class BatchedMesh extends Mesh { const active = this._active; const matricesTexture = this._matricesTexture; const matricesArray = this._matricesTexture.image.data; + const colorsTexture = this._colorsTexture; // push new visibility states visibility.push( true ); @@ -447,6 +451,14 @@ class BatchedMesh extends Mesh { _identityMatrix.toArray( matricesArray, geometryId * 16 ); matricesTexture.needsUpdate = true; + // initialize the color to white + if ( colorsTexture !== null ) { + + _whiteColor.toArray( colorsTexture.image.data, geometryId * 4 ); + colorsTexture.needsUpdate = true; + + } + // add the reserved range and draw range objects reservedRanges.push( reservedRange ); drawRanges.push( { From 83a2adc5b63ecaee5403299b93c1629d3d9fac46 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Sat, 18 May 2024 17:12:58 +0900 Subject: [PATCH 2/2] update comment --- src/objects/BatchedMesh.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objects/BatchedMesh.js b/src/objects/BatchedMesh.js index fad29a45061898..19cba48eef205b 100644 --- a/src/objects/BatchedMesh.js +++ b/src/objects/BatchedMesh.js @@ -195,7 +195,7 @@ class BatchedMesh extends Mesh { let size = Math.sqrt( this._maxGeometryCount ); size = Math.ceil( size ); - // 4 floats per RGBA pixel initialized to opaque white + // 4 floats per RGBA pixel initialized to white const colorsArray = new Float32Array( size * size * 4 ).fill( 1 ); const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType ); colorsTexture.colorSpace = ColorManagement.workingColorSpace;