Class DynamicAnimControl

All Implemented Interfaces:
PhysicsCollisionListener, PhysicsControl, PhysicsTickListener, Savable, Control, JmeCloneable, Cloneable

public class DynamicAnimControl extends DacLinks implements PhysicsCollisionListener
Before adding this control to a spatial, configure it by invoking DacConfiguration.link(java.lang.String, float, com.jme3.bullet.animation.RangeOfMotion) for each bone that should have its own rigid body. Leave unlinked bones near the root of the skeleton to form the torso of the ragdoll.

When you add the control to a spatial, it generates a ragdoll consisting of a rigid body for the torso and another for each linked bone. It also creates a SixDofJoint connecting each rigid body to its parent in the link hierarchy. The mass of each rigid body and the range-of-motion of each joint can be reconfigured on the fly.

Each link is either dynamic (driven by forces and torques) or kinematic (unperturbed by forces and torques). Transitions from dynamic to kinematic can be immediate or gradual.

This class is shared between JBullet and Native Bullet.

  • Field Details

    • logger35

      public static final Logger logger35
      message logger for this class
  • Constructor Details

    • DynamicAnimControl

      public DynamicAnimControl()
      Instantiate an enabled control without any linked bones (torso only).
  • Method Details

    • addCollisionListener

      public void addCollisionListener(RagdollCollisionListener listener)
      Add a collision listener to this control.
      Parameters:
      listener - (not null, alias created)
    • animateSubtree

      public void animateSubtree(PhysicsLink rootLink, float blendInterval)
      Begin blending the specified link and all its descendants to kinematic animation.
      Parameters:
      rootLink - the root of the subtree to bind (not null)
      blendInterval - the duration of the blend interval (in seconds, ≥0)
    • blendToKinematicMode

      public void blendToKinematicMode(float blendInterval, Transform endModelTransform)
      Begin blending all links to purely kinematic mode, driven by animation. TODO callback when the transition completes

      Allowed only when the control IS added to a spatial.

      Parameters:
      blendInterval - the duration of the blend interval (in seconds, ≥0)
      endModelTransform - the desired local transform for the controlled spatial when the transition completes or null for no change to local transform (unaffected)
    • centerOfMass

      public float centerOfMass(Vector3f storeLocation, Vector3f storeVelocity)
      Calculate the ragdoll's total mass and center of mass.

      Allowed only when the control IS added to a spatial.

      Parameters:
      storeLocation - storage for the location of the center (in physics-space coordinates, modified if not null)
      storeVelocity - storage for the velocity of the center (psu/second in physics-space coordinates, modified if not null)
      Returns:
      the total mass (>0)
    • setContactResponseSubtree

      public void setContactResponseSubtree(PhysicsLink rootLink, boolean desiredResponse)
      Alter the contact-response setting of the specified link and all its descendants. Note: recursive!

      Allowed only when the control IS added to a spatial.

      Parameters:
      rootLink - the root of the subtree to modify (not null)
      desiredResponse - true for the usual rigid-body response, false for ghost-like response
    • setDynamicChain

      public void setDynamicChain(PhysicsLink startLink, int chainLength, Vector3f uniformAcceleration)
      Immediately put the specified link and all its ancestors (excluding the torso) into dynamic mode. Note: recursive!

      Allowed only when the control IS added to a spatial.

      Parameters:
      startLink - the start of the chain to modify (not null)
      chainLength - the maximum number of links to modify (≥0)
      uniformAcceleration - the uniform acceleration vector (in physics-space coordinates, not null, unaffected)
    • setDynamicSubtree

      public void setDynamicSubtree(PhysicsLink rootLink, Vector3f uniformAcceleration)
      Immediately put the specified link and all its descendants into dynamic mode. Note: recursive!

      Allowed only when the control IS added to a spatial.

      Parameters:
      rootLink - the root of the subtree to modify (not null)
      uniformAcceleration - the uniform acceleration vector (in physics-space coordinates, not null, unaffected)
    • setKinematicMode

      public void setKinematicMode()
      Immediately put all links into purely kinematic mode.

      Allowed only when the control IS added to a spatial.

    • setRagdollMode

      public void setRagdollMode()
      Immediately put this control into ragdoll mode.

      Allowed only when the control IS added to a spatial and all links are "ready".

    • addPhysics

      protected void addPhysics(PhysicsSpace space)
      Add all managed physics objects to the PhysicsSpace.
      Overrides:
      addPhysics in class DacLinks
      Parameters:
      space - which physics space to add to (not null)
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Callback from Cloner to convert this shallow-cloned control into a deep-cloned one, using the specified cloner and original to resolve copied fields.
      Specified by:
      cloneFields in interface JmeCloneable
      Overrides:
      cloneFields in class DacLinks
      Parameters:
      cloner - the cloner that's cloning this control (not null, modified)
      original - the control from which this control was shallow-cloned (not null, unaffected)
    • jmeClone

      public DynamicAnimControl jmeClone()
      Create a shallow clone for the JME cloner.
      Specified by:
      jmeClone in interface JmeCloneable
      Overrides:
      jmeClone in class DacLinks
      Returns:
      a new instance
    • read

      public void read(JmeImporter im) throws IOException
      De-serialize this control, for example when loading from a J3O file.
      Specified by:
      read in interface Savable
      Overrides:
      read in class DacLinks
      Parameters:
      im - the importer (not null)
      Throws:
      IOException - from the importer
    • removePhysics

      protected void removePhysics(PhysicsSpace space)
      Remove all managed physics objects from the PhysicsSpace.
      Overrides:
      removePhysics in class DacLinks
      Parameters:
      space - which physics space to remove from (not null)
    • write

      public void write(JmeExporter ex) throws IOException
      Serialize this control, for example when saving to a J3O file.
      Specified by:
      write in interface Savable
      Overrides:
      write in class DacLinks
      Parameters:
      ex - the exporter (not null)
      Throws:
      IOException - from the exporter
    • collision

      public void collision(PhysicsCollisionEvent event)
      For internal use only: callback for collision events.
      Specified by:
      collision in interface PhysicsCollisionListener
      Parameters:
      event - (not null)