Built-in Global Variables
When an instance of the ShowBase
class
is created, many of its member variables are written to the built-in scope
of the Python interpreter, making them available to any Python module without
the need for extra imports.
While these are handy for prototyping, we do not recommend using them in bigger projects as it can make the code confusing to read to other Python developers to whom it may not be obvious from where these variables are originating.
Many of these built-in variables are alternatively accessible as members of
the global base
instance, or can instead be imported from the
ShowBaseGlobal
module.
The variables written to the built-in scope are:
- base
A global instance of the
ShowBase
class is available to any Python scope asbase
. This allows access to the graphical display, the scene graph, the input devices, the task and event managers, and all the other things that ShowBase is responsible for setting up and managing.Although it is not a required component, most Panda3D applications are created using the ShowBase abstraction layer, because it sets up nearly everything needed by most games and simulations, with only a minimal amount of set up required. In fact, to start up a ShowBase application, it is only necessary to call:
from direct.showbase.ShowBase import ShowBase base = ShowBase() base.run()
There can only be one ShowBase instance at a time; call
destroy()
to get rid of it, which will allow another instance to be created.- Type
.ShowBase
- render
A NodePath created as the root of the default 3-D scene graph. Parent models to this node to make them show up in the 3-D display region.
- Type
- render2d
Like
render
, but created as root of the 2-D scene graph. The coordinate system of this node runs from -1 to 1, with the X axis running from left to right and the Z axis from bottom to top.- Type
- aspect2d
The root of the 2-D scene graph used for GUI rendering. Unlike
render2d
, which may result in elements being stretched in windows that do not have a square aspect ratio, this node is scaled automatically to ensure that nodes parented to it do not appear stretched.- Type
- pixel2d
This is a variant of
aspect2d
that is scaled up such that one Panda unit is equal to one pixel on screen. It can be used if pixel-perfect layout of UI elements is desired. Its pixel origin is also in the top-left corner of the screen. Because Panda uses a Z-up coordinate system, however, please note that the Z direction goes up the screen rather than down, and therefore it is necessary to use negative instead of positive coordinates in the Z direction.- Type
This is a scene graph that is not used for anything, to which nodes can be parented that should not appear anywhere. This is esoteric and rarely needs to be used; the use of
stash()
will suffice in most situations wherein a node needs to be temporarily removed from the scene graph.- Type
- camera
A node that is set up with the camera used to render the default 3-D scene graph (
render
) attached to it. This is the node that should be used to manipulate this camera, but please note that it is necessary to first callbase.disableMouse()
to ensure that the default mouse controller releases its control of the camera.- Type
- loader
This is the primary interface through which assets such as models, textures, sounds, shaders and fonts are loaded. See Model Files and Simple Texture Replacement.
- Type
- taskMgr
The global task manager, as imported from
direct.task.TaskManagerGlobal
.- Type
- jobMgr
The global job manager, as imported from
direct.showbase.JobManagerGlobal
.- Type
- eventMgr
The global event manager, as imported from
direct.showbase.EventManagerGlobal
.- Type
- messenger
The global messenger, imported from
direct.showbase.MessengerGlobal
, is responsible for event handling. The most commonly used method of this object is perhapsmessenger.send("event")
, which dispatches a custom event.- Type
- bboard
The global bulletin board, as imported from
direct.showbase.BulletinBoardGlobal
.- Type
- ostream
The default Panda3D output stream for notifications and logging, as a short-hand for
Notify.out()
.- Type
- globalClock
The clock object used by default for timing information, a short-hand for
ClockObject.get_global_clock()
.The most common use is to obtain the time elapsed since the last frame (for calculations in movement code), using
globalClock.dt
. The value is given in seconds.Another useful function is to get the frame time (in seconds, since the program started):
frameTime = globalClock.getFrameTime()
This is now deprecated, use
base.clock
instead.- Type
- vfs
A global instance of the virtual file system, as a short-hand for
VirtualFileSystem.get_global_ptr()
.- Type
- cpMgr
Provides access to the loaded configuration files. Short-hand for
ConfigPageManager.get_global_ptr()
.- Type
- cvMgr
Provides access to configuration variables. Short-hand for
ConfigVariableManager.get_global_ptr()
.
- pandaSystem
Provides information about the Panda3D distribution, such as the version, compiler information and build settings. Short-hand for
PandaSystem.get_global_ptr()
.- Type
- inspect(obj)[source]
Short-hand for
direct.tkpanels.Inspector.inspect()
, which opens up a GUI panel for inspecting an object’s properties.See Utility Functions.
- config
The deprecated
DConfig
interface for accessing config variables.
- run()
Calls the task manager main loop, which runs indefinitely. This is a deprecated short-hand for
base.run()
.See Main Loop.