提交 59e929e5 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #10474 from sunag/84dev

Optional makeEmpty in THREE.Box3
......@@ -57,6 +57,8 @@ Box3.prototype = {
this.min.set( minX, minY, minZ );
this.max.set( maxX, maxY, maxZ );
return this;
},
setFromBufferAttribute: function ( attribute ) {
......@@ -88,6 +90,8 @@ Box3.prototype = {
this.min.set( minX, minY, minZ );
this.max.set( maxX, maxY, maxZ );
return this;
},
setFromPoints: function ( points ) {
......@@ -121,69 +125,13 @@ Box3.prototype = {
}(),
setFromObject: function () {
// 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 Vector3();
return function setFromObject( object ) {
var scope = this;
object.updateMatrixWorld( true );
this.makeEmpty();
object.traverse( function ( node ) {
var i, l;
var geometry = node.geometry;
if ( geometry !== undefined ) {
if ( geometry.isGeometry ) {
var vertices = geometry.vertices;
for ( i = 0, l = vertices.length; i < l; i ++ ) {
v1.copy( vertices[ i ] );
v1.applyMatrix4( node.matrixWorld );
scope.expandByPoint( v1 );
}
} else if ( geometry.isBufferGeometry ) {
var attribute = geometry.attributes.position;
if ( attribute !== undefined ) {
for ( i = 0, l = attribute.count; i < l; i ++ ) {
v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
setFromObject: function ( object ) {
scope.expandByPoint( v1 );
}
}
}
}
} );
return this;
this.makeEmpty();
};
return this.expandByObject( object );
}(),
},
clone: function () {
......@@ -258,6 +206,68 @@ Box3.prototype = {
},
expandByObject: function () {
// 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 Vector3();
return function expandByObject( object ) {
var scope = this;
object.updateMatrixWorld( true );
object.traverse( function ( node ) {
var i, l;
var geometry = node.geometry;
if ( geometry !== undefined ) {
if ( geometry.isGeometry ) {
var vertices = geometry.vertices;
for ( i = 0, l = vertices.length; i < l; i ++ ) {
v1.copy( vertices[ i ] );
v1.applyMatrix4( node.matrixWorld );
scope.expandByPoint( v1 );
}
} else if ( geometry.isBufferGeometry ) {
var attribute = geometry.attributes.position;
if ( attribute !== undefined ) {
for ( i = 0, l = attribute.count; i < l; i ++ ) {
v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
scope.expandByPoint( v1 );
}
}
}
}
} );
return this;
};
}(),
containsPoint: function ( point ) {
return point.x < this.min.x || point.x > this.max.x ||
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册