Panda3D is a framework for 3D rendering and game development for Python and C++ programs.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The ShowBase class provides the main application framework for Panda3D applications. It handles window creation, system initialization, main loop management, and provides access to core subsystems.
ShowBase is the foundation class for all Panda3D applications. It initializes the graphics system, creates the main window, and provides access to core engine subsystems.
class ShowBase:
def __init__(self, fStartDirect: bool = True, windowType: str = None) -> None:
"""
Initialize Panda3D application.
Args:
fStartDirect: Whether to start DirectStart subsystem
windowType: Graphics window type ('onscreen', 'offscreen', etc.)
"""
def run(self) -> None:
"""Start the main application loop. This method blocks until the application exits."""
def destroy(self) -> None:
"""Clean up and destroy the application."""
def userExit(self) -> None:
"""Handle user-initiated exit (window close, Alt+F4, etc.)."""
def finalExitCallbacks(self) -> None:
"""Execute final cleanup callbacks before exit."""
# Core subsystem access
loader: Loader # Asset loading system
render: NodePath # Main 3D scene root
render2d: NodePath # 2D overlay root
aspect2d: NodePath # Aspect-corrected 2D root
pixel2d: NodePath # Pixel-coordinate 2D root
camera: NodePath # Default 3D camera
cam: NodePath # Camera node (different from camera)
camNode: Camera # Actual camera object
cam2d: NodePath # 2D camera
taskMgr: TaskManager # Task scheduling system
messenger: Messenger # Event messaging system
eventMgr: EventManager # Event management
accept: callable # Event acceptance method
ignore: callable # Event ignore method
ignoreAll: callable # Ignore all events method
# Graphics and windowing
win: GraphicsWindow # Main graphics window
winList: List[GraphicsWindow] # All graphics windows
pipe: GraphicsPipe # Graphics pipe
# Audio system
sfxManagerList: List # Sound effect managers
musicManager # Music manager
# Input systems
mouseWatcherNode: MouseWatcher # Mouse input handling
buttonThrowers: List # Keyboard input handling
# Configuration and system
config: Config # Configuration systemControl graphics windows, display properties, and rendering pipeline configuration.
class ShowBase:
def openDefaultWindow(self, **props) -> bool:
"""Open the default graphics window with specified properties."""
def openMainWindow(self, **props) -> GraphicsWindow:
"""Open main graphics window."""
def closeWindow(self, win: GraphicsWindow) -> None:
"""Close a graphics window."""
def makeCamera(self,
win: GraphicsWindow,
sort: int = 0,
displayRegion: DisplayRegion = None,
camName: str = 'cam') -> NodePath:
"""Create a camera for a graphics window."""
def setupRender(self) -> None:
"""Initialize the 3D rendering system."""
def setupRender2d(self) -> None:
"""Initialize the 2D overlay system."""
def enableParticles(self) -> None:
"""Enable particle system rendering."""
def disableParticles(self) -> None:
"""Disable particle system rendering."""ShowBase integrates with Panda3D's event system and provides convenience methods for input handling.
class ShowBase:
def accept(self, event: str, method: callable, extraArgs: List = []) -> None:
"""Accept an event and bind it to a method."""
def acceptOnce(self, event: str, method: callable, extraArgs: List = []) -> None:
"""Accept an event only once."""
def ignore(self, event: str) -> None:
"""Stop accepting a specific event."""
def ignoreAll(self) -> None:
"""Stop accepting all events."""
def getAllAccepting(self) -> List[str]:
"""Get list of all accepted events."""
def isAccepting(self, event: str) -> bool:
"""Check if currently accepting an event."""ShowBase provides direct access to the task management system for frame-based logic.
class ShowBase:
def taskMgr: TaskManager
"""Access to global task manager."""
# Common task management patterns
def addTask(self, task: callable, name: str, priority: int = 0) -> Task:
"""Add a task to the task manager."""
def removeTask(self, task: str | Task) -> bool:
"""Remove a task from the task manager."""
def doMethodLater(self, delay: float, task: callable, name: str) -> Task:
"""Schedule a task to run after a delay."""Access engine configuration, system information, and performance monitoring.
class ShowBase:
def getConfigShowbase(self) -> ConfigVariableBool:
"""Get ShowBase configuration variable."""
def getAspectRatio(self) -> float:
"""Get current window aspect ratio."""
def adjustWindowAspectRatio(self, aspectRatio: float) -> None:
"""Adjust 2D display region for aspect ratio."""
def getSize(self) -> Tuple[int, int]:
"""Get window size as (width, height)."""
def getFrameRateMeter(self) -> FrameRateMeter:
"""Get frame rate monitoring object."""
def setFrameRateMeter(self, flag: bool) -> None:
"""Enable or disable frame rate display."""ShowBase provides access to the audio system for music and sound effects.
class ShowBase:
def enableMusic(self, bEnableMusic: bool) -> None:
"""Enable or disable music system."""
def enableSoundEffects(self, bEnableSoundEffects: bool) -> None:
"""Enable or disable sound effects system."""
def enableAllAudio(self) -> None:
"""Enable all audio subsystems."""
def disableAllAudio(self) -> None:
"""Disable all audio subsystems."""from direct.showbase.ShowBase import ShowBase
from panda3d.core import Vec3
from direct.task import Task
class MyGame(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Basic setup
self.setBackgroundColor(0.1, 0.1, 0.8, 1)
self.camera.setPos(0, -10, 0)
# Load content
self.setupScene()
# Start game logic
self.setupTasks()
# Setup input handling
self.setupInput()
def setupScene(self):
"""Initialize 3D scene content."""
self.model = self.loader.loadModel("models/teapot")
self.model.reparentTo(self.render)
self.model.setScale(2)
def setupTasks(self):
"""Setup frame-based tasks."""
self.taskMgr.add(self.updateGame, "update-game")
def updateGame(self, task):
"""Main game update loop."""
dt = globalClock.getDt()
# Rotate the model
self.model.setH(self.model.getH() + 30 * dt)
return task.cont
def setupInput(self):
"""Setup input event handling."""
self.accept("escape", self.userExit)
self.accept("space", self.toggleAnimation)
def toggleAnimation(self):
"""Toggle model animation."""
# Custom input handling logic
pass
# Start the application
app = MyGame()
app.run()from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
class MultiWindowApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Create additional window
self.createSecondWindow()
def createSecondWindow(self):
"""Create a second graphics window."""
# Window properties
props = WindowProperties()
props.setTitle("Second Window")
props.setSize(400, 300)
props.setOrigin(100, 100)
# Create window
self.second_win = self.openWindow(props=props)
if self.second_win:
# Create camera for second window
self.second_cam = self.makeCamera(self.second_win)
self.second_cam.setPos(5, -10, 2)
self.second_cam.lookAt(0, 0, 0)
app = MultiWindowApp()
app.run()from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
class OffScreenApp(ShowBase):
def __init__(self):
# Initialize with offscreen rendering
ShowBase.__init__(self, windowType='offscreen')
# Setup scene for rendering
self.setupOffscreenScene()
# Render frame and save
self.renderAndSave()
# Exit after rendering
self.userExit()
def setupOffscreenScene(self):
"""Setup scene for offscreen rendering."""
self.model = self.loader.loadModel("models/teapot")
self.model.reparentTo(self.render)
self.camera.setPos(0, -5, 2)
self.camera.lookAt(0, 0, 0)
def renderAndSave(self):
"""Render frame and save to file."""
# Force a frame render
self.graphicsEngine.renderFrame()
# Save screenshot
self.screenshot("output.png")
app = OffScreenApp()
app.run()class GraphicsWindow:
"""Represents a graphics window."""
def getXSize(self) -> int: ...
def getYSize(self) -> int: ...
def isClosed(self) -> bool: ...
class GraphicsPipe:
"""Graphics rendering pipeline."""
def makeOutput(self, **props) -> GraphicsWindow: ...
class Config:
"""Configuration system access."""
def GetBool(self, var: str, default: bool = False) -> bool: ...
def GetString(self, var: str, default: str = "") -> str: ...
class Task:
"""Task object for task management."""
cont: int # Continue task constant
done: int # Complete task constant
again: int # Restart task constantInstall with Tessl CLI
npx tessl i tessl/pypi-panda3d