CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-panda3d

Panda3D is a framework for 3D rendering and game development for Python and C++ programs.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

scene-graph.mddocs/

Scene Graph and 3D Objects

The scene graph is Panda3D's hierarchical organization system for 3D content. All objects in the 3D world are represented as nodes in a tree structure, with the NodePath class providing the primary interface for manipulation.

Capabilities

NodePath - Core 3D Object Interface

The NodePath class is the fundamental interface for all 3D objects in Panda3D. It provides methods for positioning, orienting, scaling, and managing hierarchical relationships between objects.

class NodePath:
    def set_pos(self, x: float, y: float, z: float) -> None:
        """Set absolute position in 3D space."""
    
    def set_pos(self, pos: Vec3) -> None:
        """Set absolute position using Vec3."""
    
    def set_x(self, x: float) -> None:
        """Set X coordinate only."""
    
    def set_y(self, y: float) -> None:
        """Set Y coordinate only."""
    
    def set_z(self, z: float) -> None:
        """Set Z coordinate only."""
    
    def get_pos(self) -> Vec3:
        """Get current absolute position."""
    
    def get_x(self) -> float:
        """Get X coordinate."""
    
    def get_y(self) -> float:
        """Get Y coordinate."""
    
    def get_z(self) -> float:
        """Get Z coordinate."""

Rotation and Orientation

Panda3D supports multiple rotation representations including Euler angles (Heading-Pitch-Roll) and quaternions for smooth rotations.

class NodePath:
    def setHpr(self, h: float, p: float, r: float) -> None:
        """Set heading, pitch, roll rotation in degrees."""
    
    def setHpr(self, hpr: Vec3) -> None:
        """Set HPR rotation using Vec3."""
    
    def setH(self, h: float) -> None:
        """Set heading (Y-axis rotation) only."""
    
    def setP(self, p: float) -> None:
        """Set pitch (X-axis rotation) only."""
    
    def setR(self, r: float) -> None:
        """Set roll (Z-axis rotation) only."""
    
    def getHpr(self) -> Vec3:
        """Get current HPR rotation."""
    
    def setQuat(self, quat: Quat) -> None:
        """Set rotation using quaternion."""
    
    def getQuat(self) -> Quat:
        """Get current rotation as quaternion."""
    
    def lookAt(self, target: Vec3) -> None:
        """Orient to look at target position."""
    
    def lookAt(self, target: NodePath) -> None:
        """Orient to look at target object."""

Scale and Size

Control object scaling along individual axes or uniformly.

class NodePath:
    def setScale(self, scale: float) -> None:
        """Set uniform scale factor."""
    
    def setScale(self, sx: float, sy: float, sz: float) -> None:
        """Set scale along each axis."""
    
    def setScale(self, scale: Vec3) -> None:
        """Set scale using Vec3."""
    
    def setSx(self, sx: float) -> None:
        """Set X-axis scale only."""
    
    def setSy(self, sy: float) -> None:
        """Set Y-axis scale only."""
    
    def setSz(self, sz: float) -> None:
        """Set Z-axis scale only."""
    
    def getScale(self) -> Vec3:
        """Get current scale factors."""

Hierarchy Management

Manage parent-child relationships between objects in the scene graph.

class NodePath:
    def reparentTo(self, newParent: NodePath) -> None:
        """Move this object to be child of newParent."""
    
    def wrtReparentTo(self, newParent: NodePath) -> None:
        """Reparent while maintaining world coordinates."""
    
    def detachNode(self) -> None:
        """Remove from scene graph but keep object."""
    
    def removeNode(self) -> None:
        """Remove and destroy this object."""
    
    def getParent(self) -> NodePath:
        """Get parent node."""
    
    def getChildren(self) -> List[NodePath]:
        """Get all child nodes."""
    
    def getNumChildren(self) -> int:
        """Get number of child nodes."""
    
    def getChild(self, index: int) -> NodePath:
        """Get child node by index."""
    
    def find(self, path: str) -> NodePath:
        """Find descendant node by name or path."""
    
    def findAllMatches(self, path: str) -> List[NodePath]:
        """Find all descendant nodes matching path."""

Visibility and Rendering Control

Control object visibility and rendering properties.

class NodePath:
    def show(self) -> None:
        """Make object visible."""
    
    def hide(self) -> None:
        """Make object invisible."""
    
    def isHidden(self) -> bool:
        """Check if object is hidden."""
    
    def setTransparency(self, mode: int) -> None:
        """Enable transparency rendering."""
    
    def setAlphaScale(self, alpha: float) -> None:
        """Set overall transparency (0.0-1.0)."""
    
    def setColorScale(self, r: float, g: float, b: float, a: float = 1.0) -> None:
        """Multiply object colors by scale factors."""
    
    def setColor(self, r: float, g: float, b: float, a: float = 1.0) -> None:
        """Set object color."""
    
    def clearColor(self) -> None:
        """Remove color override."""

Coordinate System Utilities

Transform coordinates between different reference frames.

class NodePath:
    def getRelativePoint(self, other: NodePath, point: Vec3) -> Vec3:
        """Convert point from other's coordinate system to this one."""
    
    def getRelativeVector(self, other: NodePath, vector: Vec3) -> Vec3:
        """Convert vector from other's coordinate system to this one."""
    
    def getDistance(self, other: NodePath) -> float:
        """Get distance to another object."""
    
    def getTransform(self) -> TransformState:
        """Get complete transformation state."""
    
    def setTransform(self, transform: TransformState) -> None:
        """Set complete transformation state."""

Collision and Physics Integration

Enable collision detection and physics simulation for objects.

class NodePath:
    def setCollideMask(self, mask: BitMask32) -> None:
        """Set collision bitmask for this object."""
    
    def getCollideMask(self) -> BitMask32:
        """Get collision bitmask."""
    
    def node(self) -> PandaNode:
        """Get underlying PandaNode for advanced operations."""
    
    def isEmpty(self) -> bool:
        """Check if NodePath references a valid node."""
    
    def hasParent(self) -> bool:
        """Check if object has a parent."""

Usage Examples

Basic Object Manipulation

from direct.showbase.ShowBase import ShowBase
from panda3d.core import Vec3

class MyGame(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        
        # Load and position a model
        self.model = self.loader.loadModel("models/teapot")
        self.model.reparentTo(self.render)
        self.model.setScale(2.0)
        self.model.setPos(0, 10, 0)
        self.model.setHpr(45, 0, 0)
        
        # Create hierarchy
        self.parent_obj = self.render.attachNewNode("parent")
        self.child_obj = self.loader.loadModel("models/box")
        self.child_obj.reparentTo(self.parent_obj)
        self.child_obj.setPos(5, 0, 0)  # Relative to parent
        
        # Rotating parent affects child
        self.parent_obj.setH(90)  # Child rotates with parent

app = MyGame()
app.run()

Dynamic Object Management

def create_objects(self):
    """Create multiple objects dynamically."""
    self.objects = []
    
    for i in range(10):
        obj = self.loader.loadModel("models/cube")
        obj.reparentTo(self.render)
        obj.setPos(i * 2, 0, 0)
        obj.setScale(0.5)
        self.objects.append(obj)

def cleanup_objects(self):
    """Remove all created objects."""
    for obj in self.objects:
        obj.removeNode()
    self.objects.clear()

Types

class PandaNode:
    """Base class for all scene graph nodes."""
    def getName(self) -> str: ...
    def setName(self, name: str) -> None: ...

class TransformState:
    """Represents complete 3D transformation."""
    def getPos(self) -> Vec3: ...
    def getHpr(self) -> Vec3: ...
    def getScale(self) -> Vec3: ...

BitMask32: int  # 32-bit collision mask type

Install with Tessl CLI

npx tessl i tessl/pypi-panda3d

docs

animation.md

application-framework.md

asset-loading.md

audio.md

index.md

input.md

mathematics.md

scene-graph.md

task-event.md

user-interface.md

tile.json