|
@@ -59,52 +59,34 @@ THREE.Box3.prototype = {
|
|
|
// Computes the world-axis-aligned bounding box of an object (including its children),
|
|
|
// accounting for both the object's, and children's, world transforms
|
|
|
|
|
|
- var v1 = new THREE.Vector3();
|
|
|
+ var box;
|
|
|
|
|
|
return function ( object ) {
|
|
|
|
|
|
- var scope = this;
|
|
|
+ if ( box === undefined ) box = new THREE.Box3();
|
|
|
|
|
|
- object.updateMatrixWorld( true );
|
|
|
+ var scope = this;
|
|
|
|
|
|
this.makeEmpty();
|
|
|
|
|
|
+ object.updateMatrixWorld( true );
|
|
|
+
|
|
|
object.traverse( function ( node ) {
|
|
|
|
|
|
var geometry = node.geometry;
|
|
|
|
|
|
if ( geometry !== undefined ) {
|
|
|
|
|
|
- if ( geometry instanceof THREE.Geometry ) {
|
|
|
-
|
|
|
- var vertices = geometry.vertices;
|
|
|
-
|
|
|
- for ( var i = 0, il = vertices.length; i < il; i ++ ) {
|
|
|
-
|
|
|
- v1.copy( vertices[ i ] );
|
|
|
-
|
|
|
- v1.applyMatrix4( node.matrixWorld );
|
|
|
+ if ( geometry.boundingBox === null ) {
|
|
|
|
|
|
- scope.expandByPoint( v1 );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
|
|
|
-
|
|
|
- var positions = geometry.attributes[ 'position' ].array;
|
|
|
-
|
|
|
- for ( var i = 0, il = positions.length; i < il; i += 3 ) {
|
|
|
-
|
|
|
- v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
|
|
|
-
|
|
|
- v1.applyMatrix4( node.matrixWorld );
|
|
|
-
|
|
|
- scope.expandByPoint( v1 );
|
|
|
-
|
|
|
- }
|
|
|
+ geometry.computeBoundingBox();
|
|
|
|
|
|
}
|
|
|
|
|
|
+ box.copy( geometry.boundingBox ;
|
|
|
+ box.applyMatrix4( node.matrixWorld );
|
|
|
+ scope.union( box );
|
|
|
+
|
|
|
}
|
|
|
|
|
|
} );
|