Просмотр исходного кода

Merge pull request #10303 from Mugen87/dev

Box3: Refactored .setFromObject()
Mr.doob 8 лет назад
Родитель
Сommit
9111feba82
4 измененных файлов с 28 добавлено и 37 удалено
  1. 5 20
      src/math/Box3.js
  2. 7 5
      src/math/Vector2.js
  3. 7 5
      src/math/Vector3.js
  4. 9 7
      src/math/Vector4.js

+ 5 - 20
src/math/Box3.js

@@ -138,6 +138,8 @@ Box3.prototype = {
 
 			object.traverse( function ( node ) {
 
+				var i, l;
+
 				var geometry = node.geometry;
 
 				if ( geometry !== undefined ) {
@@ -146,7 +148,7 @@ Box3.prototype = {
 
 						var vertices = geometry.vertices;
 
-						for ( var i = 0, il = vertices.length; i < il; i ++ ) {
+						for ( i = 0, l = vertices.length; i < l; i ++ ) {
 
 							v1.copy( vertices[ i ] );
 							v1.applyMatrix4( node.matrixWorld );
@@ -161,26 +163,9 @@ Box3.prototype = {
 
 						if ( attribute !== undefined ) {
 
-							var array, offset, stride;
-
-							if ( attribute.isInterleavedBufferAttribute ) {
-
-								array = attribute.data.array;
-								offset = attribute.offset;
-								stride = attribute.data.stride;
-
-							} else {
-
-								array = attribute.array;
-								offset = 0;
-								stride = 3;
-
-							}
-
-							for ( var i = offset, il = array.length; i < il; i += stride ) {
+							for ( i = 0, l = attribute.count; i < l; i ++ ) {
 
-								v1.fromArray( array, i );
-								v1.applyMatrix4( node.matrixWorld );
+								v1.fromAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
 
 								scope.expandByPoint( v1 );
 

+ 7 - 5
src/math/Vector2.js

@@ -87,7 +87,7 @@ Vector2.prototype = {
 			default: throw new Error( 'index is out of range: ' + index );
 
 		}
-		
+
 		return this;
 
 	},
@@ -455,12 +455,14 @@ Vector2.prototype = {
 
 	fromAttribute: function ( attribute, index, offset ) {
 
-		if ( offset === undefined ) offset = 0;
+		if ( offset !== undefined ) {
 
-		index = index * attribute.itemSize + offset;
+			console.warn( 'THREE.Vector2: offset has been removed from .fromAttribute().' );
+
+		}
 
-		this.x = attribute.array[ index ];
-		this.y = attribute.array[ index + 1 ];
+		this.x = attribute.getX( index );
+		this.y = attribute.getY( index );
 
 		return this;
 

+ 7 - 5
src/math/Vector3.js

@@ -763,13 +763,15 @@ Vector3.prototype = {
 
 	fromAttribute: function ( attribute, index, offset ) {
 
-		if ( offset === undefined ) offset = 0;
+		if ( offset !== undefined ) {
+
+			console.warn( 'THREE.Vector3: offset has been removed from .fromAttribute().' );
 
-		index = index * attribute.itemSize + offset;
+		}
 
-		this.x = attribute.array[ index ];
-		this.y = attribute.array[ index + 1 ];
-		this.z = attribute.array[ index + 2 ];
+		this.x = attribute.getX( index );
+		this.y = attribute.getY( index );
+		this.z = attribute.getZ( index );
 
 		return this;
 

+ 9 - 7
src/math/Vector4.js

@@ -86,7 +86,7 @@ Vector4.prototype = {
 			default: throw new Error( 'index is out of range: ' + index );
 
 		}
-		
+
 		return this;
 
 	},
@@ -613,14 +613,16 @@ Vector4.prototype = {
 
 	fromAttribute: function ( attribute, index, offset ) {
 
-		if ( offset === undefined ) offset = 0;
+		if ( offset !== undefined ) {
 
-		index = index * attribute.itemSize + offset;
+			console.warn( 'THREE.Vector4: offset has been removed from .fromAttribute().' );
+
+		}
 
-		this.x = attribute.array[ index ];
-		this.y = attribute.array[ index + 1 ];
-		this.z = attribute.array[ index + 2 ];
-		this.w = attribute.array[ index + 3 ];
+		this.x = attribute.getX( index );
+		this.y = attribute.getY( index );
+		this.z = attribute.getZ( index );
+		this.w = attribute.getW( index );
 
 		return this;