浏览代码

Revert "InterleavedBufferAttribute: Implement .clone()."

This reverts commit 8f78c13402d24ab22ecc58df8b67435179d40f4c.
Don McCurdy 7 年之前
父节点
当前提交
81f90828bc
共有 2 个文件被更改,包括 29 次插入24 次删除
  1. 29 4
      examples/js/loaders/GLTFLoader.js
  2. 0 20
      src/core/InterleavedBufferAttribute.js

+ 29 - 4
examples/js/loaders/GLTFLoader.js

@@ -1100,7 +1100,7 @@ THREE.GLTFLoader = ( function () {
 				// So morphTarget value will depend on mesh's position, then cloning attribute
 				// So morphTarget value will depend on mesh's position, then cloning attribute
 				// for the case if attribute is shared among two or more meshes.
 				// for the case if attribute is shared among two or more meshes.
 
 
-				positionAttribute = accessors[ target.POSITION ].clone();
+				positionAttribute = cloneBufferAttribute( accessors[ target.POSITION ] );
 				var position = geometry.attributes.position;
 				var position = geometry.attributes.position;
 
 
 				for ( var j = 0, jl = positionAttribute.count; j < jl; j ++ ) {
 				for ( var j = 0, jl = positionAttribute.count; j < jl; j ++ ) {
@@ -1118,7 +1118,7 @@ THREE.GLTFLoader = ( function () {
 
 
 				// Copying the original position not to affect the final position.
 				// Copying the original position not to affect the final position.
 				// See the formula above.
 				// See the formula above.
-				positionAttribute = geometry.attributes.position.clone();
+				positionAttribute = cloneBufferAttribute( geometry.attributes.position );
 
 
 			}
 			}
 
 
@@ -1135,7 +1135,7 @@ THREE.GLTFLoader = ( function () {
 
 
 				// see target.POSITION's comment
 				// see target.POSITION's comment
 
 
-				normalAttribute = accessors[ target.NORMAL ].clone();
+				normalAttribute = cloneBufferAttribute( accessors[ target.NORMAL ] );
 				var normal = geometry.attributes.normal;
 				var normal = geometry.attributes.normal;
 
 
 				for ( var j = 0, jl = normalAttribute.count; j < jl; j ++ ) {
 				for ( var j = 0, jl = normalAttribute.count; j < jl; j ++ ) {
@@ -1151,7 +1151,7 @@ THREE.GLTFLoader = ( function () {
 
 
 			} else if ( geometry.attributes.normal !== undefined ) {
 			} else if ( geometry.attributes.normal !== undefined ) {
 
 
-				normalAttribute = geometry.attributes.normal.clone();
+				normalAttribute = cloneBufferAttribute( geometry.attributes.normal );
 
 
 			}
 			}
 
 
@@ -1231,6 +1231,31 @@ THREE.GLTFLoader = ( function () {
 
 
 	}
 	}
 
 
+	function cloneBufferAttribute( attribute ) {
+
+		if ( attribute.isInterleavedBufferAttribute ) {
+
+			var count = attribute.count;
+			var itemSize = attribute.itemSize;
+			var array = attribute.array.slice( 0, count * itemSize );
+
+			for ( var i = 0; i < count; ++ i ) {
+
+				array[ i ] = attribute.getX( i );
+				if ( itemSize >= 2 ) array[ i + 1 ] = attribute.getY( i );
+				if ( itemSize >= 3 ) array[ i + 2 ] = attribute.getZ( i );
+				if ( itemSize >= 4 ) array[ i + 3 ] = attribute.getW( i );
+
+			}
+
+			return new THREE.BufferAttribute( array, itemSize, attribute.normalized );
+
+		}
+
+		return attribute.clone();
+
+	}
+
 	/* GLTF PARSER */
 	/* GLTF PARSER */
 
 
 	function GLTFParser( json, extensions, options ) {
 	function GLTFParser( json, extensions, options ) {

+ 0 - 20
src/core/InterleavedBufferAttribute.js

@@ -1,4 +1,3 @@
-import { BufferAttribute } from './BufferAttribute.js';
 import { _Math } from '../math/Math.js';
 import { _Math } from '../math/Math.js';
 
 
 /**
 /**
@@ -135,25 +134,6 @@ Object.assign( InterleavedBufferAttribute.prototype, {
 
 
 		return this;
 		return this;
 
 
-	},
-
-	clone: function () {
-
-		var count = this.count;
-		var itemSize = this.itemSize;
-		var array = this.data.array.slice( 0, count * itemSize );
-
-		for ( var i = 0; i < count; ++ i ) {
-
-			array[ i ] = this.getX( i );
-			if ( itemSize >= 2 ) array[ i + 1 ] = this.getY( i );
-			if ( itemSize >= 3 ) array[ i + 2 ] = this.getZ( i );
-			if ( itemSize >= 4 ) array[ i + 3 ] = this.getW( i );
-
-		}
-
-		return new BufferAttribute( array, itemSize, this.normalized );
-
 	}
 	}
 
 
 } );
 } );