hairussabar / papervision3d

Automatically exported from code.google.com/p/papervision3d
0 stars 0 forks source link

Made AnimationController playback tweenable (code provided) #261

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'm not sure of the proper procedure for this but I just made some changes
on my local copy of
org.papervision3d.core.controller.AnimationController.as that I needed for
a project. Would probably be useful for other people, if so feel free to
incorporate it (and improve on it hopefully). If there's a better way to
submit this kind of thing please let me know, I've been using Papervision
for a while but I'm kind of new to the whole subversion thing.

I made "currentTime" writeable so you can jump/tween to specific times, and
added a getter/setter called "progress" which allows you to jump to or
tween using a 0-1 scale rather than the native length of the animation:

    public function set currentTime(inVal:Number):void {
        var storedIsPlaying:Boolean=_isPlaying;
        _isPlaying=true;
        _currentTimeStamp = getTimer() - inVal * 1000;
        update();
        _isPlaying=storedIsPlaying;
    }

    public function get progress():Number {
        return (_currentTime-startTime)/(endTime-startTime);
    }
    public function set progress(inVal:Number):void {
        currentTime=startTime+(inVal*(endTime-startTime));
    }

Now the animation can jump to a specific time or (more usefully) can be
tweened e.g. using TweenMax so animations can be played back at speeds
other than the speed it was created at, using different eases, played
backwards, etc.

Example 1, jump to the start of the animation then play it back in 3
seconds (originally was about 1sec. in the DAE):

    theObject.animation.currentTime=0;
    TweenMax.to(theObject.animation,3,{
        currentTime: theObject.animation.endTime
    });

Example 2, start 1/2 way through the animation, play to the end in 3
seconds, then reverse back to the initial position:

    theObject.animation.progress=0.5;
    TweenMax.to(theObject.animation,3,{
        progress: 1,
        yoyo: true,
        repeat: 1
    });

Original issue reported on code.google.com by t...@tom-callahan.com on 4 Mar 2010 at 3:45

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Missed some stuff -- here's an updated progress getter/setter that takes clips 
into
account, and a new getter/setter "clip" that allows you to set a clip w/o 
initiating
playback:

        public function get progress():Number {
            var st:Number;
            var et:Number;
            if (_clip) {
                st=_clip.startTime;
                et=_clip.endTime;
            } else {
                st=startTime;
                et=endTime;
            }
            return (_currentTime-st)/(et-st);
        }
        public function set progress(inVal:Number):void {
            var st:Number;
            var et:Number;
            if (_clip) {
                st=_clip.startTime;
                et=_clip.endTime;
            } else {
                st=startTime;
                et=endTime;
            }
            currentTime=st+(inVal*(et-st));
        }

        public function set clip(inClip:String):void {
            if(inClip && inClip.length && _clipByName[inClip] is AnimationClip3D) 
            {   
                _clip = _clipByName[inClip];
            }
            else
            {
                _clip = null;
            }
        }
        public function get clip():String {
            return _clip.name;
        }

Original comment by t...@tom-callahan.com on 6 Mar 2010 at 2:11