diff --git a/examples/webgl_animation_track_clip_mixer.html b/examples/webgl_animation_track_clip_mixer.html index db062737da1b11dad460736eb7654e82801c6125..fafd902d9e7ca132331e5edcb48365d4755f6355 100644 --- a/examples/webgl_animation_track_clip_mixer.html +++ b/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 ); diff --git a/src/animation/AnimationClip.js b/src/animation/AnimationClip.js index e5b1dadce21678c3355a90f1ee7340034c96dac8..ec5ce1939e6387d4226419ff97b3fe840d129fed 100644 --- a/src/animation/AnimationClip.js +++ b/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; }; + diff --git a/src/animation/PropertyBinding.js b/src/animation/PropertyBinding.js index e0541666b096036067a18badb0f75a4ba0382c48..75e4c24c57b5b0e31a87a98d3bbc8000bac52a19 100644 --- a/src/animation/PropertyBinding.js +++ b/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; }