Просмотр исходного кода

SelectionBox: Add support for batchedMesh (#32052)

* SelectionBox: Add support for batchedMesh in SelectionBox

* Update SelectionBox.js

Cleanup.

---------

Co-authored-by: sunjiang <jiang_sun@roboticplus.com>
Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
sunjiang 4 месяцев назад
Родитель
Сommit
b65bc7a383
1 измененных файлов с 30 добавлено и 0 удалено
  1. 30 0
      examples/jsm/interactive/SelectionBox.js

+ 30 - 0
examples/jsm/interactive/SelectionBox.js

@@ -92,6 +92,12 @@ class SelectionBox {
 		 * @type {Object}
 		 */
 		this.instances = {};
+		/**
+		 * The selected batches of batched meshes.
+		 *
+		 * @type {Object}
+		 */
+		this.batches = {};
 
 		/**
 		 * How deep the selection frustum of perspective cameras should extend.
@@ -259,6 +265,30 @@ class SelectionBox {
 
 				}
 
+			} else if ( object.isBatchedMesh ) {
+
+				this.batches[ object.uuid ] = [];
+
+				for ( let instanceId = 0, count = 0; count < object.instanceCount; instanceId ++ ) {
+
+					// skip invalid instances in the batchedMesh
+
+					if ( object.validateInstanceId( instanceId ) === false ) continue;
+
+					count ++;
+
+					object.getMatrixAt( instanceId, _matrix );
+					_matrix.decompose( _center, _quaternion, _scale );
+					_center.applyMatrix4( object.matrixWorld );
+
+					if ( frustum.containsPoint( _center ) ) {
+
+						this.batches[ object.uuid ].push( instanceId );
+
+					}
+
+				}
+
 			} else {
 
 				if ( object.geometry.boundingSphere === null ) object.geometry.computeBoundingSphere();

粤ICP备19079148号