Browse Source

Geometry/BufferGeometry: Changed semantics of .center()

Mugen87 7 years ago
parent
commit
fdb44520f5
4 changed files with 24 additions and 12 deletions
  1. 1 1
      docs/api/core/BufferGeometry.html
  2. 1 1
      docs/api/core/Geometry.html
  3. 11 5
      src/core/BufferGeometry.js
  4. 11 5
      src/core/Geometry.js

+ 1 - 1
docs/api/core/BufferGeometry.html

@@ -212,7 +212,7 @@
 		<h3>[method:null applyMatrix]( [param:Matrix4 matrix] )</h3>
 		<div>Bakes matrix transform directly into vertex coordinates.</div>
 
-		<h3>[method:null center] ()</h3>
+		<h3>[method:BufferGeometry center] ()</h3>
 		<div>Center the geometry based on the bounding box.</div>
 
 		<h3>[method:BufferGeometry clone]()</h3>

+ 1 - 1
docs/api/core/Geometry.html

@@ -214,7 +214,7 @@
 		<h3>[method:null applyMatrix]( [param:Matrix4 matrix] )</h3>
 		<div>Bakes matrix transform directly into vertex coordinates.</div>
 
-		<h3>[method:null center] ()</h3>
+		<h3>[method:Geometry center] ()</h3>
 		<div>Center the geometry based on the bounding box.</div>
 
 		<h3>[method:Geometry clone]()</h3>

+ 11 - 5
src/core/BufferGeometry.js

@@ -278,15 +278,21 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 	center: function () {
 
-		this.computeBoundingBox();
+		var offset = new Vector3();
 
-		var offset = this.boundingBox.getCenter().negate();
+		return function center() {
 
-		this.translate( offset.x, offset.y, offset.z );
+			this.computeBoundingBox();
 
-		return offset;
+			this.boundingBox.getCenter( offset ).negate();
 
-	},
+			this.translate( offset.x, offset.y, offset.z );
+
+			return this;
+
+		};
+
+	}(),
 
 	setFromObject: function ( object ) {
 

+ 11 - 5
src/core/Geometry.js

@@ -354,15 +354,21 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 	center: function () {
 
-		this.computeBoundingBox();
+		var offset = new Vector3();
 
-		var offset = this.boundingBox.getCenter().negate();
+		return function center() {
 
-		this.translate( offset.x, offset.y, offset.z );
+			this.computeBoundingBox();
 
-		return offset;
+			this.boundingBox.getCenter( offset ).negate();
 
-	},
+			this.translate( offset.x, offset.y, offset.z );
+
+			return this;
+
+		};
+
+	}(),
 
 	normalize: function () {