Panda3D Manual: Loading the Grassy Scenery
<<prev | top | next>> |
With Panda3D running properly, it is now possible to load some grassy scenery. Update your code as follows:
import direct.directbase.DirectStart #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) #Run the tutorial run()
The command `loader.loadModel()` loads the specified file, in this case the environment.egg file in the models folder. The return value is a 'NodePath', effectively a pointer to the model. Note that Panda Filename Syntax uses the forward-slash, even under Windows. Panda3D contains a data structure called the scene graph. The scene graph is a tree containing all objects that need to be rendered. At the root of the tree is an object named `render`. Nothing is rendered until it is first installed into the scene graph. To install the grassy scenery model into the scene graph, we use the method `reparentTo`. This sets the parent of the model, thereby giving it a place in the scene graph. Doing so makes the model visible. Finally, we adjust the position and scale of the model. In this particular case, the environment model is a little too large and somewhat offset for our purposes. The `setScale` and `setPosition` rescale and recenter the model. Go ahead and run the program. You should see this: The rock and tree appear to be hovering. The camera is slightly below ground, and backface culling is making the ground invisible to us. If we reposition the camera, the terrain will look better.
<<prev | top | next>> |