Browse Source

Merge pull request #5273 from dubejf/dev

BufferAttribute: Simplify cloning
Mr.doob 11 years ago
parent
commit
d04634db3e
2 changed files with 2 additions and 28 deletions
  1. 1 20
      src/core/BufferAttribute.js
  2. 1 8
      src/core/BufferGeometry.js

+ 1 - 20
src/core/BufferAttribute.js

@@ -104,26 +104,7 @@ THREE.BufferAttribute.prototype = {
 
 
 	clone: function () {
 	clone: function () {
 
 
-		var attribute = new THREE.BufferAttribute( null, this.itemSize );
-
-		var types = [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array ];
-
-		var sourceArray = this.array;
-
-		for ( var i = 0, il = types.length; i < il; i ++ ) {
-
-			var type = types[ i ];
-
-			if ( sourceArray instanceof type ) {
-
-				attribute.array = new type( sourceArray );
-				break;
-
-			}
-
-		}
-
-		return attribute;
+		return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
 
 
 	}
 	}
 
 

+ 1 - 8
src/core/BufferGeometry.js

@@ -829,18 +829,11 @@ THREE.BufferGeometry.prototype = {
 
 
 		/* Create a copy of all attributes for reordering. */
 		/* Create a copy of all attributes for reordering. */
 		var sortedAttributes = {};
 		var sortedAttributes = {};
-		var types = [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array ];
 		for ( var attr in this.attributes ) {
 		for ( var attr in this.attributes ) {
 			if ( attr == 'index' )
 			if ( attr == 'index' )
 				continue;
 				continue;
 			var sourceArray = this.attributes[ attr ].array;
 			var sourceArray = this.attributes[ attr ].array;
-			for ( var i = 0, il = types.length; i < il; i ++ ) {
-				var type = types[ i ];
-				if ( sourceArray instanceof type ) {
-					sortedAttributes[ attr ] = new type( this.attributes[ attr ].itemSize * vertexCount );
-					break;
-				}
-			}
+			sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
 		}
 		}
 
 
 		/* Move attribute positions based on the new index map */
 		/* Move attribute positions based on the new index map */