瀏覽代碼

updating examples to new Clip parsing inside of JSONLoader/ObjectLoader.

Ben Houston 10 年之前
父節點
當前提交
a1a88ebc35

+ 3 - 4
examples/webgl_animation_skinning_blending.html

@@ -221,10 +221,9 @@
 				controls.update();
 
 				// Set default weights
-
-				blendMesh.animations[ 'idle' ].weight = 1 / 3;
-				blendMesh.animations[ 'walk' ].weight = 1 / 3;
-				blendMesh.animations[ 'run' ].weight = 1 / 3;
+				blendMesh.applyWeight( 'idle', 1 / 3 );
+				blendMesh.applyWeight( 'walk', 1 / 3 );
+				blendMesh.applyWeight( 'run', 1 / 3 );
 
 				gui = new BlendCharacterGui(blendMesh);
 

+ 4 - 4
examples/webgl_animation_skinning_morph.html

@@ -232,12 +232,12 @@
 				helper.visible = false;
 				scene.add( helper );
 
+	
+				var clipMorpher = THREE.AnimationClip.CreateFromMorphTargetSequence( 'facialExpressions', mesh.geometry.morphTargets, 3 );
+				var clipBones = geometry.clips[0];
+
 				mixer = new THREE.AnimationMixer( mesh );
-		
-				var clipMorpher = THREE.AnimationClip.CreateMorphAnimation( mesh.geometry.morphTargets, 3 );
 				mixer.addAction( new THREE.AnimationAction( clipMorpher, 0, 1, 1, true ) );
-
-				var clipBones = geometry.clips[0];
 				mixer.addAction( new THREE.AnimationAction( clipBones, 0, 1, 1, true ) );
 			}
 

+ 5 - 5
src/animation/AnimationClip.js

@@ -99,10 +99,10 @@ THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetS
 			});
 		}
 
-		tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetSequence[i].name + ']', keys ) );
+		tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetSequence[i].name + ']', keys ).scale( 1.0 / fps ) );
 	}
 
-	return new THREE.AnimationClip( name, -1, tracks ).scale( 1.0 / fps );
+	return new THREE.AnimationClip( name, -1, tracks );
 
 };
 
@@ -148,7 +148,7 @@ THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets
 THREE.AnimationClip.parse = function( json ) {
 
 	var tracks = [];
-	
+
 	for( var i = 0; i < json.tracks.length; i ++ ) {
 
 		tracks.push( THREE.KeyframeTrack.parse( json.tracks[i] ).scale( 1.0 / json.fps ) );
@@ -160,8 +160,8 @@ THREE.AnimationClip.parse = function( json ) {
 };
 
 
-// parse the old animation.hierarchy format
-THREE.AnimationClip.parseAnimationHierarchy = function( animation, bones, nodeName ) {
+// parse the animation.hierarchy format
+THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
 
 	if( ! animation ) {
 		console.error( "  no animation in JSONLoader data" );

+ 15 - 0
src/animation/AnimationMixer.js

@@ -23,6 +23,8 @@ THREE.AnimationMixer.prototype = {
 
 	addAction: function( action ) {
 
+		// TODO: check for duplicate action names?  Or provide each action with a UUID?
+
 		this.actions.push( action );
 		action.mixer = this;
 
@@ -146,6 +148,19 @@ THREE.AnimationMixer.prototype = {
 
 	},
 
+	// can be optimized if needed
+	findActionByName: function( name ) {
+
+		for( var i = 0; i < this.actions.length; i ++ ) {
+
+			if( this.actions[i].name === name ) return this.actions[i];
+
+		}
+
+		return null;
+
+	},
+
 	play: function( action, optionalFadeInDuration ) {
 
 		action.startTime = this.time;

+ 14 - 3
src/loaders/JSONLoader.js

@@ -425,11 +425,22 @@ THREE.JSONLoader.prototype = {
 			geometry.clips = [];
 
 			// parse old style Bone/Hierarchy animations
-			var animation = json.animations || json.animation;
+			var animations = [];
+			if( json.animation !== undefined ) {
+				animations.push( json.animation );
+			}
+			if( json.animations !== undefined ) {
+				if( json.animations.length ) {
+					animations = animations.concat( json.animations );
+				}
+				else {
+					animations.push( json.animations );
+				}
+			}
 
-			if( animation ) {
+			for( var i = 0; i < animations.length; i ++ ) {
 
-				var clip = THREE.AnimationClip.parseAnimationHierarchy( animation, geometry.bones );
+				var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
 				if( clip ) geometry.clips.push( clip );
 
 			}