java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.PhysicsScene
All Implemented Interfaces:
ConstJoltPhysicsObject, ConstPhysicsScene, RefTarget, AutoCloseable, Comparable<JoltPhysicsObject>

public class PhysicsScene extends JoltPhysicsObject implements ConstPhysicsScene, RefTarget
The creation settings of a set of bodies.
  • Field Details

    • cFixedToWorld

      public static final int cFixedToWorld
      body index that denotes attachment to the fixed world
      See Also:
  • Constructor Details

    • PhysicsScene

      public PhysicsScene()
      Instantiate an empty scene.
  • Method Details

    • addBody

      public void addBody(ConstBodyCreationSettings body)
      Add the specified body to the scene.
      Parameters:
      body - the body settings (not null, unaffected)
    • addConstraint

      public void addConstraint(TwoBodyConstraintSettings constraint, int body1, int body2)
      Add the specified constraint to the scene.
      Parameters:
      constraint - the constraint settings (not null, unaffected)
      body1 - the index of the first body in the bodies list
      body2 - the index of the 2nd body in the bodies list
    • addSoftBody

      public void addSoftBody(ConstSoftBodyCreationSettings softBody)
      Add the specified soft body to the scene.
      Parameters:
      softBody - the soft-body settings (not null, unaffected)
    • createBodies

      public boolean createBodies(PhysicsSystem system)
      Instantiate the bodies in the scene.
      Parameters:
      system - where to add the bodies (not null, modified)
      Returns:
      true if successful, otherwise false
    • fixInvalidScales

      public boolean fixInvalidScales()
      Correct any incorrectly scaled shapes in the scene.
      Returns:
      true if successful, otherwise false
    • fromPhysicsSystem

      public void fromPhysicsSystem(ConstPhysicsSystem system)
      Load the current state of the specified physics system.
      Parameters:
      system - the physics system to load from (not null, unaffected)
    • sRestoreFromBinaryState

      public static PhysicsSceneResult sRestoreFromBinaryState(StreamIn stream)
      Attempt to de-serialize a saved scene from the specified stream.
      Parameters:
      stream - the stream to read (not null)
      Returns:
      a new object
    • getBodies

      public BodyCreationSettings[] getBodies()
      Access the body-creation settings as a Java array.
      Specified by:
      getBodies in interface ConstPhysicsScene
      Returns:
      a new array of new JVM objects with the pre-existing native objects assigned
    • getConstraints

      public ConnectedConstraint[] getConstraints()
      Access the constraints as a Java array.
      Specified by:
      getConstraints in interface ConstPhysicsScene
      Returns:
      a new array of new JVM objects with the pre-existing native objects assigned
    • getNumBodies

      public int getNumBodies()
      Count the bodies in the scene. The scene is unaffected.
      Specified by:
      getNumBodies in interface ConstPhysicsScene
      Returns:
      the count (≥0)
    • getNumConstraints

      public int getNumConstraints()
      Count the constraints in the scene. The scene is unaffected.
      Specified by:
      getNumConstraints in interface ConstPhysicsScene
      Returns:
      the count (≥0)
    • getNumSoftBodies

      public int getNumSoftBodies()
      Count the soft bodies in the scene. The scene is unaffected.
      Specified by:
      getNumSoftBodies in interface ConstPhysicsScene
      Returns:
      the count (≥0)
    • getSoftBodies

      public SoftBodyCreationSettings[] getSoftBodies()
      Access the soft-body creation settings as a Java array.
      Specified by:
      getSoftBodies in interface ConstPhysicsScene
      Returns:
      a new array of new JVM objects with pre-existing native objects assigned
    • saveBinaryState

      public void saveBinaryState(StreamOut stream, boolean saveShapes, boolean saveGroupFilter)
      Save the scene to the specified binary stream. The scene is unaffected.
      Specified by:
      saveBinaryState in interface ConstPhysicsScene
      Parameters:
      stream - the stream to write to (not null)
      saveShapes - if true, save the shapes
      saveGroupFilter - if true, save the group filter
    • getRefCount

      public int getRefCount()
      Count the active references to the native PhysicsScene. The scene is unaffected.
      Specified by:
      getRefCount in interface RefTarget
      Returns:
      the count (≥0)
    • setEmbedded

      public void setEmbedded()
      Mark the native PhysicsScene as embedded.
      Specified by:
      setEmbedded in interface RefTarget
    • toRef

      public PhysicsSceneRef toRef()
      Create a counted reference to the current scene.
      Specified by:
      toRef in interface RefTarget
      Returns:
      a new JVM object with a new native object assigned