Ver Fonte

BufferGeometry: Make computeBoundingBox and computeBoundingSphere compatible to to InterleavedBufferAttribute

Mugen87 há 8 anos atrás
pai
commit
1b2d43c731
3 ficheiros alterados com 64 adições e 16 exclusões
  1. 26 10
      docs/api/math/Box3.html
  2. 7 6
      src/core/BufferGeometry.js
  3. 31 0
      src/math/Box3.js

+ 26 - 10
docs/api/math/Box3.html

@@ -93,6 +93,22 @@
 		Determines whether or not this box intersects *plane*.
 		</div>
 
+		<h3>[method:Box3 setFromArray]( [page:Array array] ) [page:Box3 this]</h3>
+		<div>
+		array -- An array of position data that the resulting box will envelop.
+		</div>
+		<div>
+		Sets the upper and lower bounds of this box to include all of the data in *array*.
+		</div>
+
+		<h3>[method:Box3 setFromBuffer]( [page:BufferAttribute buffer] ) [page:Box3 this]</h3>
+		<div>
+		buffer -- An buffer attribute of position data that the resulting box will envelop.
+		</div>
+		<div>
+		Sets the upper and lower bounds of this box to include all of the data in *buffer*.
+		</div>
+
 		<h3>[method:Box3 setFromPoints]( [page:Array points] ) [page:Box3 this]</h3>
 		<div>
 		points -- Set of points that the resulting box will envelop.
@@ -101,6 +117,16 @@
 		Sets the upper and lower bounds of this box to include all of the points in *points*.
 		</div>
 
+		<h3>[method:Box3 setFromCenterAndSize]( [page:Vector3 center], [page:Vector3 size] ) [page:Box3 this]</h3>
+		<div>
+		center -- Desired center position of the box. <br>
+		size -- Desired x, y and z dimensions of the box.
+		</div>
+		<div>
+		Centers this box on *center* and sets this box's width, height and depth to the values specified <br>
+		in *size*.
+		</div>
+
 		<h3>[method:Box3 setFromObject]( [page:Object3D object] ) [page:Box3 this]</h3>
 		<div>
 		object -- [page:Object3D] to compute the bounding box for.
@@ -262,16 +288,6 @@
 		If the point lies inside of this box, the distance will be 0.
 		</div>
 
-		<h3>[method:Box3 setFromCenterAndSize]( [page:Vector3 center], [page:Vector3 size] ) [page:Box3 this]</h3>
-		<div>
-		center -- Desired center position of the box. <br>
-		size -- Desired x, y and z dimensions of the box.
-		</div>
-		<div>
-		Centers this box on *center* and sets this box's width, height and depth to the values specified <br>
-		in *size*.
-		</div>
-
 		<h2>Source</h2>
 
 		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]

+ 7 - 6
src/core/BufferGeometry.js

@@ -579,11 +579,11 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
 
 		}
 
-		var positions = this.attributes.position.array;
+		var positions = this.attributes.position;
 
 		if ( positions !== undefined ) {
 
-			this.boundingBox.setFromArray( positions );
+			this.boundingBox.setFromBuffer( positions );
 
 		} else {
 
@@ -616,10 +616,9 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
 
 			if ( positions ) {
 
-				var array = positions.array;
 				var center = this.boundingSphere.center;
 
-				box.setFromArray( array );
+				box.setFromBuffer( positions );
 				box.getCenter( center );
 
 				// hoping to find a boundingSphere with a radius smaller than the
@@ -627,9 +626,11 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
 
 				var maxRadiusSq = 0;
 
-				for ( var i = 0, il = array.length; i < il; i += 3 ) {
+				for ( var i = 0, il = positions.count; i < il; i ++ ) {
 
-					vector.fromArray( array, i );
+					vector.x = positions.getX( i );
+					vector.y = positions.getY( i );
+					vector.z = positions.getZ( i );
 					maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
 
 				}

+ 31 - 0
src/math/Box3.js

@@ -59,6 +59,37 @@ Box3.prototype = {
 
 	},
 
+	setFromBuffer: function ( buffer ) {
+
+		var minX = + Infinity;
+		var minY = + Infinity;
+		var minZ = + Infinity;
+
+		var maxX = - Infinity;
+		var maxY = - Infinity;
+		var maxZ = - Infinity;
+
+		for ( var i = 0, l = buffer.count; i < l; i ++ ) {
+
+			var x = buffer.getX( i );
+			var y = buffer.getY( i );
+			var z = buffer.getZ( i );
+
+			if ( x < minX ) minX = x;
+			if ( y < minY ) minY = y;
+			if ( z < minZ ) minZ = z;
+
+			if ( x > maxX ) maxX = x;
+			if ( y > maxY ) maxY = y;
+			if ( z > maxZ ) maxZ = z;
+
+		}
+
+		this.min.set( minX, minY, minZ );
+		this.max.set( maxX, maxY, maxZ );
+
+	},
+
 	setFromPoints: function ( points ) {
 
 		this.makeEmpty();