Browse Source

make morph target animation clips work.

Ben Houston 10 years ago
parent
commit
74c2898d3f

+ 12 - 10
examples/webgl_animation_track_clip_mixer.html

@@ -258,19 +258,21 @@
 				mixer = new THREE.AnimationMixer( mesh );
 
 				var clip1 = THREE.AnimationClip.CreateShakeAnimation( 10, new THREE.Vector3( 10, 10, 10 ) );
-				mixer.addAction( new THREE.AnimationAction( clip1, 0, 1, 1, true ) );
+				//mixer.addAction( new THREE.AnimationAction( clip1, 0, 1, 1, true ) );
 				var clip2 = THREE.AnimationClip.CreatePulsationAnimation( 10, 100 );
-				mixer.addAction( new THREE.AnimationAction( clip2, 0, 1, 1, true ) );
+				//mixer.addAction( new THREE.AnimationAction( clip2, 0, 1, 1, true ) );
 				var clip3 = THREE.AnimationClip.CreateRotationAnimation( 100, 'y' );
-				mixer.addAction( new THREE.AnimationAction( clip3, 0, 1, 1, true ) );
+				//mixer.addAction( new THREE.AnimationAction( clip3, 0, 1, 1, true ) );
 				var clip4 = THREE.AnimationClip.CreateScaleAxisAnimation( 10, 'x' );
-				mixer.addAction( new THREE.AnimationAction( clip4, 0, 1, 1, true ) );
+				//mixer.addAction( new THREE.AnimationAction( clip4, 0, 1, 1, true ) );
 				var clip5 = THREE.AnimationClip.CreateMaterialColorAnimation( 10, [ new THREE.Color( 0xffffff ), new THREE.Color( 0xff0000 ), new THREE.Color( 0xff00ff ) ] );
-				mixer.addAction( new THREE.AnimationAction( clip5, 0, 1, 1, true ) );
-
-				var clip6 = THREE.AnimationClip.CreateVisibilityAnimation( 10 );
-				mixer.addAction( new THREE.AnimationAction( clip6, 0, 1, 1, true ) );
+				//mixer.addAction( new THREE.AnimationAction( clip5, 0, 1, 1, true ) );
 
+				//var clip6 = THREE.AnimationClip.CreateVisibilityAnimation( 10 );
+				//mixer.addAction( new THREE.AnimationAction( clip6, 0, 1, 1, true ) );
+				
+				var clip7 = THREE.AnimationClip.CreateMorphAnimation( mesh.geometry.morphTargets, 3 );
+				mixer.addAction( new THREE.AnimationAction( clip7, 0, 1, 1, true ) );
 			}
 
 			function initGUI() {
@@ -326,7 +328,7 @@
 				//if ( helper !== undefined ) helper.update();
 
 				// update morphs
-
+/*
 				if ( mesh ) {
 
 					var time = Date.now() * 0.001;
@@ -343,7 +345,7 @@
 
 					mesh.morphTargetInfluences[ 3 ] = ( 1 + Math.cos( 4 * time ) ) / 2;
 
-				}
+				}*/
 
 				renderer.render( scene, camera );
 

+ 6 - 5
src/animation/AnimationClip.js

@@ -160,12 +160,12 @@ THREE.AnimationClip.prototype = {
 
 // TODO: Fix this for loops.
 // TODO: Test this
-THREE.AnimationClip.CreateMorphAnimation = function( morphTargetNames, duration ) {
+THREE.AnimationClip.CreateMorphAnimation = function( morphTargets, duration ) {
 
 	var tracks = [];
-	var frameStep = duration / morphTargetNames;
+	var frameStep = duration / morphTargets.length;
 
-	for( var i = 0; i < morphTargetNames.length; i ++ ) {
+	for( var i = 0; i < morphTargets.length; i ++ ) {
 
 		var keys = [];
 
@@ -177,13 +177,13 @@ THREE.AnimationClip.CreateMorphAnimation = function( morphTargetNames, duration
 
 		keys.push( { time: i * frameStep, value: 1 } );
 
-		if( ( i + 1 ) <= morphTargetNames.length ) {
+		if( ( i + 1 ) <= morphTargets.length ) {
 
 			keys.push( { time: ( i + 1 ) * frameStep, value: 0 } );
 
 		}
 
-		var morphName = morphTargetNames[i];
+		var morphName = morphTargets[i].name;
 		var trackName = '.morphTargetInfluences[' + morphName + ']';
 		var track = new THREE.KeyframeTrack( trackName, keys );
 
@@ -323,3 +323,4 @@ THREE.AnimationClip.CreateMaterialColorAnimation = function( duration, colors, l
 
 	return clip;
 };
+

+ 11 - 4
src/animation/PropertyBinding.js

@@ -119,10 +119,17 @@ THREE.PropertyBinding.prototype = {
 					// TODO/OPTIMIZE, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
 					
 					// support resolving morphTarget names into indices.
-					console.log( "  resolving morphTargetInfluence name: ", this.propertyIndex );
-					for( var i = 0; i < this.node.morphTargets.length; i ++ ) {
-						if( this.node.morphTargets[i].name === this.propertyIndex ) {
-							console.log( "  resolved to index: ", i );
+					//console.log( "  resolving morphTargetInfluence name: ", this.propertyIndex );
+					if( this.node.geometry ) {
+						console.error( '  can not bind to morphTargetInfluences becasuse node does not have a geometry', this );				
+					}
+					if( this.node.geometry.morphTargets ) {
+						console.error( '  can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );				
+					}
+					
+					for( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
+						if( this.node.geometry.morphTargets[i].name === this.propertyIndex ) {
+							//console.log( "  resolved to index: ", i );
 							this.propertyIndex = i;
 							break;
 						}