SuperDex Physics C++ API
Loading...
Searching...
No Matches
superdex::Scene Class Referenceabstract

Represents a simulation scene. More...

#include <mochi_scene.h>

Public Member Functions

virtual void CancelCallback (CallbackHandle handle)=0
 Cancel a previously registered callback.
virtual StateHandle CaptureState (Error &error)=0
 Capture the simulation state that changes from step to step for later restoration.
virtual void CaptureStateToBytes (DynamicArray< uint8_t > &outData, Error &error)=0
 Capture simulation state to a binary byte buffer.
virtual void CaptureStateToFile (std::string_view filePath, Error &error)=0
 Captures a snapshot of the state of a Scene, similar to Scene::CaptureState, then writes the data to a JSON file for manual inspection.
virtual ConstraintCreateArticulated3dRotationRangeConstraint (Articulated3dRotationRangeConstraintParams const &params, Error &error)=0
 Create a range constraint on the DoFs of a 3D rotation joint of an articulated actor.
virtual ConstraintCreateArticulated3dRotationTargetConstraint (Articulated3dRotationTargetConstraintParams const &params, Error &error)=0
 Create a target constraint on an articulated 3D rotation.
virtual ActorCreateArticulatedActor (ArticulatedActorParams const &params, Error &error)=0
 Create an articulated actor.
virtual ConstraintCreateArticulatedSingleDofRangeConstraint (ArticulatedSingleDofRangeConstraintParams const &params, Error &error)=0
 Create a range constraint on a single articulated DoF.
virtual ConstraintCreateArticulatedSingleDofTargetConstraint (ArticulatedSingleDofTargetConstraintParams const &params, Error &error)=0
 Create a target constraint on a single articulated DoF.
virtual ConstraintCreateDeformableNodePositionConstraint (DeformableNodePositionConstraintParams const &params, Error &error)=0
 Create a position constraint on a deformable actor node.
virtual ConstraintCreateDeformableNodeToDeformableNodeConstraint (DeformableNodeToDeformableNodeConstraintParams const &params, Error &error)=0
 Create a constraint connecting two deformable actor nodes.
virtual ConstraintCreateDeformableNodeToRigidConstraint (DeformableNodeToRigidConstraintParams const &params, Error &error)=0
 Create a constraint connecting a deformable node to a rigid actor.
virtual ConstraintCreateJointRotationRangeConstraint (JointRotationRangeConstraintParams const &params, Error &error)=0
 Create a range constraint on joint rotation.
virtual ConstraintCreateJointRotationTrackingConstraint (JointRotationTrackingConstraintParams const &params, Error &error)=0
 Create a tracking constraint on joint rotation.
virtual ActorCreateRigidActor (RigidActorParams const &params, Error &error)=0
 Create a rigid body actor.
virtual ConstraintCreateRigidPivotPositionConstraint (RigidPivotPositionConstraintParams const &params, Error &error)=0
 Create a position constraint on a rigid actor's pivot point.
virtual ConstraintCreateRigidPivotRotationConstraint (RigidPivotRotationConstraintParams const &params, Error &error)=0
 Create a rotation constraint on a rigid actor's pivot frame.
virtual ConstraintCreateRigidPivotToRigidTargetConstraint (RigidPivotToRigidTargetConstraintParams const &params, Error &error)=0
 Create a position constraint between a rigid actor's pivot point and the world position of that pivot under a target center-of-mass transform.
virtual ConstraintCreateRigidPrismaticJointConstraint (RigidPrismaticJointConstraintParams const &params, Error &error)=0
 Create a prismatic joint constraint between two rigid actors.
virtual ConstraintCreateRigidSphericalJointConstraint (RigidSphericalJointConstraintParams const &params, Error &error)=0
 Create a spherical joint constraint between two rigid actors.
virtual ConstraintCreateRodElementRotationToRigidConstraint (RodElementRotationToRigidConstraintParams const &params, Error &error)=0
 Create a rotation constraint between a rigid actor and a rod element.
virtual ActorCreateSoftActor (SoftActorParams const &params, Error &error)=0
 Create a soft deformable actor.
virtual ActorCreateSoftSkinnedActor (SoftSkinnedActorParams const &params, Error &error)=0
 Create a soft-skinned actor with an articulated skeleton.
void DestroyActor (Actor *actor)
 Destroy an actor and remove it from the scene.
virtual void DestroyActor (ActorHandle actor)=0
 Destroy an actor and remove it from the scene.
virtual void DestroyConstraint (Constraint *constraint)=0
 Destroy a constraint and remove it from the scene.
virtual void DestroyConstraint (ConstraintHandle constraint)=0
 Destroy a constraint and remove it from the scene.
virtual void EnableActorContactAsymmetric (ActorHandle colliding, ActorHandle collider, bool enable, IncludeNestedActors includeNestedActors, Error &error)=0
 Enable or disable collision detection between two actors.
virtual void EnableActorContactSymmetric (ActorHandle actorA, ActorHandle actorB, bool enable, IncludeNestedActors includeNestedActors, Error &error)=0
 Equivalent to calling EnableActorContactAsymmetric with actorA and actorB in both orders using the same includeNestedActors.
virtual void EnableLayerContactAsymmetric (std::string_view layerA, std::string_view layerB, bool enable, Error &error)=0
 Enable or disable collision detection for an ordered pair of contact layer names.
virtual void EnableLayerContactSymmetric (std::string_view layerA, std::string_view layerB, bool enable, Error &error)=0
 Equivalent to calling EnableLayerContactAsymmetric with layerA and layerB in both orders.
virtual void EnumerateContactLayerNames (std::function< void(std::string_view name)> const &callback) const =0
 Enumerate all unique contact layer names in the scene.
virtual void ForEachActor (std::function< void(Actor *)> const &callback)=0
 Iterate over all the actors in the scene using a callback.
virtual void ForEachActor (std::function< void(Actor const *)> const &callback) const =0
 Iterate over all the actors in the scene using a callback (const version).
virtual void ForEachConstraint (std::function< void(Constraint *)> const &callback)=0
 Iterate over all the constraints in the scene using a callback.
virtual void ForEachConstraint (std::function< void(Constraint const *)> const &callback) const =0
 Iterate over all the constraints in the scene using a callback (const version).
virtual Actor const * GetActor (ActorHandle actor) const =0
 Get a const pointer to the Actor associated with an ActorHandle.
virtual ActorGetActor (ActorHandle actor)=0
 Get the Actor pointer associated with an ActorHandle.
virtual void GetActors (Span< Actor * > outActors, Error &error)=0
 Get Actor pointers for all the actors in the scene.
virtual void GetActors (Span< Actor const * > outActors, Error &error) const =0
 Get const Actor pointers for all the actors in the scene.
virtual Constraint const * GetConstraint (ConstraintHandle constraint) const =0
 Get the const Constraint pointer associated with a ConstraintHandle.
virtual ConstraintGetConstraint (ConstraintHandle constraint)=0
 Get the Constraint pointer associated with a ConstraintHandle.
virtual Context const * GetContext () const =0
 Get read-only access to the Context that owns this scene.
virtual ContextGetContext ()=0
 Get the Context that owns this scene.
virtual DebugDraw const & GetDebugDraw () const =0
 Get a const reference to the debug draw interface for this scene.
virtual DebugDrawGetDebugDraw ()=0
 Get the debug draw interface for this scene.
virtual bool GetForceSingleIsland () const =0
 Get whether all actors are forced to be in a single simulation island.
virtual Real3 GetGravity () const =0
 Get the gravity vector in world frame.
virtual SceneHandle GetHandle () const =0
 Get the scene handle.
virtual double GetLastTimeStep () const =0
 Returns the time step size [s] from the most recent positive call to Step.
virtual char const * GetName () const =0
 Get the name of the scene.
virtual int GetNumActors () const =0
 Get the number of actors in the scene, including nested link actors and nested soft actors.
virtual int GetNumConstraints () const =0
 Get the number of constraints in the scene.
virtual int GetNumContactLayers () const =0
 Get the number of unique contact layer names in the scene.
virtual PerformanceStats GetPerformanceStats () const =0
 Get timing and profiling metrics from the last simulation step.
virtual SolverParams GetSolverParams () const =0
 Get the solver parameters.
virtual SolverStats GetSolverStats () const =0
 Get solver convergence metrics from the last simulation step.
virtual double GetTotalSimulationTime () const =0
 Returns the total simulation time [s] in the scene.
virtual bool IsEqualState (StateHandle stateA, StateHandle stateB) const =0
 Return true if both StateHandles are valid and refer to identical state information (full precision).
virtual bool IsLayerContactEnabled (std::string_view layerA, std::string_view layerB) const =0
 Check if collision detection is enabled for an ordered pair of contact layer names.
virtual bool IsRecording () const =0
 Check if the scene is currently recording.
virtual CallbackHandle RegisterPostStepCallback (std::string_view debugName, std::function< void(StepInfo const &)> callback, int priority=kDefaultCallbackPriority)=0
 Register a callback to execute after each simulation step.
virtual CallbackHandle RegisterPreStepCallback (std::string_view debugName, std::function< void(StepInfo const &)> callback, int priority=kDefaultCallbackPriority)=0
 Register a callback to execute before each simulation step.
virtual void ReleaseAllStates ()=0
 Release memory for all captured state and invalidate all prior StateHandle objects.
virtual void ReleaseState (StateHandle handle)=0
 Release a StateHandle when you are done with it.
virtual void RestoreState (StateHandle handle, bool releaseImmediately, Error &error)=0
 Restore captured simulation state.
virtual void RestoreStateFromBytes (Span< uint8_t const > data, Error &error)=0
 Restore simulation state from a binary byte buffer produced by CaptureStateToBytes.
virtual void SetForceSingleIsland (bool forceSingleIsland)=0
 Enables/disables forcing all actors in the scene to be in a single simulation island.
virtual void SetGravity (Real3 const &gravity)=0
 Set the gravity vector in world frame.
virtual void SetSolverParams (SolverParams const &params, Error &error)=0
 Set the solver parameters.
virtual void StartRecording (std::string_view filePath, RecordingParams const &params, Error &error)=0
 Create or replace the specified file and start recording the scene to an HDF5 file.
virtual void Step (double timeStepSec)=0
 Advance the simulation of the Scene one step.
virtual void StopRecording ()=0
 Stop recording the scene and close the recording file.
virtual void UpdateDebugger ()=0
 This gives the debugger a chance to process messages that require reading or writing scene state.

Static Public Attributes

static constexpr int kDefaultCallbackPriority = 100
 Default priority for callback ordering.

Protected Member Functions

virtual ~Scene ()=default
 Don't delete the Scene pointer. Call Context::DestroyScene.

Detailed Description

Represents a simulation scene.

Note
Each scene manages the simulation of a series of actors.
Actors from different scenes do not interact with each other.
Warning
Concurrent access to the scene and its actors and constraints is illegal.

Definition at line 45 of file mochi_scene.h.

Constructor & Destructor Documentation

◆ ~Scene()

virtual superdex::Scene::~Scene ( )
protectedvirtualdefault

Don't delete the Scene pointer. Call Context::DestroyScene.

Member Function Documentation

◆ CancelCallback()

virtual void superdex::Scene::CancelCallback ( CallbackHandle handle)
pure virtual

Cancel a previously registered callback.

Parameters
[in]handleCallbackHandle from RegisterPreStepCallback or RegisterPostStepCallback. Must be owned by this scene.
Note
Invalid and already-cancelled handles are ignored.
See also
RegisterPreStepCallback, RegisterPostStepCallback

◆ CaptureState()

virtual StateHandle superdex::Scene::CaptureState ( Error & error)
nodiscardpure virtual

Capture the simulation state that changes from step to step for later restoration.

Captured state includes actor solution, transforms, and velocities; current and previous constraint/controller targets; and external forces.

Parameters
[in,out]errorError status. Check Error::IsOK for success.
Returns
StateHandle to be used with RestoreState. Call ReleaseState or ReleaseAllStates when you're done with it.
Warning
Not supported for scenes with ROM actors.
See also
RestoreState, ReleaseState, ReleaseAllStates, CaptureStateToFile, CaptureStateToBytes

◆ CaptureStateToBytes()

virtual void superdex::Scene::CaptureStateToBytes ( DynamicArray< uint8_t > & outData,
Error & error )
pure virtual

Capture simulation state to a binary byte buffer.

Captures the same simulation state as CaptureState, but writes the binary representation to caller-owned memory instead of storing it internally. This is useful for transferring state between processes or caching state outside the scene.

Parameters
[in,out]outDataOutput byte buffer. Capture data is appended to the buffer.
[in,out]errorError status. Check Error::IsOK for success.
Note
On failure, the output buffer may contain a partial capture. Discard the buffer or truncate it to its original size before reuse.
Warning
Has the same capture restrictions as CaptureState, including no support for scenes with ROM actors.
The binary representation uses an internal capture format. It is intended only for compatible scenes with the same actors and constraints created in the same order and the same component layouts, using the same SuperDex Physics build. It is not a stable long-term serialization or asset interchange format.
See also
RestoreStateFromBytes, CaptureState, CaptureStateToFile

◆ CaptureStateToFile()

virtual void superdex::Scene::CaptureStateToFile ( std::string_view filePath,
Error & error )
pure virtual

Captures a snapshot of the state of a Scene, similar to Scene::CaptureState, then writes the data to a JSON file for manual inspection.

Parameters
[in]filePathPath of the output file to write/overwrite (case sensitive on some filesystems).
[in,out]errorError status. Check Error::IsOK for success.
Warning
Not supported for scenes with ROM actors.
See also
Scene::CaptureState

◆ CreateArticulated3dRotationRangeConstraint()

virtual Constraint * superdex::Scene::CreateArticulated3dRotationRangeConstraint ( Articulated3dRotationRangeConstraintParams const & params,
Error & error )
pure virtual

Create a range constraint on the DoFs of a 3D rotation joint of an articulated actor.

Parameters
[in]paramsParameters defining the DoF range constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
Note
Use this API for runtime creation/deletion of joint limits. For static joint limits, use the Scene::CreateArticulatedActor API instead.
See also
ConstraintType::Articulated3dRotationRange, Articulated3dRotationRangeConstraintParams, DestroyConstraint

◆ CreateArticulated3dRotationTargetConstraint()

virtual Constraint * superdex::Scene::CreateArticulated3dRotationTargetConstraint ( Articulated3dRotationTargetConstraintParams const & params,
Error & error )
pure virtual

Create a target constraint on an articulated 3D rotation.

Parameters
[in]paramsParameters defining the 3D rotation target constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::Articulated3dRotationTarget, Articulated3dRotationTargetConstraintParams, DestroyConstraint

◆ CreateArticulatedActor()

virtual Actor * superdex::Scene::CreateArticulatedActor ( ArticulatedActorParams const & params,
Error & error )
pure virtual

Create an articulated actor.

Parameters
[in]paramsParameters defining the articulated actor.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Actor, or nullptr on error.
Note
To access nested link actors, use Actor::GetNestedLinkActors.
Warning
A zero-DOF skeleton (every joint is ArticulatedJointType::Hard) is a static welded structure and cannot carry a skin (ArticulatedActorParams::skin).
See also
ArticulatedActorParams, DestroyActor

◆ CreateArticulatedSingleDofRangeConstraint()

virtual Constraint * superdex::Scene::CreateArticulatedSingleDofRangeConstraint ( ArticulatedSingleDofRangeConstraintParams const & params,
Error & error )
pure virtual

Create a range constraint on a single articulated DoF.

Parameters
[in]paramsParameters defining the DoF range constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
Note
Use this API for runtime creation/deletion of joint limits. For static joint limits, use the Scene::CreateArticulatedActor API instead.
See also
ConstraintType::ArticulatedSingleDofRange, ArticulatedSingleDofRangeConstraintParams, DestroyConstraint

◆ CreateArticulatedSingleDofTargetConstraint()

virtual Constraint * superdex::Scene::CreateArticulatedSingleDofTargetConstraint ( ArticulatedSingleDofTargetConstraintParams const & params,
Error & error )
pure virtual

Create a target constraint on a single articulated DoF.

Parameters
[in]paramsParameters defining the single DoF target constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::ArticulatedSingleDofTarget, ArticulatedSingleDofTargetConstraintParams, DestroyConstraint

◆ CreateDeformableNodePositionConstraint()

virtual Constraint * superdex::Scene::CreateDeformableNodePositionConstraint ( DeformableNodePositionConstraintParams const & params,
Error & error )
pure virtual

Create a position constraint on a deformable actor node.

Parameters
[in]paramsParameters defining the deformable node position constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::DeformableNodePosition, DeformableNodePositionConstraintParams, DestroyConstraint

◆ CreateDeformableNodeToDeformableNodeConstraint()

virtual Constraint * superdex::Scene::CreateDeformableNodeToDeformableNodeConstraint ( DeformableNodeToDeformableNodeConstraintParams const & params,
Error & error )
pure virtual

Create a constraint connecting two deformable actor nodes.

Parameters
[in]paramsParameters defining the deformable-node-to-deformable-node constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::DeformableNodeToDeformableNode, DeformableNodeToDeformableNodeConstraintParams, DestroyConstraint

◆ CreateDeformableNodeToRigidConstraint()

virtual Constraint * superdex::Scene::CreateDeformableNodeToRigidConstraint ( DeformableNodeToRigidConstraintParams const & params,
Error & error )
pure virtual

Create a constraint connecting a deformable node to a rigid actor.

Parameters
[in]paramsParameters defining the deformable-node-to-rigid constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::DeformableNodeToRigid, DeformableNodeToRigidConstraintParams, DestroyConstraint

◆ CreateJointRotationRangeConstraint()

virtual Constraint * superdex::Scene::CreateJointRotationRangeConstraint ( JointRotationRangeConstraintParams const & params,
Error & error )
pure virtual

Create a range constraint on joint rotation.

Parameters
[in]paramsParameters defining the joint rotation range constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::JointRotationRange, JointRotationRangeConstraintParams, DestroyConstraint

◆ CreateJointRotationTrackingConstraint()

virtual Constraint * superdex::Scene::CreateJointRotationTrackingConstraint ( JointRotationTrackingConstraintParams const & params,
Error & error )
pure virtual

Create a tracking constraint on joint rotation.

Parameters
[in]paramsParameters defining the joint rotation tracking constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::JointRotationTracking, JointRotationTrackingConstraintParams, DestroyConstraint

◆ CreateRigidActor()

virtual Actor * superdex::Scene::CreateRigidActor ( RigidActorParams const & params,
Error & error )
pure virtual

Create a rigid body actor.

Parameters
[in]paramsParameters defining the rigid actor.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Actor, or nullptr on error.
See also
RigidActorParams, DestroyActor

◆ CreateRigidPivotPositionConstraint()

virtual Constraint * superdex::Scene::CreateRigidPivotPositionConstraint ( RigidPivotPositionConstraintParams const & params,
Error & error )
pure virtual

Create a position constraint on a rigid actor's pivot point.

Parameters
[in]paramsParameters defining the rigid pivot position constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::RigidPivotPosition, RigidPivotPositionConstraintParams, DestroyConstraint

◆ CreateRigidPivotRotationConstraint()

virtual Constraint * superdex::Scene::CreateRigidPivotRotationConstraint ( RigidPivotRotationConstraintParams const & params,
Error & error )
pure virtual

Create a rotation constraint on a rigid actor's pivot frame.

Parameters
[in]paramsParameters defining the rigid pivot rotation constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::RigidPivotRotation, RigidPivotRotationConstraintParams, DestroyConstraint

◆ CreateRigidPivotToRigidTargetConstraint()

virtual Constraint * superdex::Scene::CreateRigidPivotToRigidTargetConstraint ( RigidPivotToRigidTargetConstraintParams const & params,
Error & error )
pure virtual

Create a position constraint between a rigid actor's pivot point and the world position of that pivot under a target center-of-mass transform.

Parameters
[in]paramsParameters defining the rigid pivot to rigid target constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::RigidPivotToRigidTarget, RigidPivotToRigidTargetConstraintParams, DestroyConstraint

◆ CreateRigidPrismaticJointConstraint()

virtual Constraint * superdex::Scene::CreateRigidPrismaticJointConstraint ( RigidPrismaticJointConstraintParams const & params,
Error & error )
pure virtual

Create a prismatic joint constraint between two rigid actors.

Parameters
[in]paramsParameters defining the prismatic joint constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::RigidPrismaticJoint, RigidPrismaticJointConstraintParams, DestroyConstraint

◆ CreateRigidSphericalJointConstraint()

virtual Constraint * superdex::Scene::CreateRigidSphericalJointConstraint ( RigidSphericalJointConstraintParams const & params,
Error & error )
pure virtual

Create a spherical joint constraint between two rigid actors.

Parameters
[in]paramsParameters defining the spherical joint constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::RigidSphericalJoint, RigidSphericalJointConstraintParams, DestroyConstraint

◆ CreateRodElementRotationToRigidConstraint()

virtual Constraint * superdex::Scene::CreateRodElementRotationToRigidConstraint ( RodElementRotationToRigidConstraintParams const & params,
Error & error )
pure virtual

Create a rotation constraint between a rigid actor and a rod element.

Parameters
[in]paramsParameters defining the rod element rotation constraint.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Constraint, or nullptr on error.
See also
ConstraintType::RodElementRotationToRigid, RodElementRotationToRigidConstraintParams, DestroyConstraint

◆ CreateSoftActor()

virtual Actor * superdex::Scene::CreateSoftActor ( SoftActorParams const & params,
Error & error )
pure virtual

Create a soft deformable actor.

Parameters
[in]paramsParameters defining the soft actor.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Actor, or nullptr on error.
See also
SoftActorParams, DestroyActor

◆ CreateSoftSkinnedActor()

virtual Actor * superdex::Scene::CreateSoftSkinnedActor ( SoftSkinnedActorParams const & params,
Error & error )
pure virtual

Create a soft-skinned actor with an articulated skeleton.

Parameters
[in]paramsParameters defining the soft-skinned actor.
[in,out]errorError status. Check Error::IsOK for success.
Returns
Pointer to the created Actor, or nullptr on error.
Note
To access underlying soft actors, use Actor::GetNestedSoftActors.
To access underlying rigid link actors, use Actor::GetNestedLinkActors.
Warning
The skeleton must have at least one non-Hard joint.
See also
SoftSkinnedActorParams, DestroyActor

◆ DestroyActor() [1/2]

void superdex::Scene::DestroyActor ( Actor * actor)
inline

Destroy an actor and remove it from the scene.

Parameters
[in]actorPointer to the actor to destroy.
Note
Nested actors cannot be destroyed individually. When you destroy the parent actor (e.g. an articulation), all the nested actors will be destroyed automatically.
Constraints attached to the actor are automatically destroyed.
If actor is null, this function has no effect.
After the actor is destroyed, do not use the pointer or its handle.
Warning
The pointer must be null or point to a live actor owned by this scene. Passing a pointer to an actor that has been destroyed is undefined behavior.
See also
GetActor, Actor::GetHandle

Definition at line 23 of file mochi_scene_inl.h.

◆ DestroyActor() [2/2]

virtual void superdex::Scene::DestroyActor ( ActorHandle actor)
pure virtual

Destroy an actor and remove it from the scene.

Parameters
[in]actorHandle of the actor to destroy. If valid, it must be owned by this scene.
Note
Nested actors cannot be destroyed individually. When you destroy the parent actor (e.g. an articulation), all the nested actors will be destroyed automatically.
Constraints attached to the actor are automatically destroyed.
An invalid handle or one that does not currently identify an actor in the scene has no effect.
After the actor is destroyed, do not use its handle.
See also
GetActor, Actor::GetHandle

◆ DestroyConstraint() [1/2]

virtual void superdex::Scene::DestroyConstraint ( Constraint * constraint)
pure virtual

Destroy a constraint and remove it from the scene.

Parameters
[in]constraintPointer to the constraint to destroy.
Note
If constraint is null, this function has no effect.
After the constraint is destroyed, do not use the pointer or its handle.
Warning
The pointer must be null or point to a live constraint owned by this scene. Passing a pointer to a constraint that has been destroyed is undefined behavior.
See also
GetConstraint, Constraint::GetHandle

◆ DestroyConstraint() [2/2]

virtual void superdex::Scene::DestroyConstraint ( ConstraintHandle constraint)
pure virtual

Destroy a constraint and remove it from the scene.

Parameters
[in]constraintHandle of the constraint to destroy. If valid, it must be owned by this scene.
Note
An invalid handle or one that does not currently identify a constraint in the scene has no effect.
After the constraint is destroyed, do not use its handle.
See also
GetConstraint, Constraint::GetHandle

◆ EnableActorContactAsymmetric()

virtual void superdex::Scene::EnableActorContactAsymmetric ( ActorHandle colliding,
ActorHandle collider,
bool enable,
IncludeNestedActors includeNestedActors,
Error & error )
pure virtual

Enable or disable collision detection between two actors.

Order matters: controls only the specified direction (colliding actor checking against collider actor).

Parameters
[in]collidingHandle of the colliding actor.
[in]colliderHandle of the collider actor.
[in]enableTrue to enable contact, false to disable it.
[in]includeNestedActorsWhether nested actors should be affected by this contact setting. With IncludeNestedActors::No, only the exact handles are affected. With IncludeNestedActors::Yes, parent actors with nested actors resolve to the parent plus nested actors. The setting is applied to every ordered pair in the cross-product of the two resolved handle sets; no pairs outside that cross-product are affected. If the resolved sets overlap, pairs in the overlap, including self-pairs, are affected.
[in,out]errorError status. Check Error::IsOK for success.
Note
Contact is enabled by default. You only need to call this method if you wish to disable (or re-enable) contact for a specific actor pair.
Both layer-to-layer and actor-to-actor contact must be enabled for contact to occur.
Contact between adjacent links is automatically disabled when an articulated or soft-skinned actor is created. A later actor-contact setting can override that automatic disable for any pair included in the resolved actor sets. In particular, enabling contact between a parent actor and itself with IncludeNestedActors::Yes enables contact between that parent's nested actors, including adjacent links, unless a later actor-contact setting disables those pairs again.
Call twice with swapped arguments or use EnableActorContactSymmetric to affect collision checks in both directions.
See also
EnableActorContactSymmetric, EnableLayerContactAsymmetric

◆ EnableActorContactSymmetric()

virtual void superdex::Scene::EnableActorContactSymmetric ( ActorHandle actorA,
ActorHandle actorB,
bool enable,
IncludeNestedActors includeNestedActors,
Error & error )
pure virtual

Equivalent to calling EnableActorContactAsymmetric with actorA and actorB in both orders using the same includeNestedActors.

Parameters
[in]actorAHandle of the first actor.
[in]actorBHandle of the second actor.
[in]enableTrue to enable contact, false to disable it.
[in]includeNestedActorsWhether nested actors should be affected by this contact setting. See EnableActorContactAsymmetric for details.
[in,out]errorError status. Check Error::IsOK for success.
See also
EnableActorContactAsymmetric, EnableLayerContactSymmetric

◆ EnableLayerContactAsymmetric()

virtual void superdex::Scene::EnableLayerContactAsymmetric ( std::string_view layerA,
std::string_view layerB,
bool enable,
Error & error )
pure virtual

Enable or disable collision detection for an ordered pair of contact layer names.

Order matters: controls only the specified direction (actors in layerA checking against actors in layerB).

Parameters
[in]layerAName of the layer of the "colliding" actor (the one checking for contact). Must be non-empty.
[in]layerBName of the layer of the "collider" actor (the one with a ColliderType being tested). Must be non-empty.
[in]enableTrue to enable contact, false to disable it.
[in,out]errorError status. Check Error::IsOK for success.
Note
Contact is enabled by default. You only need to call this method if you wish to disable (or re-enable) contact for a specific layer pair.
Both layer-to-layer and actor-to-actor contact must be enabled for contact to occur.
Call twice with swapped arguments or use EnableLayerContactSymmetric to affect collision checks in both directions.
Calling this method with a layer name not previously seen in the scene registers it as a new contact layer, increasing GetNumContactLayers and adding the name to EnumerateContactLayerNames.
See also
EnableLayerContactSymmetric, EnableActorContactAsymmetric, IsLayerContactEnabled

◆ EnableLayerContactSymmetric()

virtual void superdex::Scene::EnableLayerContactSymmetric ( std::string_view layerA,
std::string_view layerB,
bool enable,
Error & error )
pure virtual

Equivalent to calling EnableLayerContactAsymmetric with layerA and layerB in both orders.

Parameters
[in]layerAName of the first contact layer. Must be non-empty.
[in]layerBName of the second contact layer. Must be non-empty.
[in]enableTrue to enable contact, false to disable it.
[in,out]errorError status. Check Error::IsOK for success.
See also
EnableLayerContactAsymmetric, EnableActorContactSymmetric, IsLayerContactEnabled

◆ EnumerateContactLayerNames()

virtual void superdex::Scene::EnumerateContactLayerNames ( std::function< void(std::string_view name)> const & callback) const
pure virtual

Enumerate all unique contact layer names in the scene.

Parameters
[in]callbackFunction called once for each layer name.
Note
The callback fires GetNumContactLayers times.
Enumeration order is unspecified.
Warning
Do not register new contact layers from inside the callback. Doing so may invalidate the enumeration and cause undefined behavior.
See also
GetNumContactLayers

◆ ForEachActor() [1/2]

virtual void superdex::Scene::ForEachActor ( std::function< void(Actor *)> const & callback)
pure virtual

Iterate over all the actors in the scene using a callback.

Includes nested link actors and nested soft actors.

Parameters
[in]callbackFunction called once for each actor.
Note
To skip nested actors, check Actor::IsNestedLinkActor and Actor::IsNestedSoftActor inside the callback.
Warning
Destroying other actors or constraints from within the callback is illegal.

◆ ForEachActor() [2/2]

virtual void superdex::Scene::ForEachActor ( std::function< void(Actor const *)> const & callback) const
pure virtual

Iterate over all the actors in the scene using a callback (const version).

Includes nested link actors and nested soft actors.

Parameters
[in]callbackFunction called once for each actor.
Note
To skip nested actors, check Actor::IsNestedLinkActor and Actor::IsNestedSoftActor inside the callback.
Warning
Destroying other actors or constraints from within the callback is illegal.

◆ ForEachConstraint() [1/2]

virtual void superdex::Scene::ForEachConstraint ( std::function< void(Constraint *)> const & callback)
pure virtual

Iterate over all the constraints in the scene using a callback.

Parameters
[in]callbackFunction called once for each constraint.
Note
Includes constraints created implicitly by CreateArticulatedActor (e.g. articulated joint limits).
Warning
Destroying other constraints or actors from within the callback is illegal.

◆ ForEachConstraint() [2/2]

virtual void superdex::Scene::ForEachConstraint ( std::function< void(Constraint const *)> const & callback) const
pure virtual

Iterate over all the constraints in the scene using a callback (const version).

Parameters
[in]callbackFunction called once for each constraint.
Note
Includes constraints created implicitly by CreateArticulatedActor (e.g. articulated joint limits).
Warning
Destroying other constraints or actors from within the callback is illegal.

◆ GetActor() [1/2]

virtual Actor const * superdex::Scene::GetActor ( ActorHandle actor) const
nodiscardpure virtual

Get a const pointer to the Actor associated with an ActorHandle.

Parameters
[in]actorHandle of the actor to retrieve. If valid, it must be owned by this scene.
Returns
Const pointer to the Actor, or nullptr if the handle does not currently identify an actor in this scene.
See also
Actor, ActorHandle, DestroyActor, Actor::GetHandle

◆ GetActor() [2/2]

virtual Actor * superdex::Scene::GetActor ( ActorHandle actor)
nodiscardpure virtual

Get the Actor pointer associated with an ActorHandle.

Parameters
[in]actorHandle of the actor to retrieve. If valid, it must be owned by this scene.
Returns
Pointer to the Actor, or nullptr if the handle does not currently identify an actor in this scene.
See also
Actor, ActorHandle, DestroyActor, Actor::GetHandle

◆ GetActors() [1/2]

virtual void superdex::Scene::GetActors ( Span< Actor * > outActors,
Error & error )
pure virtual

Get Actor pointers for all the actors in the scene.

Parameters
[out]outActorsOutput span to fill with Actor pointers. Must be of size GetNumActors().
[in,out]errorError status. Check Error::IsOK for success.
See also
GetNumActors, GetActor

◆ GetActors() [2/2]

virtual void superdex::Scene::GetActors ( Span< Actor const * > outActors,
Error & error ) const
pure virtual

Get const Actor pointers for all the actors in the scene.

Parameters
[out]outActorsOutput span to fill with const Actor pointers. Must be of size GetNumActors().
[in,out]errorError status. Check Error::IsOK for success.
See also
GetNumActors, GetActor

◆ GetConstraint() [1/2]

virtual Constraint const * superdex::Scene::GetConstraint ( ConstraintHandle constraint) const
nodiscardpure virtual

Get the const Constraint pointer associated with a ConstraintHandle.

Parameters
[in]constraintHandle of the constraint to retrieve. If valid, it must be owned by this scene.
Returns
Const pointer to the Constraint, or nullptr if the handle does not currently identify a constraint in this scene.
See also
Constraint, ConstraintHandle, DestroyConstraint, Constraint::GetHandle

◆ GetConstraint() [2/2]

virtual Constraint * superdex::Scene::GetConstraint ( ConstraintHandle constraint)
nodiscardpure virtual

Get the Constraint pointer associated with a ConstraintHandle.

Parameters
[in]constraintHandle of the constraint to retrieve. If valid, it must be owned by this scene.
Returns
Pointer to the Constraint, or nullptr if the handle does not currently identify a constraint in this scene.
See also
Constraint, ConstraintHandle, DestroyConstraint, Constraint::GetHandle

◆ GetContext() [1/2]

virtual Context const * superdex::Scene::GetContext ( ) const
nodiscardpure virtual

Get read-only access to the Context that owns this scene.

Returns
Const pointer to the Context that owns this scene.

◆ GetContext() [2/2]

virtual Context * superdex::Scene::GetContext ( )
nodiscardpure virtual

Get the Context that owns this scene.

Returns
Pointer to the Context that owns this scene.

◆ GetDebugDraw() [1/2]

virtual DebugDraw const & superdex::Scene::GetDebugDraw ( ) const
nodiscardpure virtual

Get a const reference to the debug draw interface for this scene.

Returns
Const reference to the DebugDraw interface.
See also
DebugDraw

◆ GetDebugDraw() [2/2]

virtual DebugDraw & superdex::Scene::GetDebugDraw ( )
nodiscardpure virtual

Get the debug draw interface for this scene.

Returns
Reference to the DebugDraw interface.
See also
DebugDraw

◆ GetForceSingleIsland()

virtual bool superdex::Scene::GetForceSingleIsland ( ) const
nodiscardpure virtual

Get whether all actors are forced to be in a single simulation island.

Returns
True if all actors are forced into a single simulation island.
See also
SetForceSingleIsland

◆ GetGravity()

virtual Real3 superdex::Scene::GetGravity ( ) const
nodiscardpure virtual

Get the gravity vector in world frame.

Returns
Gravity vector [m/s^2] in world frame.
See also
SetGravity

◆ GetHandle()

virtual SceneHandle superdex::Scene::GetHandle ( ) const
pure virtual

Get the scene handle.

Returns
Scene's handle.
Note
Handles are safe to store and remain valid throughout the scene lifespan.
Call Context::GetScene to look up the scene's pointer from the scene's handle.
See also
Context::GetScene

◆ GetLastTimeStep()

virtual double superdex::Scene::GetLastTimeStep ( ) const
nodiscardpure virtual

Returns the time step size [s] from the most recent positive call to Step.

Returns
The time step size [s] from the most recent positive Step call.
Note
In a newly created scene, the return value is unspecified until the first positive Step call.
RestoreState and RestoreStateFromBytes restore this value from the captured state.
Calling Step with a zero time step (e.g. to refresh queries without advancing the simulation) does not update this value (i.e. it retains the value from the last positive time step).

◆ GetName()

virtual char const * superdex::Scene::GetName ( ) const
nodiscardpure virtual

Get the name of the scene.

Returns
Name of the scene.

◆ GetNumActors()

virtual int superdex::Scene::GetNumActors ( ) const
nodiscardpure virtual

Get the number of actors in the scene, including nested link actors and nested soft actors.

Returns
Number of actors in the scene.
Note
To count only top-level actors, iterate with ForEachActor and skip actors for which Actor::IsNestedLinkActor or Actor::IsNestedSoftActor returns true.

◆ GetNumConstraints()

virtual int superdex::Scene::GetNumConstraints ( ) const
nodiscardpure virtual

Get the number of constraints in the scene.

Returns
Number of constraints in the scene.
Note
Includes constraints created implicitly by CreateArticulatedActor (e.g. articulated joint limits).

◆ GetNumContactLayers()

virtual int superdex::Scene::GetNumContactLayers ( ) const
nodiscardpure virtual

Get the number of unique contact layer names in the scene.

Returns
Number of unique layer names in the scene.
Note
The count may include layer names not currently assigned to an actor.
See also
EnumerateContactLayerNames

◆ GetPerformanceStats()

virtual PerformanceStats superdex::Scene::GetPerformanceStats ( ) const
nodiscardpure virtual

Get timing and profiling metrics from the last simulation step.

Returns
The PerformanceStats from the last simulation step.
See also
PerformanceStats

◆ GetSolverParams()

virtual SolverParams superdex::Scene::GetSolverParams ( ) const
nodiscardpure virtual

Get the solver parameters.

Returns
Current solver parameters.
See also
SetSolverParams

◆ GetSolverStats()

virtual SolverStats superdex::Scene::GetSolverStats ( ) const
nodiscardpure virtual

Get solver convergence metrics from the last simulation step.

Returns
The SolverStats from the last simulation step.
See also
SolverStats, Actor::GetConvergenceStatus

◆ GetTotalSimulationTime()

virtual double superdex::Scene::GetTotalSimulationTime ( ) const
nodiscardpure virtual

Returns the total simulation time [s] in the scene.

Returns
The total simulation time [s].
Note
May not match the real-time that has elapsed.

◆ IsEqualState()

virtual bool superdex::Scene::IsEqualState ( StateHandle stateA,
StateHandle stateB ) const
nodiscardpure virtual

Return true if both StateHandles are valid and refer to identical state information (full precision).

Parameters
[in]stateAFirst StateHandle to compare
[in]stateBSecond StateHandle to compare
Returns
True if both states are valid and identical.

◆ IsLayerContactEnabled()

virtual bool superdex::Scene::IsLayerContactEnabled ( std::string_view layerA,
std::string_view layerB ) const
nodiscardpure virtual

Check if collision detection is enabled for an ordered pair of contact layer names.

Order matters: refers only to the specified direction (actors in layerA checking against actors in layerB).

Parameters
[in]layerAName of the layer of the "colliding" actor (the one checking for contact).
[in]layerBName of the layer of the "collider" actor (the one with a ColliderType being tested).
Returns
True if layer-to-layer contact is enabled, false if layer-to-layer contact is disabled.
Note
Contact is enabled by default, so you will get true for any pair of layers unless overridden via EnableLayerContactAsymmetric or EnableLayerContactSymmetric.
This only checks the layer filter. Actor-to-actor contact can still be disabled with EnableActorContactAsymmetric or EnableActorContactSymmetric.
See also
EnableLayerContactAsymmetric, EnableLayerContactSymmetric

◆ IsRecording()

virtual bool superdex::Scene::IsRecording ( ) const
nodiscardpure virtual

Check if the scene is currently recording.

Returns
True if recording is active, false otherwise.
Note
A recording write failure does not end the recording session.
See also
StartRecording, StopRecording

◆ RegisterPostStepCallback()

virtual CallbackHandle superdex::Scene::RegisterPostStepCallback ( std::string_view debugName,
std::function< void(StepInfo const &)> callback,
int priority = kDefaultCallbackPriority )
nodiscardpure virtual

Register a callback to execute after each simulation step.

Parameters
[in]debugNameDescriptive name for debugging and profiling.
[in]callbackCallback function receiving StepInfo.
[in]priorityExecution order. Lower values execute first (higher priority).
Returns
CallbackHandle for the registered callback.
Note
Callbacks run sequentially on the thread that calls Step, in increasing priority order (lower values first).
The relative order of callbacks registered with equal priority is unspecified. Assign distinct priorities when ordering matters.
Callbacks must be thread-safe if they access shared state.
Callbacks should not modify scene structure (add/remove actors/constraints).
See also
CancelCallback, RegisterPreStepCallback

◆ RegisterPreStepCallback()

virtual CallbackHandle superdex::Scene::RegisterPreStepCallback ( std::string_view debugName,
std::function< void(StepInfo const &)> callback,
int priority = kDefaultCallbackPriority )
nodiscardpure virtual

Register a callback to execute before each simulation step.

Parameters
[in]debugNameDescriptive name for debugging and profiling.
[in]callbackCallback function receiving StepInfo.
[in]priorityExecution order. Lower values execute first (higher priority).
Returns
CallbackHandle for the registered callback.
Note
Callbacks run sequentially on the thread that calls Step, in increasing priority order (lower values first).
The relative order of callbacks registered with equal priority is unspecified. Assign distinct priorities when ordering matters.
Callbacks must be thread-safe if they access shared state.
Callbacks should not modify scene structure (add/remove actors/constraints).
See also
CancelCallback, RegisterPostStepCallback

◆ ReleaseAllStates()

virtual void superdex::Scene::ReleaseAllStates ( )
pure virtual

Release memory for all captured state and invalidate all prior StateHandle objects.

◆ ReleaseState()

virtual void superdex::Scene::ReleaseState ( StateHandle handle)
pure virtual

Release a StateHandle when you are done with it.

This frees up memory.

Parameters
[in]handleStateHandle to release.
Note
Redundant calls to ReleaseState will be ignored.

◆ RestoreState()

virtual void superdex::Scene::RestoreState ( StateHandle handle,
bool releaseImmediately,
Error & error )
pure virtual

Restore captured simulation state.

Optionally release the StateHandle at the same time.

Parameters
[in]handleStateHandle from a successful call to CaptureState.
[in]releaseImmediatelyIf true, release the state handle immediately (as if ReleaseState were called), even if the restore fails.
[in,out]errorError status. Check Error::IsOK for success.
Note
The StateHandle must have been captured from this Scene.
The scene composition (actors, constraints) must be the same as when the state was captured.
Warning
Does not create or destroy actors or constraints, or restore shapes, materials, or scene parameters. Captured mutable state on existing actors, including static actor transforms, is restored; if topology or persistent configuration changes, simulation results may differ.
Restoration is not transactional. If restoration fails, the scene may be partially modified. Restore a known-good checkpoint or recreate the scene before continuing.
See also
CaptureState, ReleaseState, ReleaseAllStates, RestoreStateFromBytes

◆ RestoreStateFromBytes()

virtual void superdex::Scene::RestoreStateFromBytes ( Span< uint8_t const > data,
Error & error )
pure virtual

Restore simulation state from a binary byte buffer produced by CaptureStateToBytes.

Parameters
[in]dataState data from a successful call to CaptureStateToBytes.
[in,out]errorError status. Check Error::IsOK for success.
Note
The byte buffer must have been captured from this or a compatible scene via CaptureStateToBytes.
The capture and restore scenes must use the same SuperDex Physics build.
The restore requirements from RestoreState apply, including scene composition (actors, constraints) being the same as when the state was captured.
Warning
Has the same restore scope and non-transactional failure behavior as RestoreState.
See also
CaptureStateToBytes, RestoreState

◆ SetForceSingleIsland()

virtual void superdex::Scene::SetForceSingleIsland ( bool forceSingleIsland)
pure virtual

Enables/disables forcing all actors in the scene to be in a single simulation island.

An island is a group of actors and constraints that are solved together. Islands are managed automatically based on proximity and other factors. Islands can be solved in parallel, which can greatly improve the performance of the scene. However, if you suspect that island partitioning might be causing a problem, then you can use this function to force all actors in the scene to be simulated in a single island.

Parameters
[in]forceSingleIslandWhether to force all actors to be in a single simulation island.
Warning
Forcing single-island is a debugging feature. It will hurt performance.
See also
GetForceSingleIsland

◆ SetGravity()

virtual void superdex::Scene::SetGravity ( Real3 const & gravity)
pure virtual

Set the gravity vector in world frame.

Parameters
[in]gravityGravity vector [m/s^2] in world frame.
See also
GetGravity

◆ SetSolverParams()

virtual void superdex::Scene::SetSolverParams ( SolverParams const & params,
Error & error )
pure virtual

Set the solver parameters.

Parameters
[in]paramsSolver parameters to set.
[in,out]errorError status. Check Error::IsOK for success.
See also
GetSolverParams, SolverParams

◆ StartRecording()

virtual void superdex::Scene::StartRecording ( std::string_view filePath,
RecordingParams const & params,
Error & error )
pure virtual

Create or replace the specified file and start recording the scene to an HDF5 file.

Parameters
[in]filePathPath to the output recording file (case sensitive on some filesystems). File will be created or replaced.
[in]paramsParameters controlling what data to record.
[in,out]errorError status. Check Error::IsOK for success.
Note
Enabling additional recording features will generally increase the recording file size and degrade performance.
If the scene is already recording, the previous recording is stopped before starting the new one.
Warning
Requires a build with HDF5 support.
The recording system may undergo a substantial refactor to expand its capabilities. Its API and recorded file format may change in future releases.
See also
StopRecording, IsRecording, RecordingParams

◆ Step()

virtual void superdex::Scene::Step ( double timeStepSec)
pure virtual

Advance the simulation of the Scene one step.

SuperDex Physics uses fully-implicit time integration, enabling substantially larger stable time steps than physics engines using explicit or semi-implicit methods, particularly for stiff systems. Fewer steps per simulated second often improve simulation performance and real-time factor.

Parameters
[in]timeStepSecTime step size [s]. Must be non-negative.
Note
Time steps of 10–25 ms (40–100 physics steps per simulated second) run robustly in most scenes, including complex contact-rich and deformable simulations. This is a practical starting range, not a guarantee. Smaller steps may still be required to resolve fast motion, accurately capture short-duration contact dynamics without excessive numerical dissipation, resolve dynamics associated with small geometric or discretization length scales, or improve nonlinear-solver convergence.
It is OK to use a different time step each time.
If the time step is zero, then the state of the simulation will not change, but pre-step and post-step callbacks will still be called, and queries will be updated.
If the time step is negative or NaN, no step is taken and an error is logged.
See also
IntegrationMethod

◆ StopRecording()

virtual void superdex::Scene::StopRecording ( )
pure virtual

Stop recording the scene and close the recording file.

See also
StartRecording, IsRecording

◆ UpdateDebugger()

virtual void superdex::Scene::UpdateDebugger ( )
pure virtual

This gives the debugger a chance to process messages that require reading or writing scene state.

Please call this periodically if you are not actively stepping the scene. If this function is never called and the scene is never stepped, then some debugger features will not work.

Note
Must be called on the scene's owning thread (like other Scene methods).

Member Data Documentation

◆ kDefaultCallbackPriority

int superdex::Scene::kDefaultCallbackPriority = 100
staticconstexpr

Default priority for callback ordering.

Lower values execute earlier (higher priority).

Definition at line 254 of file mochi_scene.h.


The documentation for this class was generated from the following files: