浏览代码

Geometry: Simplified .center()

Mr.doob 10 年之前
父节点
当前提交
abb1b9ef11
共有 1 个文件被更改,包括 7 次插入8 次删除
  1. 7 8
      src/core/Geometry.js

+ 7 - 8
src/core/Geometry.js

@@ -81,18 +81,21 @@ THREE.Geometry.prototype = {
 
 		}
 
-		if ( this.boundingBox instanceof THREE.Box3 ) {
+		if ( this.boundingBox !== null ) {
 
 			this.computeBoundingBox();
 
 		}
 
-		if ( this.boundingSphere instanceof THREE.Sphere ) {
+		if ( this.boundingSphere !== null ) {
 
 			this.computeBoundingSphere();
 
 		}
 
+		this.verticesNeedUpdate = true;
+		this.normalsNeedUpdate = true;
+
 	},
 
 	fromBufferGeometry: function ( geometry ) {
@@ -189,13 +192,9 @@ THREE.Geometry.prototype = {
 
 		this.computeBoundingBox();
 
-		var offset = new THREE.Vector3();
-
-		offset.addVectors( this.boundingBox.min, this.boundingBox.max );
-		offset.multiplyScalar( - 0.5 );
+		var offset = this.boundingBox.center().negate();
 
-		this.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) );
-		this.computeBoundingBox();
+		this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
 
 		return offset;