direct.showbase.ShowBase

from direct.showbase.ShowBase import ShowBase, WindowControls, exitfunc

This module contains ShowBase, an application framework responsible for opening a graphical display, setting up input devices and creating the scene graph.

Inheritance diagram

Inheritance diagram of direct.showbase.ShowBase

class ShowBase(fStartDirect=True, windowType=None)[source]

Bases: direct.showbase.DirectObject.DirectObject

SetAllSfxEnables(self, bEnabled)[source]

Calls setActive(bEnabled) on all valid SFX managers.

__init__(self, fStartDirect=True, windowType=None)[source]

Opens a window, sets up a 3-D and several 2-D scene graphs, and everything else needed to render the scene graph to the window.

To prevent a window from being opened, set windowType to the string ‘none’ (or ‘offscreen’ to create an offscreen buffer). If this is not specified, the default value is taken from the ‘window-type’ configuration variable.

This constructor will add various things to the Python builtins scope, including this instance itself (under the name base).

addAngularIntegrator(self)[source]
addSfxManager(self, extraSfxManager)[source]
adjustWindowAspectRatio(self, aspectRatio)[source]

This function is normally called internally by windowEvent(), but it may also be called to explicitly adjust the aspect ratio of the render/render2d DisplayRegion, by a class that has redefined these.

attachInputDevice(self, device, prefix=None, watch=False)[source]

This function attaches an input device to the data graph, which will cause the device to be polled and generate events. If a prefix is given and not None, it is used to prefix events generated by this device, separated by a hyphen.

The watch argument can be set to True (as of Panda3D 1.10.3) to set up the default MouseWatcher to receive inputs from this device, allowing it to be polled via mouseWatcherNode and control user interfaces. Setting this to True will also make it generate unprefixed events, regardless of the specified prefix.

If you call this, you should consider calling detachInputDevice when you are done with the device or when it is disconnected.

backfaceCullingOff(self)[source]
backfaceCullingOn(self)[source]
changeMouseInterface(self, changeTo)[source]

Switch mouse action

closeWindow(self, win, keepCamera=False, removeWindow=True)[source]

Closes the indicated window and removes it from the list of windows. If it is the main window, clears the main window pointer to None.

config = <module 'direct.showbase.DConfig' from '/opt/hostedtoolcache/Python/3.7.6/x64/lib/python3.7/site-packages/direct/showbase/DConfig.py'>
createBaseAudioManagers(self)[source]
createStats(self, hostname=None, port=None)[source]
destroy(self)[source]

Call this function to destroy the ShowBase and stop all its tasks, freeing all of the Panda resources. Normally, you should not need to call it explicitly, as it is bound to the exitfunc and will be called at application exit time automatically.

This function is designed to be safe to call multiple times.

detachInputDevice(self, device)[source]

This should be called after attaching an input device using attachInputDevice and the device is disconnected or you no longer wish to keep polling this device for events.

You do not strictly need to call this if you expect the device to be reconnected (but be careful that you don’t reattach it).

disableAllAudio(self)[source]
disableMouse(self)[source]

Temporarily disable the mouse control of the camera, either via the drive interface or the trackball, whichever is currently in use.

disableParticles(self)[source]
enableAllAudio(self)[source]
enableMouse(self)[source]

Reverse the effect of a previous call to disableMouse(). useDrive() also implicitly enables the mouse.

enableMusic(self, bEnableMusic)[source]
enableParticles(self)[source]
enableSoftwareMousePointer(self)[source]

Creates some geometry and parents it to render2d to show the currently-known mouse position. Useful if the mouse pointer is invisible for some reason.

enableSoundEffects(self, bEnableSoundEffects)[source]
finalizeExit(self)[source]
getAlt(self)[source]
getAspectRatio(self, win=None)[source]
getAxes(self)[source]
getBackgroundColor(self, win=None)[source]

Returns the current window background color. This assumes the window is set up to clear the color each frame (this is the normal setting).

getControl(self)[source]
getExitErrorCode(self)[source]
getMeta(self)[source]
getRepository(self)[source]
getShift(self)[source]
getSize(self, win=None)[source]
initShadowTrav(self)[source]
isParticleMgrEnabled(self)[source]
isPhysicsMgrEnabled(self)[source]
loadMusic(self, name)[source]
loadSfx(self, name)[source]
makeAllPipes(self)[source]

Creates all GraphicsPipes that the system knows about and fill up self.pipeList with them.

makeCamera(self, win, sort=0, scene=None, displayRegion=(0, 1, 0, 1), stereo=None, aspectRatio=None, clearDepth=0, clearColor=None, lens=None, camName='cam', mask=None, useCamera=None)[source]

Makes a new 3-d camera associated with the indicated window, and creates a display region in the indicated subrectangle.

If stereo is True, then a stereo camera is created, with a pair of DisplayRegions. If stereo is False, then a standard camera is created. If stereo is None or omitted, a stereo camera is created if the window says it can render in stereo.

If useCamera is not None, it is a NodePath to be used as the camera to apply to the window, rather than creating a new camera.

makeCamera2d(self, win, sort=10, displayRegion=(0, 1, 0, 1), coords=(-1, 1, -1, 1), lens=None, cameraName=None)[source]

Makes a new camera2d associated with the indicated window, and assigns it to render the indicated subrectangle of render2d.

makeCamera2dp(self, win, sort=20, displayRegion=(0, 1, 0, 1), coords=(-1, 1, -1, 1), lens=None, cameraName=None)[source]

Makes a new camera2dp associated with the indicated window, and assigns it to render the indicated subrectangle of render2dp.

makeDefaultPipe(self, printPipeTypes=None)[source]

Creates the default GraphicsPipe, which will be used to make windows unless otherwise specified.

makeModulePipe(self, moduleName)[source]

Returns a GraphicsPipe from the indicated module, e.g. ‘pandagl’ or ‘pandadx9’. Does not affect base.pipe or base.pipeList.

movie(self, namePrefix='movie', duration=1.0, fps=30, format='png', sd=4, source=None)[source]

Spawn a task to capture a movie using the screenshot function.

Parameters
  • namePrefix (str) – used to form output file names (can include path information (e.g. ‘/i/beta/frames/myMovie’)

  • duration (float) – the length of the movie in seconds

  • fps (float) – the frame rate of the resulting movie

  • format (str) – specifies output file format (e.g. png, bmp)

  • sd (int) – specifies number of significant digits for frame count in the output file name (e.g. if sd = 4, the name will be something like movie_0001.png)

  • source – the Window, Buffer, DisplayRegion, or Texture from which to save the resulting images. The default is the main window.

Returns

A Task that can be awaited.

notify = <direct.directnotify.Notifier.Notifier object>
oobe(self, cam=None)[source]

Enable a special “out-of-body experience” mouse-interface mode. This can be used when a “god” camera is needed; it moves the camera node out from under its normal node and sets the world up in trackball state. Button events are still sent to the normal mouse action node (e.g. the DriveInterface), and mouse events, if needed, may be sent to the normal node by holding down the Control key.

This is different than useTrackball(), which simply changes the existing mouse action to a trackball interface. In fact, OOBE mode doesn’t care whether useDrive() or useTrackball() is in effect; it just temporarily layers a new trackball interface on top of whatever the basic interface is. You can even switch between useDrive() and useTrackball() while OOBE mode is in effect.

This is a toggle; the second time this function is called, it disables the mode.

oobeCull(self, cam=None)[source]

While in OOBE mode (see above), cull the viewing frustum as if it were still attached to our original camera. This allows us to visualize the effectiveness of our bounding volumes.

openDefaultWindow(self, *args, **kw)[source]
openMainWindow(self, *args, **kw)[source]

Creates the initial, main window for the application, and sets up the mouse and render2d structures appropriately for it. If this method is called a second time, it will close the previous main window and open a new one, preserving the lens properties in base.camLens.

The return value is true on success, or false on failure (in which case base.win may be either None, or the previous, closed window).

openWindow(self, props=None, fbprops=None, pipe=None, gsg=None, host=None, type=None, name=None, size=None, aspectRatio=None, makeCamera=True, keepCamera=False, scene=None, stereo=None, unexposedDraw=None, callbackWindowDict=None, requireWindow=None)[source]

Creates a window and adds it to the list of windows that are to be updated every frame.

props is the WindowProperties that describes the window.

type is either ‘onscreen’, ‘offscreen’, or ‘none’.

If keepCamera is true, the existing base.cam is set up to render into the new window.

If keepCamera is false but makeCamera is true, a new camera is set up to render into the new window.

If unexposedDraw is not None, it specifies the initial value of GraphicsWindow.setUnexposedDraw().

If callbackWindowDict is not None, a CallbackGraphicWindow is created instead, which allows the caller to create the actual window with its own OpenGL context, and direct Panda’s rendering into that window.

If requireWindow is true, it means that the function should raise an exception if the window fails to open correctly.

playMusic(self, music, looping=0, interrupt=1, volume=None, time=0.0)[source]
playSfx(self, sfx, looping=0, interrupt=1, volume=None, time=0.0, node=None, listener=None, cutoff=None)[source]
popCTrav(self)[source]
printEnvDebugInfo(self)[source]

Print some information about the environment that we are running in. Stuff like the model paths and other paths. Feel free to add stuff to this.

pushCTrav(self, cTrav)[source]
removeCameraFrustum(self)[source]
restart(self, clusterSync=False, cluster=None)[source]
reviveInput(self)[source]

Restores inputs after a previous call to silenceInput.

run(self)[source]

This method runs the TaskManager when self.appRunner is None, which is to say, when we are not running from within a p3d file. When we are within a p3d file, the Panda3D runtime has to be responsible for running the main loop, so we can’t allow the application to do it.

saveCubeMap(self, namePrefix='cube_map_#.png', defaultFilename=0, source=None, camera=None, size=128, cameraMask= 0111 1111 1111 1111 1111 1111 1111 1111, sourceLens=None)[source]

Similar to screenshot(), this sets up a temporary cube map Texture which it uses to take a series of six snapshots of the current scene, one in each of the six cube map directions. This requires rendering a new frame.

Unlike screenshot(), source may only be a GraphicsWindow, GraphicsBuffer, or DisplayRegion; it may not be a Texture.

camera should be the node to which the cubemap cameras will be parented. The default is the camera associated with source, if source is a DisplayRegion, or base.camera otherwise.

The return value is the filename if successful, or None if there is a problem.

saveSphereMap(self, namePrefix='spheremap.png', defaultFilename=0, source=None, camera=None, size=256, cameraMask= 0111 1111 1111 1111 1111 1111 1111 1111, numVertices=1000, sourceLens=None)[source]

This works much like saveCubeMap(), and uses the graphics API’s hardware cube-mapping ability to get a 360-degree view of the world. But then it converts the six cube map faces into a single fisheye texture, suitable for applying as a static environment map (sphere map).

For eye-relative static environment maps, sphere maps are often preferable to cube maps because they require only a single texture and because they are supported on a broader range of hardware.

The return value is the filename if successful, or None if there is a problem.

screenshot(self, namePrefix='screenshot', defaultFilename=1, source=None, imageComment='')[source]

Captures a screenshot from the main window or from the specified window or Texture and writes it to a filename in the current directory (or to a specified directory).

If defaultFilename is True, the filename is synthesized by appending namePrefix to a default filename suffix (including the filename extension) specified in the Config variable screenshot-filename. Otherwise, if defaultFilename is False, the entire namePrefix is taken to be the filename to write, and this string should include a suitable filename extension that will be used to determine the type of image file to write.

Normally, the source is a GraphicsWindow, GraphicsBuffer or DisplayRegion. If a Texture is supplied instead, it must have a ram image (that is, if it was generated by makeTextureBuffer() or makeCubeMap(), the parameter toRam should have been set true). If it is a cube map texture as generated by makeCubeMap(), namePrefix should contain the hash mark (‘#’) character.

The return value is the filename if successful, or None if there is a problem.

setAspectRatio(self, aspectRatio)[source]

Sets the global aspect ratio of the main window. Set it to None to restore automatic scaling.

setBackgroundColor(self, r=None, g=None, b=None, a=0.0, win=None)[source]

Sets the window background color to the indicated value. This assumes the window is set up to clear the color each frame (this is the normal setting).

The color may be either a VBase3 or a VBase4, or a 3-component tuple, or the individual r, g, b parameters.

setFrameRateMeter(self, flag)[source]

Turns on or off (according to flag) a standard frame rate meter in the upper-right corner of the main window.

setMouseOnNode(self, newNode)[source]
setSceneGraphAnalyzerMeter(self, flag)[source]

Turns on or off (according to flag) a standard frame rate meter in the upper-right corner of the main window.

setSleep(self, amount)[source]

Sets up a task that calls python ‘sleep’ every frame. This is a simple way to reduce the CPU usage (and frame rate) of a panda program.

setupDataGraph(self)[source]

Creates the data graph and populates it with the basic input devices.

setupMouse(self, win, fMultiWin=False)[source]

Creates the structures necessary to monitor the mouse input, using the indicated window. If the mouse has already been set up for a different window, those structures are deleted first.

The return value is the ButtonThrower NodePath created for this window.

If fMultiWin is true, then the previous mouse structures are not deleted; instead, multiple windows are allowed to monitor the mouse input. However, in this case, the trackball controls are not set up, and must be set up by hand if desired.

setupMouseCB(self, win)[source]
setupRender(self)[source]

Creates the render scene graph, the primary scene graph for rendering 3-d geometry.

setupRender2d(self)[source]

Creates the render2d scene graph, the primary scene graph for 2-d objects and gui elements that are superimposed over the 3-d geometry in the window.

setupRender2dp(self)[source]

Creates a render2d scene graph, the secondary scene graph for 2-d objects and gui elements that are superimposed over the 2-d and 3-d geometry in the window.

setupWindowControls(self, winCtrl=None)[source]
showCameraFrustum(self)[source]
shutdown(self)[source]
silenceInput(self)[source]

This is a heavy-handed way of temporarily turning off all inputs. Bring them back with reviveInput().

spawnTkLoop(self)[source]

Call this method to hand the main loop over to Tkinter. This sets up a timer callback so that Panda still gets updated, but Tkinter owns the main loop (which seems to make it happier than the other way around).

spawnWxLoop(self)[source]

Call this method to hand the main loop over to wxPython. This sets up a wxTimer callback so that Panda still gets updated, but wxPython owns the main loop (which seems to make it happier than the other way around).

startDirect(self, fWantDirect=1, fWantTk=1, fWantWx=0)[source]
startTk(self, fWantTk=True)[source]
startWx(self, fWantWx=True)[source]
textureOff(self)[source]
textureOn(self)[source]
tkRun(self)[source]

This method replaces base.run() after we have called spawnTkLoop(). Since at this point Tkinter now owns the main loop, this method is a call to tkRoot.mainloop().

toggleBackface(self)[source]
toggleParticles(self)[source]
toggleShowVertices(self)[source]

Toggles a mode that visualizes vertex density per screen area.

toggleTexMem(self)[source]

Toggles a handy texture memory watcher. See TexMemWatcher for more information.

toggleTexture(self)[source]
toggleWireframe(self)[source]
updateManagers(self, state)[source]
useDrive(self)[source]

Switch mouse action to drive mode

useTrackball(self)[source]

Switch mouse action to trackball mode

userExit(self)[source]
windowEvent(self, win)[source]
wireframeOff(self)[source]
wireframeOn(self)[source]
wxRun(self)[source]

This method replaces base.run() after we have called spawnWxLoop(). Since at this point wxPython now owns the main loop, this method is a call to wxApp.MainLoop().

class WindowControls(win, cam=None, camNode=None, cam2d=None, mouseWatcher=None, mouseKeyboard=None, closeCmd=<function WindowControls.<lambda>>, grid=None)[source]

Bases: object

__init__(self, win, cam=None, camNode=None, cam2d=None, mouseWatcher=None, mouseKeyboard=None, closeCmd=<function WindowControls.<lambda>>, grid=None)[source]
exitfunc()[source]