Skip to content

Commit 6a0dab0

Browse files
BatchedMesh: Fix setInstanceCount(). (#31458)
* fix BatchedMesh.setInstanceCount * Cleanup
1 parent 250c5f6 commit 6a0dab0

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/objects/BatchedMesh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ class BatchedMesh extends Mesh {
12511251
const availableInstanceIds = this._availableInstanceIds;
12521252
const instanceInfo = this._instanceInfo;
12531253
availableInstanceIds.sort( ascIdSort );
1254-
while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
1254+
while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length - 1 ) {
12551255

12561256
instanceInfo.pop();
12571257
availableInstanceIds.pop();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* global QUnit */
2+
3+
import { BatchedMesh } from '../../../../src/objects/BatchedMesh.js';
4+
import { BoxGeometry } from '../../../../src/geometries/BoxGeometry.js';
5+
import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial.js';
6+
7+
export default QUnit.module( 'Objects', () => {
8+
9+
QUnit.module( 'BatchedMesh', () => {
10+
11+
// PUBLIC
12+
13+
QUnit.test( 'setInstanceCount', ( assert ) => {
14+
15+
const box = new BoxGeometry( 1, 1, 1 );
16+
const material = new MeshBasicMaterial( { color: 0x00ff00 } );
17+
18+
// initialize and add a geometry into the batched mesh
19+
const batchedMesh = new BatchedMesh( 4, 5000, 10000, material );
20+
const boxGeometryId = batchedMesh.addGeometry( box );
21+
22+
// create instances of this geometry
23+
let boxInstanceIds = [];
24+
for (let i = 0; i < 4; i++){
25+
boxInstanceIds.push( batchedMesh.addInstance( boxGeometryId ) );
26+
}
27+
28+
batchedMesh.deleteInstance( boxInstanceIds[2] );
29+
batchedMesh.deleteInstance( boxInstanceIds[3] );
30+
31+
// shrink the instance count
32+
batchedMesh.setInstanceCount(2);
33+
34+
assert.ok( batchedMesh.instanceCount === 2, 'instance count unequal 2' );
35+
36+
} );
37+
38+
} );
39+
40+
} );

test/unit/three.source.unit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ import './src/math/interpolants/QuaternionLinearInterpolant.tests.js';
215215

216216
//src/objects
217217
import './src/objects/Bone.tests.js';
218+
import './src/objects/BatchedMesh.tests.js';
218219
import './src/objects/Group.tests.js';
219220
import './src/objects/InstancedMesh.tests.js';
220221
import './src/objects/Line.tests.js';

0 commit comments

Comments
 (0)