What is Panda3D?

Panda3D is a 3D engine: a library of subroutines for 3D rendering and game development. The library is C++ with a set of Python bindings. Game development with Panda3D usually consists of writing a Python program that controls the the Panda3D library.

Panda3D is unusual in that its design emphasis is on supporting a short learning curve and rapid development. It is ideal whenever deadlines are tight and turnaround time is of the essence.


Solar System(scene graph) Tutorial

This tutorial is intended as an initial panda scripting lesson going over display initialization, loading objects, placing objects, and the scene graph. When models are loaded, they are loaded into a node. Information such as position, orientation, color, and texture is stored on the nodes of a scene graph. A NodePath connects two nodes and serves to form a hierarchy. This hierarchy is visible in the scene graph. For more information on the scene graph, please consult the Panda3D online manual.

The following image represents the final scene graph for the solar system tutorial. This image does not include every single node in the scene graph but will suffice for demonstrating the concepts of the hierarchy of the solar system.




As you can see, the highest node in this graph is 'Render'. Render isn't an object that has any geometry. Every node that is connected to Render (directly and through other nodes) will be rendered (visible) if it has geometry associated with it. By default, loading models will not parent (connect) them to any other nodes including Render. For a model to be rendered, it must be somehow connected to Render. For example, self.moon is the node that contains the geometry for the moon but it isn't connected directly to render. However, it will still be rendered on screen since there is a path from self.moon to Render through self.orbi_root_moon and self.orbit_root_earth. Also note that all the nodes in the above picture with the self.orbit_root prefix contain no geometry but still contain attributes like position, orientation, color etc. Children nodes will inherit attributes of their parents. For instance, when self.orbit_root_earth moves, all of the nodes connected to it will move in unison. This feature will be used extensively in this tutorial as the solar system can be simluated very nicely with a hierarchal structure.

This tutorial is broken down into 4 steps. The complete python code for each step is located in the main folder of the tutorial. The code at each step is executable and each one will produce a different result when executed. Since Panda is invoked via a python script, each 'program' will be written in python with a file extension of .py. To excute the .py file, you should first open a command prompt. For windows users, click START->RUN. Type "cmd" without quotes and hit ENTER. This will open a command prompt window.
Now type "cd C:\Panda3D-1.0.2\Tutorials\Part 1 - Solar System(scene graph)\" and hit ENTER. This will take you into the tutorial directory for the solar system tutorial. To run a python script file, type "ppython" (without quotes) and the file name of the .py file you want to run at the command prompt. Hit ENTER and the script will run. For example, to execute the final script for the solar system, the command would be "ppython solar_system.py".


Step 1: DirectStart contains the main Panda3D modules, and importing them will cause the 3D window to appear. The run() command causes the real-time simulation to begin. Please refer to step_1_blank.py.



Step 2: After initializing panda, we will define a class called World. The code contained in the __init__ method will be executed when we instantiate class (towards the end of this file). Inside __init__ we will firstly change background color of the window. We then disable the mouse and set the camera position. Afterwards, we declare some variables we will need later. Please refer to step_2_black.py.



Step 3: This step loads the models for the sun and star/sky sphere in a function called 'loadPlanets' which we will call from __init__. Then they are assigned their respective textures and positions. Please refer to step_3_sun.py.



Step 4: Using the same loading technique, the rest of the planets are loaded and positioned respectively. The whole solar system up to mars is now complete. Please refer to step_4_system.py. The file solar_system.py puts these planets into motion using interval(which will be covered in the next tutorial.



Final: This is how the solar system should look when you run solar_system.py. This file includes intervals that will rotate the planets. Intervals will be dealt with in the next tutorial.