@@ -10,6 +10,7 @@ import { Box3 } from '../math/Box3.js';
1010import { Sphere } from '../math/Sphere.js' ;
1111import { Frustum } from '../math/Frustum.js' ;
1212import { Vector3 } from '../math/Vector3.js' ;
13+ import { Color } from '../math/Color.js' ;
1314
1415function sortOpaque ( a , b ) {
1516
@@ -72,6 +73,7 @@ const ID_ATTR_NAME = 'batchId';
7273const _matrix = /*@__PURE__ */ new Matrix4 ( ) ;
7374const _invMatrixWorld = /*@__PURE__ */ new Matrix4 ( ) ;
7475const _identityMatrix = /*@__PURE__ */ new Matrix4 ( ) ;
76+ const _whiteColor = /*@__PURE__ */ new Color ( 1 , 1 , 1 ) ;
7577const _projScreenMatrix = /*@__PURE__ */ new Matrix4 ( ) ;
7678const _frustum = /*@__PURE__ */ new Frustum ( ) ;
7779const _box = /*@__PURE__ */ new Box3 ( ) ;
@@ -193,7 +195,8 @@ class BatchedMesh extends Mesh {
193195 let size = Math . sqrt ( this . _maxGeometryCount ) ;
194196 size = Math . ceil ( size ) ;
195197
196- const colorsArray = new Float32Array ( size * size * 4 ) ; // 4 floats per RGBA pixel
198+ // 4 floats per RGBA pixel initialized to white
199+ const colorsArray = new Float32Array ( size * size * 4 ) . fill ( 1 ) ;
197200 const colorsTexture = new DataTexture ( colorsArray , size , size , RGBAFormat , FloatType ) ;
198201 colorsTexture . colorSpace = ColorManagement . workingColorSpace ;
199202
@@ -434,6 +437,7 @@ class BatchedMesh extends Mesh {
434437 const active = this . _active ;
435438 const matricesTexture = this . _matricesTexture ;
436439 const matricesArray = this . _matricesTexture . image . data ;
440+ const colorsTexture = this . _colorsTexture ;
437441
438442 // push new visibility states
439443 visibility . push ( true ) ;
@@ -447,6 +451,14 @@ class BatchedMesh extends Mesh {
447451 _identityMatrix . toArray ( matricesArray , geometryId * 16 ) ;
448452 matricesTexture . needsUpdate = true ;
449453
454+ // initialize the color to white
455+ if ( colorsTexture !== null ) {
456+
457+ _whiteColor . toArray ( colorsTexture . image . data , geometryId * 4 ) ;
458+ colorsTexture . needsUpdate = true ;
459+
460+ }
461+
450462 // add the reserved range and draw range objects
451463 reservedRanges . push ( reservedRange ) ;
452464 drawRanges . push ( {
0 commit comments