Ver código fonte

add example of how to specify a morph target animation.

Ben Houston 10 anos atrás
pai
commit
dadc0a1810
2 arquivos alterados com 36 adições e 6 exclusões
  1. 33 3
      src/animation/AnimationClip.js
  2. 3 3
      src/animation/PropertyBinding.js

+ 33 - 3
src/animation/AnimationClip.js

@@ -156,9 +156,39 @@ THREE.AnimationClip.prototype = {
 
 
 THREE.AnimationClip.CreateMorphAnimation = function( morphTargetNames, duration ) {
-	// TODO
-	//  - should create three keys per morphTarget track.
-	//  - one track per morphTarget name.
+
+	var tracks = [];
+	var frameStep = duration / morphTargetNames;
+
+	for( var i = 0; i < morphTargetNames.length; i ++ ) {
+
+		var keys = [];
+
+		if( ( i - 1 ) >= 0 ) {
+
+			keys.push( { time: ( i - 1 ) * frameStep, value: 0 } );
+
+		}
+
+		keys.push( { time: i * frameStep, value: 1 } );
+
+		if( ( i + 1 ) <= morphTargetNames.length ) {
+
+			keys.push( { time: ( i + 1 ) * frameStep, value: 0 } );
+
+		}
+
+		var morphName = morphTargetNames[i];
+		var trackName = node.name + '.morphTargetInfluences[' + morphName + ']';
+		var track = new THREE.KeyframeTrack( trackName, keys );
+
+		tracks.push( track );
+	}
+
+	var clip = new THREE.AnimationClip( 'morphAnimation', duration, tracks );
+	console.log( 'morphAnimationClip', clip );
+
+	return clip;
 };
 
 THREE.AnimationClip.CreateRotationAnimation = function( node, period, axis ) {

+ 3 - 3
src/animation/PropertyBinding.js

@@ -103,9 +103,9 @@ THREE.PropertyBinding.parseTrackName = function( trackName ) {
 
 	var results = {
 		directoryName: m[0],
-		nodeName: m[2],
-		propertyName: m[4],	// allowed to be null, specified root node.
-		propertySubElement: m[6]
+		nodeName: m[2], 	// allowed to be null, specified root node.
+		propertyName: m[4],
+		propertySubElement: m[6]	// allowed to be null, specifies that the whole property is set.
 	};
 
 	console.log( "PropertyBinding.parseTrackName", trackName, results );