CollisionTraverser
from panda3d.core import CollisionTraverser
- class CollisionTraverser
Bases:
Bases:
Namable
This class manages the traversal through the scene graph to detect collisions. It holds ownership of a number of collider objects, each of which is a
CollisionNode
and an associatedCollisionHandler
.When
traverse()
is called, it begins at the indicated root and detects all collisions with any of its collider objects against nodes at or below the indicated root, calling the appropriateCollisionHandler
for each detected collision.Inheritance diagram
- __init__(param0: CollisionTraverser)
- __init__(name: str)
- addCollider(collider: NodePath, handler: CollisionHandler)
Adds a new
CollisionNode
, representing an object that will be tested for collisions into other objects, along with the handler that will serve each detected collision. EachCollisionNode
may be served by only one handler at a time, but a given handler may serve manyCollisionNodes
.The handler that serves a particular node may be changed from time to time by calling
addCollider()
again on the same node.
- clearColliders()
Completely empties the set of collision nodes and their associated handlers.
- clearRecorder()
Removes the
CollisionRecorder
from the traverser and restores normal low- overhead operation.
- property colliders Sequence[NodePath]
Returns the nth
CollisionNode
that has been added to the traverser viaaddCollider()
.
- static getClassType() TypeHandle
- getCollider(n: int) NodePath
Returns the nth
CollisionNode
that has been added to the traverser viaaddCollider()
.
- getHandler(collider: NodePath) CollisionHandler
Returns the handler that is currently assigned to serve the indicated collision node, or NULL if the node is not on the traverser’s set of active nodes.
- getNumColliders() int
Returns the number of
CollisionNodes
that have been added to the traverser viaaddCollider()
.
- getRecorder() CollisionRecorder
Returns the
CollisionRecorder
currently assigned, or NULL if no recorder is assigned.
- getRespectPrevTransform() bool
Returns the flag that indicates whether the prev_transform stored on a node is respected to calculate collisions. See
setRespectPrevTransform()
.
- hasCollider(collider: NodePath) bool
Returns true if the indicated node is current in the set of nodes that will be tested each frame for collisions into other objects.
- hasRecorder() bool
Returns true if the
CollisionTraverser
has aCollisionRecorder
object currently assigned, false otherwise.
- hideCollisions()
Undoes the effect of a previous call to
showCollisions()
.
- property recorder CollisionRecorder
- Getter
Returns the
CollisionRecorder
currently assigned, or NULL if no recorder is assigned.- Setter
Uses the indicated
CollisionRecorder
object to start recording the intersection tests made by each subsequent call totraverse()
on this object. A particularCollisionRecorder
object can only record one traverser at a time; if this object has already been assigned to another traverser, that assignment is broken.This is intended to be used in a debugging mode to try to determine what work is being performed by the collision traversal. Usually, attaching a recorder will impose significant runtime overhead.
This does not transfer ownership of the
CollisionRecorder
pointer; maintenance of that remains the caller’s responsibility. If theCollisionRecorder
is destructed, it will cleanly remove itself from the traverser.
- removeCollider(collider: NodePath) bool
Removes the collider (and its associated handler) from the set of
CollisionNodes
that will be tested each frame for collisions into other objects. Returns true if the definition was found and removed, false if it wasn’t present to begin with.
- property respect_preV_transform bool
- Getter
Returns the flag that indicates whether the prev_transform stored on a node is respected to calculate collisions. See
setRespectPrevTransform()
.- Setter
Sets the flag that indicates whether the prev_transform stored on a node (as updated via set_fluid_pos(), etc.) is respected to calculate collisions. If this is true, certain types of collision tests will be enhanced by the information about objects in motion. If this is false, objects are always considered to be static. The default is false.
- property respect_prev_transform bool
- Getter
Returns the flag that indicates whether the prev_transform stored on a node is respected to calculate collisions. See
setRespectPrevTransform()
.- Setter
Sets the flag that indicates whether the prev_transform stored on a node (as updated via set_fluid_pos(), etc.) is respected to calculate collisions. If this is true, certain types of collision tests will be enhanced by the information about objects in motion. If this is false, objects are always considered to be static. The default is false.
- setRecorder(recorder: CollisionRecorder)
Uses the indicated
CollisionRecorder
object to start recording the intersection tests made by each subsequent call totraverse()
on this object. A particularCollisionRecorder
object can only record one traverser at a time; if this object has already been assigned to another traverser, that assignment is broken.This is intended to be used in a debugging mode to try to determine what work is being performed by the collision traversal. Usually, attaching a recorder will impose significant runtime overhead.
This does not transfer ownership of the
CollisionRecorder
pointer; maintenance of that remains the caller’s responsibility. If theCollisionRecorder
is destructed, it will cleanly remove itself from the traverser.
- setRespectPrevTransform(flag: bool)
Sets the flag that indicates whether the prev_transform stored on a node (as updated via set_fluid_pos(), etc.) is respected to calculate collisions. If this is true, certain types of collision tests will be enhanced by the information about objects in motion. If this is false, objects are always considered to be static. The default is false.
- showCollisions(root: NodePath) CollisionVisualizer
This is a high-level function to create a
CollisionVisualizer
object to render the collision tests performed by this traverser. The supplied root should be any node in the scene graph; typically, the top node (e.g. render). TheCollisionVisualizer
will be attached to this node.
- traverse(root: NodePath)
Perform the traversal. Begins at the indicated root and detects all collisions with any of its collider objects against nodes at or below the indicated root, calling the appropriate
CollisionHandler
for each detected collision.