Panda3D Manual: Loading Actors and Animations
<<prev | top | next>> |
## Actor Basics The python class `Actor` is designed to hold an animatable model and a set of animations. Since the Actor class inherits from the NodePath class, all NodePath functions are applicable to actors. Note, however, that Actor is a Python class that extends the C++ NodePath class. For the most part, you don't have to think about this: Actor inherits sensibly from NodePath and generally does what you expect. There are a few subtle oddities, though. When you attach an Actor into a scene graph, the low-level C++ Panda constructs only records the NodePath part of the Actor in the scene graph, which is fine as long as you also keep a pointer to the Actor instance in your Python objects. If you let the Actor destruct, however, its visible geometry will remain, but it will cease animating (because it is no longer an Actor). Also, even if you keep the Actor object around, if you retrieve a new pointer to the Actor from the scene graph (for instance, as returned by the collision system), you will get back just an ordinary NodePath, not an Actor. The Actor interface provides a high-level interface on the low-level Panda constructs. In Panda, the low-level node that performs the animation is called Character. You can see the Character node in the scene graph when you call `actor.ls()`. Do not confuse the Actor class with the ActorNode class, which is used for physics. They are completely unrelated classes with similar names. ## Using Actors The Actor class must be imported before any loading or manipulation of actors.
    from direct.actor.Actor import Actor
Once the module is loaded, the actor object must be constructed, and the model and animations must be loaded:
    nodePath = Actor()
    nodePath.loadModel(‘Model Path’)
    nodePath.loadAnims({‘Arbitrary Name1’:’Animation Path 1’})
    nodePath.loadAnims({‘Arbitrary Name2’:’Animation Path 2’})
Loading each animation requires a tuple: the name one is giving the animation and the path to the animation. This entire process can be shortened to a single command:
    nodePath = Actor('Model Path', {
      'Animation Name 1':'Animation Path 1',
      'Animation Name 2':'Animation Path 2',
    })
Animations may also be unloaded using the same tuple used in creating them.
    nodePath.unloadAnims({'Animation Name':'Animation Path'})
Although this is a rarely-used technique, it is possible to assemble a character model out of several separate pieces (separate models). This is further explained in the section Multi-Part Actors. Panda3D supports both skeletal animation and morph animations. ## Panda Filename Syntax The filenames used in the Actor constructor must follow Panda's filename conventions. See Loading Models for more information. Loading actors and animations utilizes the panda model path, the same as for static models.
<<prev | top | next>> |