Jump to content

Play bone animation backward, reverse animation


getzel
 Share

Recommended Posts

Hello !

Is it possible to play a bone animation (created in Blender) backward ?

For example : we make strafe right and want to play strafe left via code.

I imagine something like : scene.beginAnimation(skeleton, 40, 0, true, 1.0);

 

Do you think it's a cool feature ?

Implemeting all reverse animations in Blender is not complicated but heavy.

Link to comment
Share on other sites

Hiya getzel!  Yeah, it's a cool feature idea, for sure, but BJS animation keys need to be in ascending order, according to Deltakosh.  

In a different post, I pondered (long-winded) a CYCLEMODE_PINGPONG for animations... so they could run forward, then backward, then forward, then backward, etc.

In the next post, Deltakosh kindly told me some excellent info, and fixed my poorly-coded pingpong function. Playground:  http://www.babylonjs-playground.com/#1LNWLE#3

Lines 39-59 are the pingpong func, as you can see.  Essentially, it just reverses all the keys on the animations of all bones, and calls beginAnimation again.

So, although an invertKeys parameter/flag for our animation system might be a decent new feature, it might not be used often enough to warrant the change/mod.  Perhaps a wiser move would be to code/steal a very fast/efficient array-reverser... for reversing animation keys.  The reverser in the pingpong func is pretty good, but it could be tightened-up a bit.

See line 61 in that #3 playground above?  The pingpong func is set as the onAnimationEnd parameter.  You would not be doing that.  What you might do... is create/maintain two different arrays of keys...  one for strafe left, one for strafe-right.  Able is my abbreviation for animatableOn our rabbit, there are 4 bones (each with animation), and line 42 is for looping through all 4 bones.  Line 54 installs the new keys on each bone's animation.

Rudy the Rabbit... is doing ping-pong animation pretty well, there.

Still, mesh.invertAnimationKeys() or perhaps Animatable.reverseAnimationKeys()... might be worthy of PR.  Not sure.  I usually delegate framework feature decisions... to Deltakosh.  He sees 'the big picture' far-better than I.  :)  Maybe Deltakosh will comment.

Hey, thanks for the idea, Getzel.  It is worthy of some consideration, for sure.  Party on!

PS:  The #8 playground puts some texture back-onto Rudy.  It might be interesting to note that the boundingBox does not follow Rudy's reclining.  Know why?  Sure we do.  Rudy the Model... never changed rotation.  He/She stayed in one place, but the animation on his/her non-mesh "bones"... moved all his/her body parts.  Rudy never fell.  Only his/her body parts moved to horizontal (and back).  :D

Link to comment
Share on other sites

@Wingnut Thank you for your answer.  In fact reverse wouldn't work for strafe I think.

 

I tried on my model with an animation where the left leg rotates left (x direction). And with your fonction, it rotates toward z direction although it should rotate right (x direction).

Not the desired effect for the moment. But at least it has an effect.

 

Maybe i have to do more tests and study on that function.
 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...