|
@@ -1,14 +1,18 @@
|
|
|
import { InstancedBufferAttribute } from '../core/InstancedBufferAttribute.js';
|
|
|
import { Mesh } from './Mesh.js';
|
|
|
+import { Box3 } from '../math/Box3.js';
|
|
|
import { Matrix4 } from '../math/Matrix4.js';
|
|
|
+import { Sphere } from '../math/Sphere.js';
|
|
|
|
|
|
const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
|
|
|
const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
|
|
|
|
|
|
const _instanceIntersects = [];
|
|
|
|
|
|
+const _box3 = /*@__PURE__*/ new Box3();
|
|
|
const _identity = /*@__PURE__*/ new Matrix4();
|
|
|
const _mesh = /*@__PURE__*/ new Mesh();
|
|
|
+const _sphere = /*@__PURE__*/ new Sphere();
|
|
|
|
|
|
class InstancedMesh extends Mesh {
|
|
|
|
|
@@ -23,7 +27,8 @@ class InstancedMesh extends Mesh {
|
|
|
|
|
|
this.count = count;
|
|
|
|
|
|
- this.frustumCulled = false;
|
|
|
+ this.boundingBox = null;
|
|
|
+ this.boundingSphere = null;
|
|
|
|
|
|
for ( let i = 0; i < count; i ++ ) {
|
|
|
|
|
@@ -33,6 +38,68 @@ class InstancedMesh extends Mesh {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ computeBoundingBox() {
|
|
|
+
|
|
|
+ const geometry = this.geometry;
|
|
|
+ const count = this.count;
|
|
|
+
|
|
|
+ if ( this.boundingBox === null ) {
|
|
|
+
|
|
|
+ this.boundingBox = new Box3();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( geometry.boundingBox === null ) {
|
|
|
+
|
|
|
+ geometry.computeBoundingBox();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.boundingBox.makeEmpty();
|
|
|
+
|
|
|
+ for ( let i = 0; i < count; i ++ ) {
|
|
|
+
|
|
|
+ this.getMatrixAt( i, _instanceLocalMatrix );
|
|
|
+
|
|
|
+ _box3.copy( geometry.boundingBox ).applyMatrix4( _instanceLocalMatrix );
|
|
|
+
|
|
|
+ this.boundingBox.union( _box3 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ computeBoundingSphere() {
|
|
|
+
|
|
|
+ const geometry = this.geometry;
|
|
|
+ const count = this.count;
|
|
|
+
|
|
|
+ if ( this.boundingSphere === null ) {
|
|
|
+
|
|
|
+ this.boundingSphere = new Sphere();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( geometry.boundingSphere === null ) {
|
|
|
+
|
|
|
+ geometry.computeBoundingSphere();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.boundingSphere.makeEmpty();
|
|
|
+
|
|
|
+ for ( let i = 0; i < count; i ++ ) {
|
|
|
+
|
|
|
+ this.getMatrixAt( i, _instanceLocalMatrix );
|
|
|
+
|
|
|
+ _sphere.copy( geometry.boundingSphere ).applyMatrix4( _instanceLocalMatrix );
|
|
|
+
|
|
|
+ this.boundingSphere.union( _sphere );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
copy( source, recursive ) {
|
|
|
|
|
|
super.copy( source, recursive );
|