Creating a New Panda3D Application
To start Panda3D, create a text file and save it with the .py extension. PYPE, SPE and IDLE are Python-specific text-editors, but any text editor will work. Enter the following text into your Python file:
from direct.showbase.ShowBase import ShowBase
app = MyApp()
Here we made our main class inherit from
ShowBase. The ShowBase class loads most of the other Panda3D modules, and causes the 3D window to appear. The
run() procedure in ShowBase contains the Panda3D main loop. It renders a frame, handles the background tasks, and then repeats. It does not normally return, so it needs to be called only once and must be the last line in your script. In this particular example, there will be nothing to render, so you should expect a window containing an empty grey area.
DirectStart is a shortcut that instantiates ShowBase automatically on import. This may be useful for quick prototyping at the expense of clean code layout. The following example demonstrates its use:
The import line automatically constructs an instance of ShowBase, which starts the engine and creates an empty window. Because ShowBase uses Python's
__builtin__, its functions are allowed to be called without storing the instance in a variable. For the sake of cleanliness, the rest of this tutorial shall use the ShowBase subclass.
Running the Program
To run your program on Windows or Mac, enter the following in a terminal (command prompt):
To run it on GNU/Linux, enter the following in a terminal:
If Panda3D has been installed properly, a grey window titled Panda appears. There is nothing we can do with this window, but that will change shortly.