From b67cca3636243caf454adb8fdbe2252123bf0ecf Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Sat, 25 Jul 2015 08:15:14 -0400 Subject: [PATCH] more minor bug fixing with Animation. --- .../webgl_animation_track_clip_mixer.html | 8 ++++-- src/animation/AnimationClip.js | 25 ++++++++++++++++--- src/animation/KeyframeTrack.js | 3 ++- src/animation/PropertyBinding.js | 8 +++--- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/examples/webgl_animation_track_clip_mixer.html b/examples/webgl_animation_track_clip_mixer.html index 77ce32114c..e1703eeee7 100644 --- a/examples/webgl_animation_track_clip_mixer.html +++ b/examples/webgl_animation_track_clip_mixer.html @@ -258,9 +258,13 @@ mixer = new THREE.AnimationMixer( mesh ); - var rotateClip = THREE.AnimationClip.CreateRotationAnimation( 10 ); + //var clip = THREE.AnimationClip.CreateShakeAnimation( 10, new THREE.Vector3( 10, 10, 10 ) ); + //var clip = THREE.AnimationClip.CreatePulsationAnimation( 10, 100 ); + //var clip = THREE.AnimationClip.CreateRotationAnimation( 10, 'x' ); + var clip = THREE.AnimationClip.CreateScaleAxisAnimation( 10, 'x' ); - mixer.addAction( new THREE.AnimationAction( rotateClip, 0, 1, 1, true ) ); + + mixer.addAction( new THREE.AnimationAction( clip, 0, 1, 1, true ) ); } diff --git a/src/animation/AnimationClip.js b/src/animation/AnimationClip.js index 519d80ba04..fad0607ec4 100644 --- a/src/animation/AnimationClip.js +++ b/src/animation/AnimationClip.js @@ -211,6 +211,23 @@ THREE.AnimationClip.CreateRotationAnimation = function( period, axis ) { return clip; }; +THREE.AnimationClip.CreateScaleAxisAnimation = function( period, axis ) { + + var keys = []; + keys.push( { time: 0, value: 0 } ); + keys.push( { time: period, value: 360 } ); + + axis = axis || 'x'; + var trackName = '.scale[' + axis + ']'; + + var track = new THREE.KeyframeTrack( trackName, keys ); + + var clip = new THREE.AnimationClip( 'scale.x', 10, [ track ] ); + console.log( 'scaleClip', clip ); + + return clip; +}; + THREE.AnimationClip.CreateShakeAnimation = function( duration, shakeScale ) { var keys = []; @@ -228,14 +245,14 @@ THREE.AnimationClip.CreateShakeAnimation = function( duration, shakeScale ) { var track = new THREE.KeyframeTrack( trackName, keys ); - var clip = new THREE.AnimationClip( 'shake' + duration, trackName, [ track ] ); + var clip = new THREE.AnimationClip( 'shake' + duration, duration, [ track ] ); console.log( 'shakeClip', clip ); return clip; }; -THREE.AnimationClip.CreatePulsationAnimation = function( node, duration, pulseScale ) { +THREE.AnimationClip.CreatePulsationAnimation = function( duration, pulseScale ) { var keys = []; @@ -249,11 +266,11 @@ THREE.AnimationClip.CreatePulsationAnimation = function( node, duration, pulseSc } - var trackName = node.name + '.scale'; + var trackName = '.scale'; var track = new THREE.KeyframeTrack( trackName, keys ); - var clip = new THREE.AnimationClip( 'scale' + duration, trackName, [ track ] ); + var clip = new THREE.AnimationClip( 'scale' + duration, duration, [ track ] ); console.log( 'scaleClip', clip ); return clip; diff --git a/src/animation/KeyframeTrack.js b/src/animation/KeyframeTrack.js index 2d4a8955cd..08d783b860 100644 --- a/src/animation/KeyframeTrack.js +++ b/src/animation/KeyframeTrack.js @@ -14,7 +14,7 @@ THREE.KeyframeTrack = function ( name, keys ) { this.keys = keys || []; // time in seconds, value as value // TODO: sort keys via their times - this.keys.sort( function( a, b ) { return a.time < b.time; } ); + //this.keys.sort( function( a, b ) { return a.time < b.time; } ); }; @@ -27,6 +27,7 @@ THREE.KeyframeTrack.prototype = { if( this.keys.length == 0 ) throw new Error( "no keys in track named " + this.name ); + console.log( "keys", this.keys ); // before the start of the track, return the first key value if( this.keys[0].time >= time ) { diff --git a/src/animation/PropertyBinding.js b/src/animation/PropertyBinding.js index 807572a421..f2abadf674 100644 --- a/src/animation/PropertyBinding.js +++ b/src/animation/PropertyBinding.js @@ -17,7 +17,7 @@ THREE.PropertyBinding = function ( rootNode, trackName ) { this.nodeName = parseResults.nodeName; this.material = parseResults.material; this.propertyName = parseResults.propertyName || null; - this.propertyArrayIndex = parseResults.propertyArrayIndex || -1; + this.propertySubElement = parseResults.propertySubElement || -1; this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName ); @@ -51,9 +51,9 @@ THREE.PropertyBinding.prototype = { } // access a sub element of the property array (only primitives are supported right now) - if( this.propertyArrayIndex >= 0 ) { - console.log( ' update property array ' + this.propertyName + '[' + this.propertyArrayIndex + '] via assignment.' ); - nodeProperty[ this.propertyArrayIndex ] = value; + if( ( this.propertySubElement.length && this.propertySubElement.length > 0 ) || this.propertySubElement >= 0 ) { + console.log( ' update property array ' + this.propertyName + '[' + this.propertySubElement + '] via assignment.' ); + nodeProperty[ this.propertySubElement ] = value; } // must use copy for Object3D.Euler/Quaternion else if( nodeProperty.copy ) { -- GitLab