Skip to content
Home » Panda3D Part 20 – Testing the Animations in Panda3D

Panda3D Part 20 – Testing the Animations in Panda3D

Spread the love

In the previous part of the Panda3D series we animated our slug model. Today let’s test the animations in Panda3D.

Exporting the Model

Before we test the animations, we must export the slug actor from Blender and then load it in Panda3D. As you know, in Panda3D characters are called actors and they are loaded in a different way than static models.

Open the slug.blend file in Blender. First of all, we don’t need the Empty with the slug image anymore, so just go ahead and delete it from the outliner. You can also rename Armature ‘slug_actor’:

blender

Go to object mode and select all. Next, go to the File menu and under Export select glTF.

Just like with the terrain model before, select the glTF Separate option (A), type ‘tex’ as the name of the texture folder (B), and check the Remember Export Settings checkbox (C).

Under Include check Selected Objects (D). Under Transform make sure +Y Up is selected (E). Under Geometry make sure UVs, Normals and Vertex Colors are selected (F), which they should be by default:

blender

Then hit the Export glTF 2.0 button. The slug model has been exported.

Loading the Model

Now, open the project folder in VSC or your editor of choice and in the test.py file add code that will load the slug under the code that loads the terrain:

# File name: test.py

from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties
from panda3d.core import load_prc_file

# We need the Actor class to load actors.
from direct.actor.Actor import Actor

import simplepbr

load_prc_file('myConfig.prc')

class Slugrace3D(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        simplepbr.init()

        # Let's load and position the terrain.
        self.terrain = loader.loadModel("models/terrain/terrain.gltf")
        self.terrain.setPos(0, 0, -1)
        self.terrain.reparentTo(render)           

        # Let's import, position, scale and rotate the actor.
        self.slug = Actor("actors/slug/slug.gltf")
        self.slug.setPos(0, 0, -1)
        self.slug.setScale(10, 10, 10)
        self.slug.setH(90)
        self.slug.reparentTo(render) 

app = Slugrace3D()
app.run()

Now run the app. To see the actor, navigate in the window slightly until you can see the slug:

Loading the Model

Your Panda3D Magazine

Make Awesome Games and Other 3D Apps

with Panda3D and Blender using Python.

Cool stuff, easy to follow articles.

Get the magazine here (PDF).

Testing the Animations in Panda3D

We’re ready to test the animations now. The animations have been exported from Blender along with the model and we can access them by the names of the actions. We use the play method to play an animation once and the loop method to loop it.

So, let’s start with the idle animation. Here’s how we can loop it in Panda3D:

# File name: test.py

...

class Slugrace3D(ShowBase):
    def __init__(self):
        ...

        # Let's import, position, scale and rotate the actor.
        self.slug = Actor("actors/slug/slug.gltf")
        self.slug.setPos(0, 0, -1)
        self.slug.setScale(10, 10, 10)
        self.slug.setH(90)
        self.slug.reparentTo(render) 

        # play animation
        self.slug.loop('idle')

app = Slugrace3D()
app.run()

Now you can see the looping idle animation:

Testing the Animations in Panda3D

In a similar way you can test all the other animations. Just pass their names as an argument to the loop method.

It may happen that some of the actions have not been exported. If this is the case, go back to Blender, select those animations one by one and hit the Stash button for each of them:

stash button

Then you have to export the model again.

So, now we have tested all our animations in Panda3D. They work. So, let’s finally start programming our game.

Python Jumpstart Course

Learn the basics of Python, including OOP.

with lots of exercises, easy to follow

The course is available on Udemy.

Blender Jumpstart Course

Learn the basics of 3D modeling in Blender.

step-by-step, easy to follow, visually rich

The course is available on Udemy and on Skillshare.


Spread the love
Tags:

Leave a Reply