Skip to content

Commit d6c3bcc

Browse files
authored
BatchedMesh: default setColorAt to white (mrdoob#28416)
* BatchedMesh: default color to white * update comment
1 parent 0dee424 commit d6c3bcc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/objects/BatchedMesh.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Box3 } from '../math/Box3.js';
1010
import { Sphere } from '../math/Sphere.js';
1111
import { Frustum } from '../math/Frustum.js';
1212
import { Vector3 } from '../math/Vector3.js';
13+
import { Color } from '../math/Color.js';
1314

1415
function sortOpaque( a, b ) {
1516

@@ -72,6 +73,7 @@ const ID_ATTR_NAME = 'batchId';
7273
const _matrix = /*@__PURE__*/ new Matrix4();
7374
const _invMatrixWorld = /*@__PURE__*/ new Matrix4();
7475
const _identityMatrix = /*@__PURE__*/ new Matrix4();
76+
const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
7577
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
7678
const _frustum = /*@__PURE__*/ new Frustum();
7779
const _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

Comments
 (0)