Now that the scenery is in place, we will now load an
actor. Update your code to look like this:
import direct.directbase.DirectStart
from direct.task import Task
from direct.actor import Actor
import math
#Load the first environment model
environ = loader.loadModel("models/environment")
environ.reparentTo(render)
environ.setScale(0.25,0.25,0.25)
environ.setPos(-8,42,0)
#Task to move the camera
def SpinCameraTask(task):
angledegrees = task.time * 6.0
angleradians = angledegrees * (math.pi / 180.0)
base.camera.setPos(20*math.sin(angleradians),-20.0*math.cos(angleradians),3)
base.camera.setHpr(angledegrees, 0, 0)
return Task.cont
taskMgr.add(SpinCameraTask, "SpinCameraTask")
#Load the panda actor, and loop its animation
pandaActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
pandaActor.setScale(0.005,0.005,0.005)
pandaActor.reparentTo(render)
pandaActor.loop("walk")
run()
|
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 command loop("walk") causes
the walk animation to begin looping. The result is a panda walking in
place, as if on a treadmill:
|