@@ -306,30 +306,53 @@ class BatchedMesh extends Mesh {
306
306
const batchGeometry = this . geometry ;
307
307
if ( Boolean ( geometry . getIndex ( ) ) !== Boolean ( batchGeometry . getIndex ( ) ) ) {
308
308
309
- throw new Error ( 'BatchedMesh: All geometries must consistently have "index".' ) ;
309
+ throw new Error ( 'THREE. BatchedMesh: All geometries must consistently have "index".' ) ;
310
310
311
311
}
312
312
313
313
for ( const attributeName in batchGeometry . attributes ) {
314
314
315
315
if ( ! geometry . hasAttribute ( attributeName ) ) {
316
316
317
- throw new Error ( `BatchedMesh: Added geometry missing "${ attributeName } ". All geometries must have consistent attributes.` ) ;
317
+ throw new Error ( `THREE. BatchedMesh: Added geometry missing "${ attributeName } ". All geometries must have consistent attributes.` ) ;
318
318
319
319
}
320
320
321
321
const srcAttribute = geometry . getAttribute ( attributeName ) ;
322
322
const dstAttribute = batchGeometry . getAttribute ( attributeName ) ;
323
323
if ( srcAttribute . itemSize !== dstAttribute . itemSize || srcAttribute . normalized !== dstAttribute . normalized ) {
324
324
325
- throw new Error ( 'BatchedMesh: All attributes must have a consistent itemSize and normalized value.' ) ;
325
+ throw new Error ( 'THREE. BatchedMesh: All attributes must have a consistent itemSize and normalized value.' ) ;
326
326
327
327
}
328
328
329
329
}
330
330
331
331
}
332
332
333
+ validateInstanceId ( instanceId ) {
334
+
335
+ const instanceInfo = this . _instanceInfo ;
336
+ if ( instanceId < 0 || instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
337
+
338
+ throw new Error ( `THREE.BatchedMesh: Invalid instanceId ${ instanceId } . Instance is either out of range or has been deleted.` ) ;
339
+
340
+ }
341
+
342
+ }
343
+
344
+ validateGeometryId ( geometryId ) {
345
+
346
+ const geometryInfoList = this . _geometryInfo ;
347
+ if ( geometryId < 0 || geometryId >= geometryInfoList . length || geometryInfoList [ geometryId ] . active === false ) {
348
+
349
+ throw new Error ( `THREE.BatchedMesh: Invalid geometryId ${ geometryId } . Geometry is either out of range or has been deleted.` ) ;
350
+
351
+ }
352
+
353
+ }
354
+
355
+
333
356
setCustomSort ( func ) {
334
357
335
358
this . customSort = func ;
@@ -394,7 +417,7 @@ class BatchedMesh extends Mesh {
394
417
// ensure we're not over geometry
395
418
if ( atCapacity && this . _availableInstanceIds . length === 0 ) {
396
419
397
- throw new Error ( 'BatchedMesh: Maximum item count reached.' ) ;
420
+ throw new Error ( 'THREE. BatchedMesh: Maximum item count reached.' ) ;
398
421
399
422
}
400
423
@@ -483,7 +506,7 @@ class BatchedMesh extends Mesh {
483
506
geometryInfo . vertexStart + geometryInfo . reservedVertexCount > this . _maxVertexCount
484
507
) {
485
508
486
- throw new Error ( 'BatchedMesh: Reserved space request exceeds the maximum buffer size.' ) ;
509
+ throw new Error ( 'THREE. BatchedMesh: Reserved space request exceeds the maximum buffer size.' ) ;
487
510
488
511
}
489
512
@@ -520,7 +543,7 @@ class BatchedMesh extends Mesh {
520
543
521
544
if ( geometryId >= this . _geometryCount ) {
522
545
523
- throw new Error ( 'BatchedMesh: Maximum geometry count reached.' ) ;
546
+ throw new Error ( 'THREE. BatchedMesh: Maximum geometry count reached.' ) ;
524
547
525
548
}
526
549
@@ -537,7 +560,7 @@ class BatchedMesh extends Mesh {
537
560
geometry . attributes . position . count > geometryInfo . reservedVertexCount
538
561
) {
539
562
540
- throw new Error ( 'BatchedMesh: Reserved space not large enough for provided geometry.' ) ;
563
+ throw new Error ( 'THREE. BatchedMesh: Reserved space not large enough for provided geometry.' ) ;
541
564
542
565
}
543
566
@@ -652,14 +675,9 @@ class BatchedMesh extends Mesh {
652
675
653
676
deleteInstance ( instanceId ) {
654
677
655
- const instanceInfo = this . _instanceInfo ;
656
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
657
-
658
- return this ;
678
+ this . validateInstanceId ( instanceId ) ;
659
679
660
- }
661
-
662
- instanceInfo [ instanceId ] . active = false ;
680
+ this . _instanceInfo [ instanceId ] . active = false ;
663
681
this . _availableInstanceIds . push ( instanceId ) ;
664
682
this . _visibilityChanged = true ;
665
683
@@ -843,15 +861,10 @@ class BatchedMesh extends Mesh {
843
861
844
862
setMatrixAt ( instanceId , matrix ) {
845
863
846
- const instanceInfo = this . _instanceInfo ;
864
+ this . validateInstanceId ( instanceId ) ;
865
+
847
866
const matricesTexture = this . _matricesTexture ;
848
867
const matricesArray = this . _matricesTexture . image . data ;
849
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
850
-
851
- return this ;
852
-
853
- }
854
-
855
868
matrix . toArray ( matricesArray , instanceId * 16 ) ;
856
869
matricesTexture . needsUpdate = true ;
857
870
@@ -861,72 +874,46 @@ class BatchedMesh extends Mesh {
861
874
862
875
getMatrixAt ( instanceId , matrix ) {
863
876
864
- const instanceInfo = this . _instanceInfo ;
865
- const matricesArray = this . _matricesTexture . image . data ;
866
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
867
-
868
- return null ;
869
-
870
- }
871
-
872
- return matrix . fromArray ( matricesArray , instanceId * 16 ) ;
877
+ this . validateInstanceId ( instanceId ) ;
878
+ return matrix . fromArray ( this . _matricesTexture . image . data , instanceId * 16 ) ;
873
879
874
880
}
875
881
876
882
setColorAt ( instanceId , color ) {
877
883
884
+ this . validateInstanceId ( instanceId ) ;
885
+
878
886
if ( this . _colorsTexture === null ) {
879
887
880
888
this . _initColorsTexture ( ) ;
881
889
882
890
}
883
891
884
- const colorsTexture = this . _colorsTexture ;
885
- const colorsArray = this . _colorsTexture . image . data ;
886
- const instanceInfo = this . _instanceInfo ;
887
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
888
-
889
- return this ;
890
-
891
- }
892
-
893
- color . toArray ( colorsArray , instanceId * 4 ) ;
894
- colorsTexture . needsUpdate = true ;
892
+ color . toArray ( this . _colorsTexture . image . data , instanceId * 4 ) ;
893
+ this . _colorsTexture . needsUpdate = true ;
895
894
896
895
return this ;
897
896
898
897
}
899
898
900
899
getColorAt ( instanceId , color ) {
901
900
902
- const colorsArray = this . _colorsTexture . image . data ;
903
- const instanceInfo = this . _instanceInfo ;
904
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
905
-
906
- return null ;
907
-
908
- }
909
-
910
- return color . fromArray ( colorsArray , instanceId * 4 ) ;
901
+ this . validateInstanceId ( instanceId ) ;
902
+ return color . fromArray ( this . _colorsTexture . image . data , instanceId * 4 ) ;
911
903
912
904
}
913
905
914
906
setVisibleAt ( instanceId , value ) {
915
907
916
- // if the geometry is out of range, not active, or visibility state
917
- // does not change then return early
918
- const instanceInfo = this . _instanceInfo ;
919
- if (
920
- instanceId >= instanceInfo . length ||
921
- instanceInfo [ instanceId ] . active === false ||
922
- instanceInfo [ instanceId ] . visible === value
923
- ) {
908
+ this . validateInstanceId ( instanceId ) ;
909
+
910
+ if ( this . _instanceInfo [ instanceId ] . visible === value ) {
924
911
925
912
return this ;
926
913
927
914
}
928
915
929
- instanceInfo [ instanceId ] . visible = value ;
916
+ this . _instanceInfo [ instanceId ] . visible = value ;
930
917
this . _visibilityChanged = true ;
931
918
932
919
return this ;
@@ -935,62 +922,34 @@ class BatchedMesh extends Mesh {
935
922
936
923
getVisibleAt ( instanceId ) {
937
924
938
- // return early if the geometry is out of range or not active
939
- const instanceInfo = this . _instanceInfo ;
940
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
941
-
942
- return false ;
925
+ this . validateInstanceId ( instanceId ) ;
943
926
944
- }
945
-
946
- return instanceInfo [ instanceId ] . visible ;
927
+ return this . _instanceInfo [ instanceId ] . visible ;
947
928
948
929
}
949
930
950
931
setGeometryIdAt ( instanceId , geometryId ) {
951
932
952
- // return early if the geometry is out of range or not active
953
- const instanceInfo = this . _instanceInfo ;
954
- const geometryInfoList = this . _geometryInfo ;
955
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
956
-
957
- return null ;
958
-
959
- }
933
+ this . validateInstanceId ( instanceId ) ;
934
+ this . validateGeometryId ( geometryId ) ;
960
935
961
- // check if the provided geometryId is within the valid range
962
- if ( geometryId >= geometryInfoList . length || geometryInfoList [ geometryId ] . active === false ) {
963
-
964
- return null ;
965
-
966
- }
967
-
968
- instanceInfo [ instanceId ] . geometryIndex = geometryId ;
936
+ this . _instanceInfo [ instanceId ] . geometryIndex = geometryId ;
969
937
970
938
return this ;
971
939
972
940
}
973
941
974
942
getGeometryIdAt ( instanceId ) {
975
943
976
- const instanceInfo = this . _instanceInfo ;
977
- if ( instanceId >= instanceInfo . length || instanceInfo [ instanceId ] . active === false ) {
978
-
979
- return - 1 ;
980
-
981
- }
944
+ this . validateInstanceId ( instanceId ) ;
982
945
983
- return instanceInfo [ instanceId ] . geometryIndex ;
946
+ return this . _instanceInfo [ instanceId ] . geometryIndex ;
984
947
985
948
}
986
949
987
950
getGeometryRangeAt ( geometryId , target = { } ) {
988
951
989
- if ( geometryId < 0 || geometryId >= this . _geometryCount ) {
990
-
991
- return null ;
992
-
993
- }
952
+ this . validateGeometryId ( geometryId ) ;
994
953
995
954
const geometryInfo = this . _geometryInfo [ geometryId ] ;
996
955
target . vertexStart = geometryInfo . vertexStart ;
0 commit comments