Skip to content

Commit b65bc7a

Browse files
sunjiang0018sunjiangMugen87
authored
SelectionBox: Add support for batchedMesh (#32052)
* SelectionBox: Add support for batchedMesh in SelectionBox * Update SelectionBox.js Cleanup. --------- Co-authored-by: sunjiang <[email protected]> Co-authored-by: Michael Herzog <[email protected]>
1 parent cf605b4 commit b65bc7a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/jsm/interactive/SelectionBox.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ class SelectionBox {
9292
* @type {Object}
9393
*/
9494
this.instances = {};
95+
/**
96+
* The selected batches of batched meshes.
97+
*
98+
* @type {Object}
99+
*/
100+
this.batches = {};
95101

96102
/**
97103
* How deep the selection frustum of perspective cameras should extend.
@@ -259,6 +265,30 @@ class SelectionBox {
259265

260266
}
261267

268+
} else if ( object.isBatchedMesh ) {
269+
270+
this.batches[ object.uuid ] = [];
271+
272+
for ( let instanceId = 0, count = 0; count < object.instanceCount; instanceId ++ ) {
273+
274+
// skip invalid instances in the batchedMesh
275+
276+
if ( object.validateInstanceId( instanceId ) === false ) continue;
277+
278+
count ++;
279+
280+
object.getMatrixAt( instanceId, _matrix );
281+
_matrix.decompose( _center, _quaternion, _scale );
282+
_center.applyMatrix4( object.matrixWorld );
283+
284+
if ( frustum.containsPoint( _center ) ) {
285+
286+
this.batches[ object.uuid ].push( instanceId );
287+
288+
}
289+
290+
}
291+
262292
} else {
263293

264294
if ( object.geometry.boundingSphere === null ) object.geometry.computeBoundingSphere();

0 commit comments

Comments
 (0)