RANDOM USER PROJECTS
Flight Simulator, created by Carnegie Mellon students
Flight Simulator, created by Carnegie Mellon students
Epoch: a space combat game

Panda3D Manual: Loading and Animating the Panda Model

Contents

Actors

The Actor class is for animated models. Note that we use loadModel() for static models and Actor only when they are animated. The two constructor arguments for the Actor class are the name of the file containing the model and a Python dictionary containing the names of the files containing the animations.

The Program

Update the Code

Now that the scenery is in place, we will load an Actor. Update your code to look like this:

from math import pi, sin, cos
 
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
 
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
 
# Load the environment model.
self.environ = self.loader.loadModel("models/environment")
# Reparent the model to render.
self.environ.reparentTo(self.render)
# Apply scale and position transforms on the model.
self.environ.setScale(0.25, 0.25, 0.25)
self.environ.setPos(-8, 42, 0)
 
# Add the spinCameraTask procedure to the task manager.
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
 
# Load and transform the panda actor.
self.pandaActor = Actor("models/panda-model",
{"walk": "models/panda-walk4"})
self.pandaActor.setScale(0.005, 0.005, 0.005)
self.pandaActor.reparentTo(self.render)
# Loop its animation.
self.pandaActor.loop("walk")
 
# Define a procedure to move the camera.
def spinCameraTask(self, task):
angleDegrees = task.time * 6.0
angleRadians = angleDegrees * (pi / 180.0)
self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
self.camera.setHpr(angleDegrees, 0, 0)
return Task.cont
 
app = MyApp()
app.run()

The command loop("walk") causes the walk animation to begin looping.

Run the Program

The result is a panda walking in place as if on a treadmill:

Tutorial3.jpg