com.jme3.bullet.control
Class KinematicRagdollControl

java.lang.Object
  extended by com.jme3.bullet.control.KinematicRagdollControl
All Implemented Interfaces:
PhysicsCollisionListener, PhysicsControl, Savable, Control

public class KinematicRagdollControl
extends java.lang.Object
implements PhysicsControl, PhysicsCollisionListener

This control is still a WIP, use it at your own risk
To use this control you need a model with an AnimControl and a SkeletonControl.
This should be the case if you imported an animated model from Ogre or blender.
Note enabling/disabling the control add/removes it from the physic space

This control creates collision shapes for each bones of the skeleton when you call spatial.addControl(ragdollControl).

There are 2 modes for this control :


Nested Class Summary
static class KinematicRagdollControl.Mode
           
protected  class KinematicRagdollControl.PhysicsBoneLink
           
 
Field Summary
protected  boolean added
           
protected  PhysicsRigidBody baseRigidBody
           
protected  boolean blendedControl
           
protected  float blendStart
           
protected  float blendTime
           
protected  java.util.Map<java.lang.String,KinematicRagdollControl.PhysicsBoneLink> boneLinks
           
protected  java.util.Set<java.lang.String> boneList
           
protected  boolean debug
           
protected  boolean enabled
           
protected  float eventDispatchImpulseThreshold
           
protected  Vector3f initScale
           
protected  java.util.List<RagdollCollisionListener> listeners
           
protected static java.util.logging.Logger logger
           
protected  KinematicRagdollControl.Mode mode
           
protected  Vector3f modelPosition
           
protected  Quaternion modelRotation
           
protected  RagdollPreset preset
           
protected  float rootMass
           
protected  Skeleton skeleton
           
protected  PhysicsSpace space
           
protected  Spatial targetModel
           
protected  float totalMass
           
protected  float weightThreshold
           
 
Constructor Summary
KinematicRagdollControl()
          contruct a KinematicRagdollControl
KinematicRagdollControl(float weightThreshold)
           
KinematicRagdollControl(RagdollPreset preset)
           
KinematicRagdollControl(RagdollPreset preset, float weightThreshold)
           
 
Method Summary
 void addBoneName(java.lang.String name)
          Add a bone name to this control Using this method you can specify which bones of the skeleton will be used to build the collision shapes.
 void addCollisionListener(RagdollCollisionListener listener)
          add a
protected  void attachDebugShape(AssetManager manager)
           
 void blendToKinematicMode(float blendTime)
          Smoothly blend from Ragdoll mode to Kinematic mode This is useful to blend ragdoll actual position to a keyframe animation for example
 Control cloneForSpatial(Spatial spatial)
          Creates a clone of the Control, the given Spatial is the cloned version of the spatial to which this control is attached to.
 void collision(PhysicsCollisionEvent event)
          For internal use only callback for collisionevent
protected  void detachDebugShape()
           
 PhysicsRigidBody getBoneRigidBody(java.lang.String boneName)
          return the rigidBody associated to the given bone
 float getEventDispatchImpulseThreshold()
           
 SixDofJoint getJoint(java.lang.String boneName)
          Return the joint between the given bone and its parent.
 KinematicRagdollControl.Mode getMode()
          retruns the mode of this control
 PhysicsSpace getPhysicsSpace()
          returns the physic space
 float getTotalMass()
           
 float getWeightThreshold()
           
 boolean isEnabled()
          returns true if the control is enabled
 void read(JmeImporter im)
          de-serialize this control
 void reBuild()
          rebuild the ragdoll this is useful if you applied scale on the ragdoll after it's been initialized
protected  void removeFromPhysicsSpace()
           
 void render(RenderManager rm, ViewPort vp)
          For internal use only specific render for the ragdoll(if debugging)
 void setBoneCcdMotionThreshold(java.lang.String boneName, float value)
          Deprecated. use getBoneRigidBody(String BoneName).setCcdMotionThreshold(float) instead
 void setBoneCcdSweptSphereRadius(java.lang.String boneName, float value)
          Deprecated. use getBoneRigidBody(String BoneName).setCcdSweptSphereRadius(float) instead
 void setCcdMotionThreshold(float value)
          Set the CcdMotionThreshold of all the bone's rigidBodies of the ragdoll
 void setCcdSweptSphereRadius(float value)
          Set the CcdSweptSphereRadius of all the bone's rigidBodies of the ragdoll
 void setEnabled(boolean enabled)
          enable or disable the control note that if enabled is true and that the physic space has been set on the ragdoll, the ragdoll is added to the physic space if enabled is false the ragdoll is removed from physic space.
 void setEventDispatchImpulseThreshold(float eventDispatchImpulseThreshold)
           
 void setJointLimit(java.lang.String boneName, float maxX, float minX, float maxY, float minY, float maxZ, float minZ)
          Set the joint limits for the joint between the given bone and its parent.
 void setKinematicMode()
          Set the control into Kinematic mode In theis mode, the collision shapes follow the movements of the skeleton, and can interact with physical environement
protected  void setMode(KinematicRagdollControl.Mode mode)
          Enable or disable the ragdoll behaviour.
 void setPhysicsSpace(PhysicsSpace space)
          set the physic space to this ragdoll
 void setRagdollMode()
          Sets the control into Ragdoll mode The skeleton is entirely controlled by physics.
 void setRootMass(float rootMass)
           
 void setSpatial(Spatial model)
           
 void setWeightThreshold(float weightThreshold)
           
 void update(float tpf)
          Updates the control.
 void write(JmeExporter ex)
          serialize this control
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final java.util.logging.Logger logger

boneLinks

protected java.util.Map<java.lang.String,KinematicRagdollControl.PhysicsBoneLink> boneLinks

skeleton

protected Skeleton skeleton

space

protected PhysicsSpace space

enabled

protected boolean enabled

debug

protected boolean debug

baseRigidBody

protected PhysicsRigidBody baseRigidBody

weightThreshold

protected float weightThreshold

targetModel

protected Spatial targetModel

initScale

protected Vector3f initScale

mode

protected KinematicRagdollControl.Mode mode

blendedControl

protected boolean blendedControl

blendTime

protected float blendTime

blendStart

protected float blendStart

listeners

protected java.util.List<RagdollCollisionListener> listeners

eventDispatchImpulseThreshold

protected float eventDispatchImpulseThreshold

preset

protected RagdollPreset preset

boneList

protected java.util.Set<java.lang.String> boneList

modelPosition

protected Vector3f modelPosition

modelRotation

protected Quaternion modelRotation

rootMass

protected float rootMass

totalMass

protected float totalMass

added

protected boolean added
Constructor Detail

KinematicRagdollControl

public KinematicRagdollControl()
contruct a KinematicRagdollControl


KinematicRagdollControl

public KinematicRagdollControl(float weightThreshold)

KinematicRagdollControl

public KinematicRagdollControl(RagdollPreset preset,
                               float weightThreshold)

KinematicRagdollControl

public KinematicRagdollControl(RagdollPreset preset)
Method Detail

update

public void update(float tpf)
Description copied from interface: Control
Updates the control. This should not be called from user code.

Specified by:
update in interface Control
Parameters:
tpf - Time per frame.

cloneForSpatial

public Control cloneForSpatial(Spatial spatial)
Description copied from interface: Control
Creates a clone of the Control, the given Spatial is the cloned version of the spatial to which this control is attached to.

Specified by:
cloneForSpatial in interface Control
Returns:
A clone of this control for the spatial

reBuild

public void reBuild()
rebuild the ragdoll this is useful if you applied scale on the ragdoll after it's been initialized


setSpatial

public void setSpatial(Spatial model)
Specified by:
setSpatial in interface Control
Parameters:
model - the spatial to be controlled. This should not be called from user code.

addBoneName

public void addBoneName(java.lang.String name)
Add a bone name to this control Using this method you can specify which bones of the skeleton will be used to build the collision shapes.

Parameters:
name -

setJointLimit

public void setJointLimit(java.lang.String boneName,
                          float maxX,
                          float minX,
                          float maxY,
                          float minY,
                          float maxZ,
                          float minZ)
Set the joint limits for the joint between the given bone and its parent. This method can't work before attaching the control to a spatial

Parameters:
boneName - the name of the bone
maxX - the maximum rotation on the x axis (in radians)
minX - the minimum rotation on the x axis (in radians)
maxY - the maximum rotation on the y axis (in radians)
minY - the minimum rotation on the z axis (in radians)
maxZ - the maximum rotation on the z axis (in radians)
minZ - the minimum rotation on the z axis (in radians)

getJoint

public SixDofJoint getJoint(java.lang.String boneName)
Return the joint between the given bone and its parent. This return null if it's called before attaching the control to a spatial

Parameters:
boneName - the name of the bone
Returns:
the joint between the given bone and its parent

removeFromPhysicsSpace

protected void removeFromPhysicsSpace()

setEnabled

public void setEnabled(boolean enabled)
enable or disable the control note that if enabled is true and that the physic space has been set on the ragdoll, the ragdoll is added to the physic space if enabled is false the ragdoll is removed from physic space.

Specified by:
setEnabled in interface PhysicsControl
Parameters:
enabled -

isEnabled

public boolean isEnabled()
returns true if the control is enabled

Returns:

attachDebugShape

protected void attachDebugShape(AssetManager manager)

detachDebugShape

protected void detachDebugShape()

render

public void render(RenderManager rm,
                   ViewPort vp)
For internal use only specific render for the ragdoll(if debugging)

Specified by:
render in interface Control
Parameters:
rm -
vp -

setPhysicsSpace

public void setPhysicsSpace(PhysicsSpace space)
set the physic space to this ragdoll

Specified by:
setPhysicsSpace in interface PhysicsControl
Parameters:
space -

getPhysicsSpace

public PhysicsSpace getPhysicsSpace()
returns the physic space

Specified by:
getPhysicsSpace in interface PhysicsControl
Returns:

write

public void write(JmeExporter ex)
           throws java.io.IOException
serialize this control

Specified by:
write in interface Savable
Parameters:
ex -
Throws:
java.io.IOException

read

public void read(JmeImporter im)
          throws java.io.IOException
de-serialize this control

Specified by:
read in interface Savable
Parameters:
im -
Throws:
java.io.IOException

collision

public void collision(PhysicsCollisionEvent event)
For internal use only callback for collisionevent

Specified by:
collision in interface PhysicsCollisionListener
Parameters:
event -

setMode

protected void setMode(KinematicRagdollControl.Mode mode)
Enable or disable the ragdoll behaviour. if ragdollEnabled is true, the character motion will only be powerd by physics else, the characted will be animated by the keyframe animation, but will be able to physically interact with its physic environnement

Parameters:
ragdollEnabled -

blendToKinematicMode

public void blendToKinematicMode(float blendTime)
Smoothly blend from Ragdoll mode to Kinematic mode This is useful to blend ragdoll actual position to a keyframe animation for example

Parameters:
blendTime - the blending time between ragdoll to anim.

setKinematicMode

public void setKinematicMode()
Set the control into Kinematic mode In theis mode, the collision shapes follow the movements of the skeleton, and can interact with physical environement


setRagdollMode

public void setRagdollMode()
Sets the control into Ragdoll mode The skeleton is entirely controlled by physics.


getMode

public KinematicRagdollControl.Mode getMode()
retruns the mode of this control

Returns:

addCollisionListener

public void addCollisionListener(RagdollCollisionListener listener)
add a

Parameters:
listener -

setRootMass

public void setRootMass(float rootMass)

getTotalMass

public float getTotalMass()

getWeightThreshold

public float getWeightThreshold()

setWeightThreshold

public void setWeightThreshold(float weightThreshold)

getEventDispatchImpulseThreshold

public float getEventDispatchImpulseThreshold()

setEventDispatchImpulseThreshold

public void setEventDispatchImpulseThreshold(float eventDispatchImpulseThreshold)

setCcdMotionThreshold

public void setCcdMotionThreshold(float value)
Set the CcdMotionThreshold of all the bone's rigidBodies of the ragdoll

Parameters:
value -
See Also:
PhysicsRigidBody.setCcdMotionThreshold(float)

setCcdSweptSphereRadius

public void setCcdSweptSphereRadius(float value)
Set the CcdSweptSphereRadius of all the bone's rigidBodies of the ragdoll

Parameters:
value -
See Also:
PhysicsRigidBody.setCcdSweptSphereRadius(float)

setBoneCcdMotionThreshold

@Deprecated
public void setBoneCcdMotionThreshold(java.lang.String boneName,
                                                 float value)
Deprecated. use getBoneRigidBody(String BoneName).setCcdMotionThreshold(float) instead

Set the CcdMotionThreshold of the given bone's rigidBodies of the ragdoll

Parameters:
value -
See Also:
PhysicsRigidBody.setCcdMotionThreshold(float)

setBoneCcdSweptSphereRadius

@Deprecated
public void setBoneCcdSweptSphereRadius(java.lang.String boneName,
                                                   float value)
Deprecated. use getBoneRigidBody(String BoneName).setCcdSweptSphereRadius(float) instead

Set the CcdSweptSphereRadius of the given bone's rigidBodies of the ragdoll

Parameters:
value -
See Also:
PhysicsRigidBody.setCcdSweptSphereRadius(float)

getBoneRigidBody

public PhysicsRigidBody getBoneRigidBody(java.lang.String boneName)
return the rigidBody associated to the given bone

Parameters:
boneName - the name of the bone
Returns:
the associated rigidBody.