Browse Source

Merge pull request #5262 from dubejf/dev

BufferGeometry: Clone attributes
Mr.doob 11 years ago
parent
commit
db7a3497c5
2 changed files with 26 additions and 25 deletions
  1. 25 0
      src/core/BufferAttribute.js
  2. 1 25
      src/core/BufferGeometry.js

+ 25 - 0
src/core/BufferAttribute.js

@@ -100,6 +100,31 @@ THREE.BufferAttribute.prototype = {
 
 		return this;
 
+	},
+
+	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;
+
 	}
 
 };

+ 1 - 25
src/core/BufferGeometry.js

@@ -929,34 +929,10 @@ THREE.BufferGeometry.prototype = {
 
 		var geometry = new THREE.BufferGeometry();
 
-		var types = [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array ];
-
 		for ( var attr in this.attributes ) {
 
 			var sourceAttr = this.attributes[ attr ];
-			var sourceArray = sourceAttr.array;
-
-			var attribute = {
-
-				itemSize: sourceAttr.itemSize,
-				array: null
-
-			};
-
-			for ( var i = 0, il = types.length; i < il; i ++ ) {
-
-				var type = types[ i ];
-
-				if ( sourceArray instanceof type ) {
-
-					attribute.array = new type( sourceArray );
-					break;
-
-				}
-
-			}
-
-			geometry.attributes[ attr ] = attribute;
+			geometry.addAttribute( attr, sourceAttr.clone() );
 
 		}