Animation

Now we've gone over the scene graph, models and lighting. But even with all of these things put together, our project probably isn't very exciting because nothing is moving yet! Animation really brings any 3D project to life, and we'll go over some of the simple Panda3D animation methods below.

Intervals

Intervals are one of the main ways to animate in Panda3D. Basically, they are a class within the Panda3D library that allow you to playback action sequences. For more detailed instructions on all the types of intervals there are, go to this page! Here, we will go over two types here: PosIntervals and HprIntervals.

First, if you want to use intervals, make sure you include them at the top of your file:

from direct.interval.IntervalGlobal import *
PosIntervals and HprIntervals

PosIntervals are used to move the position of a model over a period of time. HprIntervals are used to change the orientation of a model over a period of time. There are two parts to making an interval: creating it and actually playing it. You can create an interval in the following way:

self.myInterval1 = self.cat.posInterval(t, (newX, newY, newZ)
self.myInterval2 = self.hat.hprInterval(t, (newH, newP, newR)

To go more in depth, the first line of code will move the model self.cat into the position (newX, newY, newZ), across a period of t seconds. Remember, this only creates the interval, it doesn't actually play it.

Basic Interval Methods

There are many ways to manipulate intervals, but here are some of the most basic methods you might need to use (they are all self-explanatory):

interval.start()
interval.start(startTime, endTime, playRate)
interval.loop()
interval.loop(startTime, endTime, playRate)

interval.pause()
interval.finish()
interval.resume()

You will most likely use the start() and loop() methods the most frequently. This is how we actually play the animations.

Sequences and Parallels

Sequences and Parallels are ways to combine intervals, and give Intervals their real power. You can use them to layer multiple intervals after & on top of each other, allowing you to create much more complicated movement in your program!

Sequences are used to play intervals one after another, while Parallels play intervals at the same time. However, the code for them is very similar! You can create them in the following way:

mySequence = Sequence(self.myInterval1, self.myInterval2)
myParallel = Parallel(self.myInterval1, self.myInterval2)

You can also append intervals:

mySequence.append(myInterval3)

And you can play them:

mySequence.start()
myParallel.play()

results matching ""

    No results matching ""