Controlling DAE animations in Papervision3d
-Works with papervision rev 910 and below (idk how much below xD)-
I just uploaded a new version of DAEMC to the trunk. This time i had to modify more files to be able to implement a feature that i think is very nice to have. And that is: controlling the animation speed smoothly. This is usefull to make matrix like effects or just for smoothing animations.
DEMO (421Kb no loader)
Video tutorial HD
How it works now?
Imagine the DAE timeline as a simple flash timeline, like this:
with DAEMC v.1 you could change the FPS of the animation and what that did was jumping frames skipping some of them resulting in a jumping animation. Now with DAEMC2 the timeline is like this one:
and it behaves similar to a motion tween timeline in flash CS4, where you can stretch the animation making it smoother, like this:
now new frames are created between the original keyframes by interpolating them (simple linear interpolation) getting a nice and smooth animation. This is made by editing a new poperty called Xframes (read-write), for example, in the image above the Xframe whould be 3, because you had 3 frames in between each frame, so as in a motion tween timeline, you can stretch the frames all you want, but not compressing them. In the DAEMC v.1 you could change the FPS to a lower rate but i decided not to implement that because i thought that doing that was always going to result in a jumpy animation… but you can still do it if you want by using a Tween engine in the curentFrameNumber property (in theory, not tested…).
This is the biggest change in the DAEMC class, but i had to edit some core files in papervision3d to get this done:
- org.papervision3d.core.animation.channel.AbstractChannel3D: added a new method updateSmoothlyToTime()
- org.papervision3d.core.animation.channel.MatrixChannel3D: override the AbstrachtChannel3D updateSmoothlyToTime
- org.papervision3d.objects.DisplayObject3D: this is the key element, added gotoTransform(), this method make the interpolation.
- a brand new org.papervision3d.objects.special .DAEMC2
From DAEMC to DAEMC2:
- added> get/set Xframes():uint > add new frames between original frames. 0 is the original frames of the animation.
- deleted> get/set fps(newFPS:uint):void //now this is controlled by Xframes
- unchanged> get totalFrames():uint
- unchanged> get currentFrame():uint
- added> currentFrameNumber(frame:Number):void > curentFrameNumber is the curent frame + de decimal value is the distance between that frame and the next one… example: 1.5 will be frame 1 in the middle between frame 1 and 2.
- unchanged> get isPlaying():Boolean
- deleted> setFrameLabel(frame:uint, name:String = null):void
- deleted> gotoAndPlay(frame:Object):void
- deleted> gotoAndStop(frame:Object):void
- unchanged> addFrameScript(frame:uint, callback:Function = null):void
- added> get/set inReverse():Boolean > Set this to true if you want the animation to play backwards
- How do i do a gotoAndPlay o gotoAndStop now? -you can do that by setting the fame you want .curentFrameNumber = X and then calling a .stop() or play()
- Why you deleted addFrameLabel? -I make myself the same question… i’ll probably add it… depends on the feedback.
- How to i change the speed of an animation at runtime? -you can set or call the Xframe property of the DAEMC2 instance.
- Why addFrameScript take an uint but curentFrameNumber is a Number? -you can only set actions on the oiginal frames of the animation. I could add the posibility later… dpending on the feedback is people will use it.
- What if i want to make an animation faster? -well, i made the currentFrame get/set so you can make experiment with tween engnes… you could tween that property to mkae it go faster…
- How would I get a model to play in reverse? doing model_instance.inReverse = true; take in count that any frame script will be called…