In the previous part of the Panda3D series we loaded the building model in Panda3D. But this is not the only model we’ll need for our game. Let’s have a look at the terrain model today.
In Panda3D we differentiate between models, which are static models, and actors, which are animated character models. We’ll have a look at the latter a bit later, and now let’s focus on the static models.
We already have the building model and you could see step by step how it was modeled and textured. We’ll also need a terrain model for the building to stand on, as well as a tent model and a tree model. Then we’re going to join all the models so that we have just one terrain model. Depending on how the game is played, it may be advisable to keep all models separate and load them individually in Panda3D, but for our simple game, let’s just join all the objects into one model.
Now, we’re not going to create the models from scratch. Instead you can grab the whole terrain model from my github repository. In my Panda3D book that I’m working on right now, I’m going to discuss each model in great detail so that you can follow along and create it from scratch. Generally I’m using the same techniques as for the building model and some more.
Create a terrain folder in the models folder and download the terrain model from github there. Here are all the parts of the terrain model discussed one by one.
Table of Contents
Terrain Plane
The actual terrain model is going to be very simple, just a plane. This is the world where everything will be placed, including the slugs. Here’s what it looks like:
Tent
Then we’ll need four tents, one for each slug. Here’s what a tent model will look like:
Tree
Then we’ll need some trees. They will be scattered all around the scene. A single tree will look like this:
The Joined Terrain Model
Now we can use all the separate models to create our final terrain model. Here it is:
We can now export this model to glTF and then import it in Panda3D. Here’s the code:
from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties
from panda3d.core import load_prc_file
import simplepbr
load_prc_file('myConfig.prc')
class Slugrace3D(ShowBase):
def __init__(self):
ShowBase.__init__(self)
simplepbr.init()
self.terrain = loader.loadModel("models/terrain/terrain.gltf")
# Let's position the terrain.
self.terrain.setPos(0, 0, -1)
self.terrain.reparentTo(render)
app = Slugrace3D()
app.run()
For this to work, make sure the terrain.gltf file is in the terrain folder, along with the textures:
And now, if you run the code, you will see the following:
Feel free to navigate the window and view the model from different angles:
Great tutorial! Please keep going with this! I am keen on to keep learning with your articles…
Thanks, I’m now also working on a Panda3D book, but I’ll be posting the following parts of the tutorial as soon as I can.
Thanks, I’m working on the Panda3D series, as well as on a Panda3D book, but also on other stuff like Kivy, Matplotlib and more. I hope you’ll enjoy it.