Papervision .DAE Animation
I’ve been working on another little experiment with FLARToolkit/Papervision, but this time the model being used contains animations embedded with in the .DAE file. My first thoughts were to go directly for the yourdae.play(); method and this would have worked if my model only had a single animation, but it was rigged with several so it turned out to be a mess. I needed to find another way to gain access to thespecific spots that the animations began at, and play on that single animation. After picking through the papervision source code for a while with no luck, I headed to the mailing list and stumbled across a post that pointed me in the right direction. After reading over this post I had an idea of what needed to be done, and ended up with a method that looked similar to this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | private function DAEAnimationFromTo(fromFrame:Number, tooFrame:Number, needsBackwards:Boolean = false):void{ var curNumber:Number = fromFrame; var chans:Array = DAE.getAnimationChannels(); if(curNumber < tooFrame){ handleAnim(); } else { if(needsBackwards){ trace('>> play backwards'); DAEAnimationToFrom(tooFrame, fromFrame); } } function handleAnim():void{ trace('anim'); curNumber += 1; for each(var chan:AbstractChannel3D in chans){ chan.updateToFrame(curNumber); } if(curNumber <= tooFrame){ setTimeout(handleAnim, Math.floor( stage.FrameRate / 1000 ) * 100); } } } |
With this method I was able to input the start and ending “frames” for the animation as numbers, and use those values to loop over those sections with in the .DAE file. If the animation is one that needs to be played both forwards and backwards, the method will check for that, and re-call a similar method that plays the animation in reverse. The steps this method goes through are:
1. obtain all of the channel information from the .DAE object
2. check to see if the current frame is less in value then the next frame that you want to goto
3. if so loop over all channels from the .DAE and move them forward 1 frame
4. set a time out value based upon your frame rate, to maintain proper animation speed.
Now this is only a method that I have found to work good for me. If you have other ideas on how to animate .DAE files, perhaps even in a totally different way, please let me know down in the comments. I’d love to hear what you have to say.
Tagged as .DAE, animation, AS3, Flash, functions, methods, Papervision + Categorized as AS3, AS3, Papervision
4 Comments
Trackbacks & Pingbacks
-
PV3D & DAE Animation | bobarb.com
[...] frame to a numbered frame. A lot like a gotoAndPlay in flash but a little more complicated. Here is a great tutorial for controlling animation. I based some of my code off of this. Categories : MU [...]
OH! It`s useful,Thank u very much!
There is a function embedded in the dae parser that does this now. Just import:
import org.papervision3d.core.animation.clip.AnimationClip3D;
and use the addClip function in your code:
dae.animation.addClip(new AnimationClip3D(“clip1″,0,1));
However, this solution cannot work backwards.
I wrote more about this at:
http://www.gotoandlearnforum.com/viewtopic.php?f=17&t=28324
thanks Doug… that’s great…