提交 74c2898d 编写于 作者: B Ben Houston

make morph target animation clips work.

上级 e6aad57c
...@@ -258,19 +258,21 @@ ...@@ -258,19 +258,21 @@
mixer = new THREE.AnimationMixer( mesh ); mixer = new THREE.AnimationMixer( mesh );
var clip1 = THREE.AnimationClip.CreateShakeAnimation( 10, new THREE.Vector3( 10, 10, 10 ) ); 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 ); 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' ); 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' ); 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 ) ] ); 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 ) ); //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 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() { function initGUI() {
...@@ -326,7 +328,7 @@ ...@@ -326,7 +328,7 @@
//if ( helper !== undefined ) helper.update(); //if ( helper !== undefined ) helper.update();
// update morphs // update morphs
/*
if ( mesh ) { if ( mesh ) {
var time = Date.now() * 0.001; var time = Date.now() * 0.001;
...@@ -343,7 +345,7 @@ ...@@ -343,7 +345,7 @@
mesh.morphTargetInfluences[ 3 ] = ( 1 + Math.cos( 4 * time ) ) / 2; mesh.morphTargetInfluences[ 3 ] = ( 1 + Math.cos( 4 * time ) ) / 2;
} }*/
renderer.render( scene, camera ); renderer.render( scene, camera );
......
...@@ -160,12 +160,12 @@ THREE.AnimationClip.prototype = { ...@@ -160,12 +160,12 @@ THREE.AnimationClip.prototype = {
// TODO: Fix this for loops. // TODO: Fix this for loops.
// TODO: Test this // TODO: Test this
THREE.AnimationClip.CreateMorphAnimation = function( morphTargetNames, duration ) { THREE.AnimationClip.CreateMorphAnimation = function( morphTargets, duration ) {
var tracks = []; 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 = []; var keys = [];
...@@ -177,13 +177,13 @@ THREE.AnimationClip.CreateMorphAnimation = function( morphTargetNames, duration ...@@ -177,13 +177,13 @@ THREE.AnimationClip.CreateMorphAnimation = function( morphTargetNames, duration
keys.push( { time: i * frameStep, value: 1 } ); 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 } ); keys.push( { time: ( i + 1 ) * frameStep, value: 0 } );
} }
var morphName = morphTargetNames[i]; var morphName = morphTargets[i].name;
var trackName = '.morphTargetInfluences[' + morphName + ']'; var trackName = '.morphTargetInfluences[' + morphName + ']';
var track = new THREE.KeyframeTrack( trackName, keys ); var track = new THREE.KeyframeTrack( trackName, keys );
...@@ -323,3 +323,4 @@ THREE.AnimationClip.CreateMaterialColorAnimation = function( duration, colors, l ...@@ -323,3 +323,4 @@ THREE.AnimationClip.CreateMaterialColorAnimation = function( duration, colors, l
return clip; return clip;
}; };
...@@ -119,10 +119,17 @@ THREE.PropertyBinding.prototype = { ...@@ -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. // 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. // support resolving morphTarget names into indices.
console.log( " resolving morphTargetInfluence name: ", this.propertyIndex ); //console.log( " resolving morphTargetInfluence name: ", this.propertyIndex );
for( var i = 0; i < this.node.morphTargets.length; i ++ ) { if( this.node.geometry ) {
if( this.node.morphTargets[i].name === this.propertyIndex ) { console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
console.log( " resolved to index: ", i ); }
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; this.propertyIndex = i;
break; break;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册