|
@@ -159,37 +159,53 @@ class Box3 {
|
|
|
|
|
|
object.updateWorldMatrix( false, false );
|
|
|
|
|
|
- if ( object.boundingBox !== undefined ) {
|
|
|
+ const geometry = object.geometry;
|
|
|
|
|
|
- if ( object.boundingBox === null ) {
|
|
|
+ if ( geometry !== undefined ) {
|
|
|
|
|
|
- object.computeBoundingBox();
|
|
|
+ const positionAttribute = geometry.getAttribute( 'position' );
|
|
|
|
|
|
- }
|
|
|
+ // precise AABB computation based on vertex data requires at least a position attribute.
|
|
|
+ // instancing isn't supported so far and uses the normal (conservative) code path.
|
|
|
|
|
|
- _box.copy( object.boundingBox );
|
|
|
- _box.applyMatrix4( object.matrixWorld );
|
|
|
+ if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {
|
|
|
|
|
|
- this.union( _box );
|
|
|
+ for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
|
|
|
|
|
|
- } else {
|
|
|
+ if ( object.isMesh === true ) {
|
|
|
+
|
|
|
+ object.getVertexPosition( i, _vector );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ _vector.fromBufferAttribute( positionAttribute, i );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _vector.applyMatrix4( object.matrixWorld );
|
|
|
+ this.expandByPoint( _vector );
|
|
|
|
|
|
- const geometry = object.geometry;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
|
|
|
- if ( geometry !== undefined ) {
|
|
|
+ if ( object.boundingBox !== undefined ) {
|
|
|
|
|
|
- if ( precise && geometry.attributes !== undefined && geometry.attributes.position !== undefined ) {
|
|
|
+ // object-level bounding box
|
|
|
|
|
|
- const position = geometry.attributes.position;
|
|
|
- for ( let i = 0, l = position.count; i < l; i ++ ) {
|
|
|
+ if ( object.boundingBox === null ) {
|
|
|
|
|
|
- _vector.fromBufferAttribute( position, i ).applyMatrix4( object.matrixWorld );
|
|
|
- this.expandByPoint( _vector );
|
|
|
+ object.computeBoundingBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
+ _box.copy( object.boundingBox );
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
|
|
|
+ // geometry-level bounding box
|
|
|
+
|
|
|
if ( geometry.boundingBox === null ) {
|
|
|
|
|
|
geometry.computeBoundingBox();
|
|
@@ -197,12 +213,13 @@ class Box3 {
|
|
|
}
|
|
|
|
|
|
_box.copy( geometry.boundingBox );
|
|
|
- _box.applyMatrix4( object.matrixWorld );
|
|
|
-
|
|
|
- this.union( _box );
|
|
|
|
|
|
}
|
|
|
|
|
|
+ _box.applyMatrix4( object.matrixWorld );
|
|
|
+
|
|
|
+ this.union( _box );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|