How to create motion-tween

Hello all!
I have some questions.
I have models “walk.egg” and “stand.egg”.
How can I create a motion-tween between the last frame of “stand” and the first frame of “walk” that makes the model moves from walking to standing so smooth…
Any idea?? Please show me some code.
Thank you.! :open_mouth:

That’s not a code issue, it’s a modeling issue. If you want a smooth transition you’ll have to create the appropriate animation.
Working that out in code would be far more complex, though it is possible to manipulate geometry in panda.

Actually, although it is true you will usually get superior results if you create a transition by hand, it is also possible to use Panda to do it procedurally. The trick is to put your Actor in blend mode, start or pose both animations, and then ramp the controlEffect of one animation down while you’re ramping the other one up, over a period of a few frames.

You can use the LerpAnimInterval to do this cross-fade for you fairly automatically. For instance:

from direct.directbase.DirectStart import *
from direct.interval.IntervalGlobal import *
from direct.actor.Actor import Actor

ralph = Actor('bvw-f2004--ralph/ralph.egg',
              {'walk' : 'bvw-f2004--ralph/ralph-walk.egg',
               'run' : 'bvw-f2004--ralph/ralph-run.egg',
               'jump' : 'bvw-f2004--ralph/ralph-jump.egg',
               })
ralph.reparentTo(render)

# Put Ralph in blend mode, to enable multiple animations at once.
ralph.enableBlend()

# Start both cycle animations running.  They'll play indefinitely, but
# until we call setControlEffect(), they won't have any visible effect
# on Ralph.
ralph.loop('walk')
ralph.loop('run')

# Make an interval that alternates walking and running, by overlapping
# frames without regard to cycles.
i1 = Sequence(LerpAnimInterval(ralph, 1, 'walk', 'run'),
              Wait(3),
              LerpAnimInterval(ralph, 1, 'run', 'walk'),
              Wait(3))
i1.loop()

The above code sample starts Ralph’s walk and run cycles looping indefinitely, and then independently of that, it starts an interval that lerps back and forth from showing the walk animation to showing the run animation.

Notice that sometimes you get little hitches as it switches between the animations, and sometimes you don’t. This is because the walk and run animations are not in sync with each other, and sometimes the transition happens while his left foot happens to be moving forward in the walk animation at the same time it’s moving backward in the run animation, or something equally incompatible, and it ends up looking weird.

You can get better results by synchronizing the animations, which is especially important for an animation that isn’t a cycle, like the jump animation. Here’s an interval that alternates walking and jumping, by holding the last frame of walk and the first frame of jump during the transition (this is what the original poster suggested he wanted to do):

i2 = Sequence(ActorInterval(ralph, 'walk', loop = 1, duration = 3),
              LerpAnimInterval(ralph, 0.5, 'walk', 'jump'),
              ActorInterval(ralph, 'jump'),
              LerpAnimInterval(ralph, 0.5, 'jump', 'walk'),
              ActorInterval(ralph, 'walk', loop = 1, duration = 3))

Or, alternatively, you might want to let the walk animation continue to play while it’s ramping down, but hold the jump frame until the jump animation starts, and similarly on the transition back to walk:

i3 = Sequence(ParallelEndTogether(ActorInterval(ralph, 'walk', loop = 1, duration = 3),
                                  LerpAnimInterval(ralph, 0.5, 'walk', 'jump')),
              ActorInterval(ralph, 'jump'),
              Parallel(ActorInterval(ralph, 'walk', loop = 1, duration = 3),
                       LerpAnimInterval(ralph, 0.5, 'jump', 'walk')))

Finally, you don’t have to use the LerpAnimInterval at all; you can do this all with tasks or whatever custom code you dream up. The trick is just to fade the one animation out at the same time you’re fading the new animation in.

David

Thank you very much!
I got it! :laughing:

I heard that
it have an algorithm that can contact with bone in .egg file

i think it might help to change between 2 actions
better than blend mode

XNA engine have library to transform bone from 2 action
Panda3D can do this?
:blush:

Er, sorry, I don’t understand your question.

David

Heuh i did not understand either.
My wild guess would be that XNA (like Wildtangent a long time ago) has an action channel inside their animation.

An action channel allow you to associate Action (or Events with Callback) to specific frame of the animation.

Ex you have an animation from an Ent (from JRR tolkien) throwing objects.
You can add the Event “THROW_OBJECT” at the frame 22 (where the object is leaving the hand of the Ent).
This way it’s easy to synchronize code logic with animation

=>It’s like the End Event features of interval, but it’ not necessary on the End !!

Could be very usefull for P3D also.
Today i tried to emulated it by creating a Sequence interval that include
anim before event, then lambda to send event, then anim after event.

But it’s pretty “bloated” when you have 3 or more actions in the action channel…

Hello.

I’am newbie here.
I’am interest in “Cross Fade Blending” so I tried David’s reply and
it works very well.

But in David’s code is an infinite loop between walking and jumping.
So I thinks if I want to control the animation by myself, I have to use task.

Would you please show me a code , using task to built Cross Fade Blending without LerpAnimInterval.
(possible to apply it in Roaming ralph.)

Thank you~

Just use the interval as shown, but call play() instead of loop().

David

Gorn, is this what you mean?

it’s not exactly what I need
but it can apply for my job
:smiley:
thank you for your answer, Thaumaturge

Found this old thread.
LerpAnimInterval may be what I need.

To check my understanding, does using it require that blend mode be enabled and both anims be started 1st. The first code example does this but then never calls setControlEffect (as in other examples I’ve seen which enable blending)

Yes. LerpAnimInterval basically replaces the call to setControlEffect(), but doesn’t do anything else.

David

Thanks for the reply. I think this will make some of my combat animations look smoother.

I know this thread is old, but where can I get the jump animation egg for Ralph? I couldn’t find it in my Panda3d directory.

I don’t believe such an animation file has ever existed. It was just an abstract illustration in my technical discussion above.

David

Okay. The reason I asked was because I had seen this video with a jump animation. It’s certainly possible the animation was created by the video’s owner. I’ll try to contact him about it.

youtube.com/watch?v=if1Gz4ekhZE

Oh, wait, it looks like I referenced an actual filename for ‘jump’ up above. Maybe it did formerly exist. We used to have a gallery of models that were donated from various sources, including and especially past CMU/BVW projects, and one of them was the Ralph model. Perhaps that source of the model included a jump animation.

I’m not sure what happened to that gallery of models. It’s no longer advertised on the website here, so perhaps someone decided it was more trouble that its worth to maintain?

David

It still exists, it’s linked in the Manual only now, under Additional Resources, I think. Anyhow, here’s the link to said gallery.
panda3d.org/download/novers … allery.zip

Thanks,

While I have you, how would you tween from an animation to a pose?