浏览代码

BufferGeometry: Implemented .center()

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

+ 9 - 3
src/core/BufferGeometry.js

@@ -84,13 +84,13 @@ THREE.BufferGeometry.prototype = {
 
 
 		}
 		}
 
 
-		if ( this.boundingBox instanceof THREE.Box3 ) {
+		if ( this.boundingBox !== null ) {
 
 
 			this.computeBoundingBox();
 			this.computeBoundingBox();
 
 
 		}
 		}
 
 
-		if ( this.boundingSphere instanceof THREE.Sphere ) {
+		if ( this.boundingSphere !== null ) {
 
 
 			this.computeBoundingSphere();
 			this.computeBoundingSphere();
 
 
@@ -100,7 +100,13 @@ THREE.BufferGeometry.prototype = {
 
 
 	center: function () {
 	center: function () {
 
 
-		// TODO
+		this.computeBoundingBox();
+
+		var offset = this.boundingBox.center().negate();
+
+		this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
+
+		return offset;
 
 
 	},
 	},