Browse Source

Mesh .updateMorphTargets(): BufferGeometry support

Mugen87 8 years ago
parent
commit
50d9be3136

+ 4 - 0
docs/api/core/BufferAttribute.html

@@ -78,6 +78,10 @@
 		<h3>[property:Integer itemSize]</h3>
 		<div>The length of vectors that are being stored in the [page:BufferAttribute.array array].</div>
 
+		<h3>[property:String name]</h3>
+		<div>
+		Optional name for this attribute instance. Default is an empty string.
+		</div>
 
 		<h3>[property:Boolean needsUpdate]</h3>
 		<div>

+ 1 - 0
examples/js/loaders/MMDLoader.js

@@ -786,6 +786,7 @@ THREE.MMDLoader.prototype.createMesh = function ( model, texturePath, onProgress
 			var params = { name: m.name };
 
 			var attribute = new THREE.Float32BufferAttribute( model.metadata.vertexCount * 3, 3 );
+			attribute.name = m.name;
 
 			for ( var j = 0; j < model.metadata.vertexCount * 3; j++ ) {
 

+ 1 - 0
src/core/BufferAttribute.js

@@ -17,6 +17,7 @@ function BufferAttribute( array, itemSize, normalized ) {
 	}
 
 	this.uuid = _Math.generateUUID();
+	this.name = '';
 
 	this.array = array;
 	this.itemSize = itemSize;

+ 43 - 7
src/objects/Mesh.js

@@ -56,17 +56,53 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	updateMorphTargets: function () {
 
-		var morphTargets = this.geometry.morphTargets;
+		var geometry = this.geometry;
+		var m, ml, name;
 
-		if ( morphTargets !== undefined && morphTargets.length > 0 ) {
+		if ( geometry.isBufferGeometry ) {
 
-			this.morphTargetInfluences = [];
-			this.morphTargetDictionary = {};
+			var morphAttributes = geometry.morphAttributes;
+			var keys = Object.keys( morphAttributes );
 
-			for ( var m = 0, ml = morphTargets.length; m < ml; m ++ ) {
+			if ( keys.length > 0 ) {
 
-				this.morphTargetInfluences.push( 0 );
-				this.morphTargetDictionary[ morphTargets[ m ].name ] = m;
+				var morphAttribute = morphAttributes[ keys[ 0 ] ];
+
+				if ( morphAttribute !== undefined ) {
+
+					this.morphTargetInfluences = [];
+					this.morphTargetDictionary = {};
+
+					for ( m = 0, ml = morphAttribute.length; m < lm; m ++ ) {
+
+						name = morphAttribute[ m ].name || m;
+
+						this.morphTargetInfluences.push( 0 );
+						this.morphTargetDictionary[ name ] = m;
+
+					}
+
+				}
+
+			}
+
+		} else {
+
+			var morphTargets = geometry.morphTargets;
+
+			if ( morphTargets !== undefined && morphTargets.length > 0 ) {
+
+				this.morphTargetInfluences = [];
+				this.morphTargetDictionary = {};
+
+				for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
+
+					name = morphTargets[ m ].name || m;
+
+					this.morphTargetInfluences.push( 0 );
+					this.morphTargetDictionary[ name ] = m;
+
+				}
 
 			}