2
0
Эх сурвалжийг харах

Merge pull request #15498 from Mugen87/dev21

BufferGeometry: Support morph targets in .toNonIndexed()
Mr.doob 6 жил өмнө
parent
commit
e38cfed628
1 өөрчлөгдсөн 47 нэмэгдсэн , 10 устгасан
  1. 47 10
      src/core/BufferGeometry.js

+ 47 - 10
src/core/BufferGeometry.js

@@ -848,6 +848,33 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 	toNonIndexed: function () {
 
+		function convertBufferAttribute( attribute, indices ) {
+
+			var array = attribute.array;
+			var itemSize = attribute.itemSize;
+
+			var array2 = new array.constructor( indices.length * itemSize );
+
+			var index = 0, index2 = 0;
+
+			for ( var i = 0, l = indices.length; i < l; i ++ ) {
+
+				index = indices[ i ] * itemSize;
+
+				for ( var j = 0; j < itemSize; j ++ ) {
+
+					array2[ index2 ++ ] = array[ index ++ ];
+
+				}
+
+			}
+
+			return new BufferAttribute( array2, itemSize );
+
+		}
+
+		//
+
 		if ( this.index === null ) {
 
 			console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
@@ -860,33 +887,43 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 		var indices = this.index.array;
 		var attributes = this.attributes;
 
+		// attributes
+
 		for ( var name in attributes ) {
 
 			var attribute = attributes[ name ];
 
-			var array = attribute.array;
-			var itemSize = attribute.itemSize;
+			var newAttribute = convertBufferAttribute( attribute, indices );
 
-			var array2 = new array.constructor( indices.length * itemSize );
+			geometry2.addAttribute( name, newAttribute );
 
-			var index = 0, index2 = 0;
+		}
 
-			for ( var i = 0, l = indices.length; i < l; i ++ ) {
+		// morph attributes
 
-				index = indices[ i ] * itemSize;
+		var morphAttributes = this.morphAttributes;
 
-				for ( var j = 0; j < itemSize; j ++ ) {
+		for ( name in morphAttributes ) {
 
-					array2[ index2 ++ ] = array[ index ++ ];
+			var morphArray = [];
+			var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
 
-				}
+			for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
+
+				var attribute = morphAttribute[ i ];
+
+				var newAttribute = convertBufferAttribute( attribute, indices );
+
+				morphArray.push( newAttribute );
 
 			}
 
-			geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
+			geometry2.morphAttributes[ name ] = morphArray;
 
 		}
 
+		// groups
+
 		var groups = this.groups;
 
 		for ( var i = 0, l = groups.length; i < l; i ++ ) {