@@ -199,7 +199,7 @@ class BatchedMesh extends Mesh {
199
199
200
200
// @TODO : geometry.groups support?
201
201
// @TODO : geometry.drawRange support?
202
- // @TODO : geometry.mortphAttributes support?
202
+ // @TODO : geometry.morphAttributes support?
203
203
204
204
if ( this . _geometryCount >= this . _maxGeometryCount ) {
205
205
@@ -345,76 +345,94 @@ class BatchedMesh extends Mesh {
345
345
// @TODO : Map geometryId to index of the arrays because
346
346
// optimize() can make geometryId mismatch the index
347
347
348
- if ( geometryId >= this . _matrices . length || this . _alives [ geometryId ] === false ) {
348
+ const visibles = this . _visibles ;
349
+ const alives = this . _alives ;
350
+ const matricesTexture = this . _matricesTexture ;
351
+ const matrices = this . _matrices ;
352
+ const matricesArray = this . _matricesArray ;
353
+ if ( geometryId >= matrices . length || alives [ geometryId ] === false ) {
349
354
350
355
return this ;
351
356
352
357
}
353
358
354
- this . _matrices [ geometryId ] . copy ( matrix ) ;
359
+ if ( visibles [ geometryId ] === true ) {
355
360
356
- if ( this . _visibles [ geometryId ] === true ) {
357
-
358
- matrix . toArray ( this . _matricesArray , geometryId * 16 ) ;
359
- this . _matricesTexture . needsUpdate = true ;
361
+ matrix . toArray ( matricesArray , geometryId * 16 ) ;
362
+ matricesTexture . needsUpdate = true ;
360
363
361
364
}
362
365
366
+ matrices [ geometryId ] . copy ( matrix ) ;
367
+
363
368
return this ;
364
369
365
370
}
366
371
367
372
getMatrixAt ( geometryId , matrix ) {
368
373
369
- if ( geometryId >= this . _matrices . length || this . _alives [ geometryId ] === false ) {
374
+ const matrices = this . _matrices ;
375
+ const alives = this . _alives ;
376
+ if ( geometryId >= matrices . length || alives [ geometryId ] === false ) {
370
377
371
378
return matrix ;
372
379
373
380
}
374
381
375
- return matrix . copy ( this . _matrices [ geometryId ] ) ;
382
+ return matrix . copy ( matrices [ geometryId ] ) ;
376
383
377
384
}
378
385
379
386
setVisibleAt ( geometryId , visible ) {
380
387
381
- if ( geometryId > = this . _visibles . length || this . _alives [ geometryId ] === false ) {
382
-
383
- return this ;
384
-
385
- }
388
+ const visibles = this . _visibles ;
389
+ const alives = this . _alives ;
390
+ const matricesTexture = this . _matricesTexture ;
391
+ const matrices = this . _matrices ;
392
+ const matricesArray = this . _matricesArray ;
386
393
387
- if ( this . _visibles [ geometryId ] === visible ) {
394
+ // if the geometry is out of range, not active, or visibility state
395
+ // does not change then return early
396
+ if (
397
+ geometryId >= visibles . length ||
398
+ alives [ geometryId ] === false ||
399
+ visibles [ geometryId ] === visible
400
+ ) {
388
401
389
402
return this ;
390
403
391
404
}
392
405
406
+ // scale the matrix to zero if it's hidden
393
407
if ( visible === true ) {
394
408
395
- this . _matrices [ geometryId ] . toArray ( this . _matricesArray , geometryId * 16 ) ;
409
+ matrices [ geometryId ] . toArray ( matricesArray , geometryId * 16 ) ;
396
410
397
411
} else {
398
412
399
- _zeroScaleMatrix . toArray ( this . _matricesArray , geometryId * 16 ) ;
413
+ _zeroScaleMatrix . toArray ( matricesArray , geometryId * 16 ) ;
400
414
401
415
}
402
416
403
- this . _matricesTexture . needsUpdate = true ;
404
- this . _visibles [ geometryId ] = visible ;
417
+ matricesTexture . needsUpdate = true ;
418
+ visibles [ geometryId ] = visible ;
405
419
return this ;
406
420
407
421
}
408
422
409
423
getVisibleAt ( geometryId ) {
410
424
411
- if ( geometryId >= this . _visibles . length || this . _alives [ geometryId ] === false ) {
425
+ const visibles = this . _visibles ;
426
+ const alives = this . _alives ;
427
+
428
+ // return early if the geometry is out of range or not active
429
+ if ( geometryId >= visibles . length || alives [ geometryId ] === false ) {
412
430
413
431
return false ;
414
432
415
433
}
416
434
417
- return this . _visibles [ geometryId ] ;
435
+ return visibles [ geometryId ] ;
418
436
419
437
}
420
438
0 commit comments