hmi.elckerlyc.animationengine.procanimation
Class ProcAnimationMU

java.lang.Object
  extended by hmi.xml.XMLStructureAdapter
      extended by hmi.elckerlyc.animationengine.procanimation.ProcAnimationMU
All Implemented Interfaces:
KeyPositionManager, MotionUnit, XMLStructure

public class ProcAnimationMU
extends XMLStructureAdapter
implements MotionUnit

Generic procedural animation package Animation is described as end effector path, joint rotation path and/or joint positions at key times Typical program flow:
1. load proc animation through XML
2. setup an IKBody
3. link the IKBody to the proc animation through the setup function
4. animate using the play function

Author:
welberge, Mark ter Maat

Nested Class Summary
(package private) static class ProcAnimationMU.IKParameter
           
 
Field Summary
private  IKBody body
           
private  Set<String> bodyPartFilter
           
private  Set<VJoint> bodyParts
           
private  ArrayList<EndEffector> endeffector
           
private  float[] goal
           
 Id id
           
private  List<KeyframeMU> keyFrameMUs
           
private  HashMap<String,Keyframes> keyframes
           
private  KeyPositionManager keyPositionManager
           
private  EndEffector leftFootEff
           
private  EndEffector leftHandEff
           
private  float[] lf
           
private  float[] lh
           
private  double maxDuration
           
private  double minDuration
           
private  ArrayList<ProcAnimationMU.IKParameter> parameters
           
private  org.lsmp.djep.xjep.XJep parser
           
private  double prefDuration
           
private  float[] q
           
private  float[] rf
           
private  float[] rh
           
private  EndEffector rightFootEff
           
private  EndEffector rightHandEff
           
private  float[] ro
           
private  EndEffector rootEff
           
private  HashMap<String,Rotation> rotations
           
private  org.nfunk.jep.Variable tVar
           
 
Fields inherited from class hmi.xml.XMLStructureAdapter
ATTRIBUTE_TOKEN_DELIMITERS, COMMA_SEPARATOR, DECODEDARRAYSIZE, DEFAULT_RECOVER_MODE, NEWLINE, SYSTEMNEWLINE, TAB, TAB_STRING
 
Constructor Summary
ProcAnimationMU()
          Constructor
 
Method Summary
 void addEndEffector(EndEffector eff)
          Adds an endeffector
 void addKeyframes(Keyframes kf)
          Adds a keyframe
 void addKeyPosition(KeyPosition kp)
           
 void addParameter(Parameter p)
          Adds a parameter
 void addSkeletonInterpolator(SkeletonInterpolator ski)
           
 StringBuilder appendAttributeString(StringBuilder buf)
          Appends a String to buf that encodes the attributes for the XML encoding.
 StringBuilder appendContent(StringBuilder buf, XMLFormatting fmt)
          Appends a String to buf that encodes the contents for the XML encoding.
private  boolean containsOnlyLetters(String str)
          Checks if the given String only contains letters
 MotionUnit copy(AnimationPlayer p)
          Create a copy of this motion unit and link it to the animationplayer
 MotionUnit copy(VJoint v)
          Creates a copy of this ProcAnimation and links is to VJoint v
 TimedMotionUnit createTMU(BMLBlockPeg bbPeg, String i, String bmlId)
          Creates the TimedMotionUnit corresponding to this motion unit
 boolean decodeAttribute(String attrName, String attrValue)
          decodes the value from an attribute value String returns true if succesful, returns false for attribute names that are not recognized.
 boolean decodeAttribute(String attrName, String attrValue, XMLTokenizer tokenizer)
          decodes the value from an attribute value String returns true if succesful, returns false for attribute names that are not recognized.
 void decodeContent(XMLTokenizer tokenizer)
          decodes the XML contents, i.e. the XML between the STag and ETag of the encoding.
 ProcAnimationMU deepCopy()
          Creates a copy of this ProcAnimation.
private  void filterBodyParts()
           
private  void findMissingParameters()
           
 List<EndEffector> getAllEndEffectors()
          Returns the complete arraylist with EndEffectors
 Set<VJoint> getControlledJoints()
          Gets the joints steered with this ProcAnimation
 EndEffector getEndEffector(String target)
          Get the EndEffector with sid target
private  ProcAnimationMU.IKParameter getIKParameter(String paramId)
           
 KeyPosition getKeyPosition(String name)
           
 List<KeyPosition> getKeyPositions()
          Gets a sorted view of the list of keypositions
 EndEffector getLeftFootEff()
           
 EndEffector getLeftHandEff()
           
 double getMaxDuration()
           
 double getMinDuration()
           
 Collection<Parameter> getParameters()
          Gets the parameters
 String getParameterValue(String name)
           
 void getPositions(float[] lf, float[] rf, float[] lh, float[] rh, float[] root, double[] swivels)
          Get the current endeffector IK info
 MotionUnit getPredictor(VJoint predict)
          Creates a copy of this ProcAnimation, but links the parameters of the copy directly to this animation.
 double getPrefDuration()
           
 double getPreferedDuration()
           
 String getReplacementGroup()
          Get the motionunit replacement group (=typically the BML behavior) Used to determine the currently active persistent TMU for this group in the player Only one group is active at a time
 EndEffector getRightFootEff()
           
 EndEffector getRightHandEff()
           
 EndEffector getRootEff()
           
 Rotation getRotation(String target)
          Returns the Rotation of the given target
 HashMap<String,Rotation> getRotations()
           
 String getXMLTag()
          returns the XML tag that is used to encode this type of XMLStructure.
private  boolean isConstantParameter(String str)
           
 void mirror()
           
private  boolean parameterExists(String str)
          Checks if a parameter exists with the given name
 void play(double t)
          Play the IKAnimation at time 0 < t < 1 First plays all skeletoninterpolators, then sets the joints starting at the root as specified by IK and keyframes
private  void play(double t, VJoint v)
           
 void removeEndEffector(String name)
          Removes all endeffectors with target name
 void removeKeyPosition(String id)
           
 void removeRotation(String name)
          Removes a rotation
 void set(ProcAnimationMU ani)
          Sets to ani, copies over all of ani's properties
 void setEffectors(ProcAnimationMU ik)
          Set the endeffectors of another ProcAnimation into this animation.
 void setEndEffector(String name, String xForm, String yForm, String zForm, String sForm, boolean isLocal)
          Sets a end effector to a certain formula, adds it to the endeffector list if it does not exist yet
 void setEndEffectors(ArrayList<EndEffector> newEndEffectors)
          Set a new set of EndEffectors
 void setKeyframes(HashMap<String,Keyframes> frs)
          Set the keyframes to frs
 void setKeyPositions(List<KeyPosition> p)
           
 void setMaxDuration(double maxDuration)
           
 void setMinDuration(double minDuration)
           
 void setParameters(Collection<Parameter> ps)
          Sets the parameters the parameters in ps, retaining the 'old' parameters that not are part of ps
 void setParameterValue(String sid, float value)
          Sets the parameter value for parameter sid.
 void setParameterValue(String name, String value)
           
private  void setParameterValues()
           
 void setPrefDuration(double prefDuration)
           
 void setRotation(String name, String xForm, String yForm, String zForm)
          Sets a rotation to a certain formula, adds it to the rotation list if it does not exist yet
 void setRotations(HashMap<String,Rotation> rots)
          Set the rotations
 void setRotations(ProcAnimationMU ik)
          Copies the rotations from another ProcAnimation Rotations that occur in ik but not in this ProcAnimation are ignored
 void setup(Collection<Parameter> params, IKBody b)
          Links the ProcAnimation to a body and a set of parameters Filters out the joints to animate based on the set Rotations, end effectors, keyframes and skeletoninterpolators
private  void setupEndEffectors()
           
private  void setupParser()
           
 String toString()
          Get the id string
 
Methods inherited from class hmi.xml.XMLStructureAdapter
appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttribute, appendAttributes, appendAttributes, appendAttributeString, appendBooleans, appendCloseEmptyTag, appendCloseSTag, appendComment, appendContent, appendDoubleElement, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendEmptyTag, appendETag, appendETag, appendFloatArrayElement, appendFloatElement, appendFloats, appendIntArrayElement, appendIntElement, appendInts, appendLongElement, appendNewLine, appendNewLine, appendNewLine, appendOpenSTag, appendOptionalDoubleElement, appendOptionalFloatElement, appendOptionalIntElement, appendOptionalLongElement, appendSpaces, appendSpaces, appendSTag, appendSTag, appendSTag, appendStringArrayElement, appendStrings, appendSystemNewLine, appendTab, appendTextElement, appendXML, appendXML, appendXML, appendXML, appendXML, appendXMLStructure, appendXMLStructureList, appendXMLTextElementList, countTokens, countTokens, decodeAttributes, decodeBoolean, decodeBooleanArray, decodeBooleanArray, decodeBooleanArray, decodeBooleanArray, decodeDouble, decodeDoubleArray, decodeDoubleArray, decodeDoubleArray, decodeDoubleArray, decodeFloat, decodeFloatArray, decodeFloatArray, decodeFloatArray, decodeFloatArray, decodeInt, decodeIntArray, decodeIntArray, decodeIntArray, decodeIntArray, decodeLong, decodeStringArray, decodeStringArray, decodeStringArray, decodeStringArray, decodeXMLStructureList, decodeXMLValueElement, getNamespace, getOptionalAttribute, getOptionalAttribute, getOptionalBooleanAttribute, getOptionalDoubleAttribute, getOptionalFloatAttribute, getOptionalIntAttribute, getOptionalLongAttribute, getRequiredAttribute, getRequiredBooleanAttribute, getRequiredDoubleAttribute, getRequiredFloatAttribute, getRequiredIntAttribute, getRequiredLongAttribute, getTagLine, hasContent, parseXMLElement, postProcess, preProcess, readXML, readXML, readXML, setConsoleAttributeEnabled, setDefaultRecoverMode, setRecoverMode, spaces, toXMLString, toXMLString, toXMLString, toXMLString, toXMLString, toXMLString, writeXML, writeXML, writeXML, writeXML, xmlTag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

id

public Id id

endeffector

private ArrayList<EndEffector> endeffector

keyFrameMUs

private List<KeyframeMU> keyFrameMUs

rotations

private HashMap<String,Rotation> rotations

keyframes

private HashMap<String,Keyframes> keyframes

bodyParts

private Set<VJoint> bodyParts

bodyPartFilter

private Set<String> bodyPartFilter

rootEff

private EndEffector rootEff

rightFootEff

private EndEffector rightFootEff

leftFootEff

private EndEffector leftFootEff

rightHandEff

private EndEffector rightHandEff

leftHandEff

private EndEffector leftHandEff

minDuration

private double minDuration

maxDuration

private double maxDuration

prefDuration

private double prefDuration

parser

private org.lsmp.djep.xjep.XJep parser

tVar

private org.nfunk.jep.Variable tVar

parameters

private ArrayList<ProcAnimationMU.IKParameter> parameters

body

private IKBody body

keyPositionManager

private KeyPositionManager keyPositionManager

lf

private float[] lf

rf

private float[] rf

lh

private float[] lh

rh

private float[] rh

goal

private float[] goal

q

private float[] q

ro

private float[] ro
Constructor Detail

ProcAnimationMU

public ProcAnimationMU()
Constructor

Method Detail

addSkeletonInterpolator

public void addSkeletonInterpolator(SkeletonInterpolator ski)

getControlledJoints

public Set<VJoint> getControlledJoints()
Gets the joints steered with this ProcAnimation


getKeyPosition

public KeyPosition getKeyPosition(String name)
Specified by:
getKeyPosition in interface KeyPositionManager

addKeyPosition

public void addKeyPosition(KeyPosition kp)
Specified by:
addKeyPosition in interface KeyPositionManager

removeKeyPosition

public void removeKeyPosition(String id)
Specified by:
removeKeyPosition in interface KeyPositionManager

getKeyPositions

public List<KeyPosition> getKeyPositions()
Description copied from interface: KeyPositionManager
Gets a sorted view of the list of keypositions

Specified by:
getKeyPositions in interface KeyPositionManager

setKeyPositions

public void setKeyPositions(List<KeyPosition> p)
Specified by:
setKeyPositions in interface KeyPositionManager

mirror

public void mirror()

deepCopy

public ProcAnimationMU deepCopy()
Creates a copy of this ProcAnimation. The copy is not linked to an ikbody


getPreferedDuration

public double getPreferedDuration()
Specified by:
getPreferedDuration in interface MotionUnit
Returns:
Prefered duration (in seconds) of this motion unit, 0 means not determined/infinite

set

public void set(ProcAnimationMU ani)
Sets to ani, copies over all of ani's properties


removeRotation

public void removeRotation(String name)
Removes a rotation


setRotation

public void setRotation(String name,
                        String xForm,
                        String yForm,
                        String zForm)
                 throws org.nfunk.jep.ParseException
Sets a rotation to a certain formula, adds it to the rotation list if it does not exist yet

Parameters:
name - name of the target
xForm - x formula
yForm - y formula
zForm - z formula
Throws:
org.nfunk.jep.ParseException

setEndEffector

public void setEndEffector(String name,
                           String xForm,
                           String yForm,
                           String zForm,
                           String sForm,
                           boolean isLocal)
Sets a end effector to a certain formula, adds it to the endeffector list if it does not exist yet

Parameters:
name - name of the target
xForm - x formula
yForm - y formula
zForm - z formula

setRotations

public void setRotations(HashMap<String,Rotation> rots)
Set the rotations

Parameters:
rotations - The rotations to set.

setParameterValue

public void setParameterValue(String sid,
                              float value)
Sets the parameter value for parameter sid. Ignores parameter sids that are not used in this ProcAnimation.

Specified by:
setParameterValue in interface MotionUnit

setKeyframes

public void setKeyframes(HashMap<String,Keyframes> frs)
Set the keyframes to frs


setRotations

public void setRotations(ProcAnimationMU ik)
Copies the rotations from another ProcAnimation Rotations that occur in ik but not in this ProcAnimation are ignored

Parameters:
ik - the IKAnimation to copy from

setParameterValues

private void setParameterValues()

setParameters

public void setParameters(Collection<Parameter> ps)
Sets the parameters the parameters in ps, retaining the 'old' parameters that not are part of ps

Parameters:
parameters - - the list of parameters to set

getIKParameter

private ProcAnimationMU.IKParameter getIKParameter(String paramId)

addKeyframes

public void addKeyframes(Keyframes kf)
Adds a keyframe


addParameter

public void addParameter(Parameter p)
Adds a parameter


setEffectors

public void setEffectors(ProcAnimationMU ik)
Set the endeffectors of another ProcAnimation into this animation. EndEffectors that occur only in ik are ignored.


setEndEffectors

public void setEndEffectors(ArrayList<EndEffector> newEndEffectors)
Set a new set of EndEffectors

Parameters:
the - new list of EndEffectors

getEndEffector

public EndEffector getEndEffector(String target)
Get the EndEffector with sid target

Parameters:
target - the sid of the endeffector to obtain
Returns:
the endeffector, null if not found

getAllEndEffectors

public List<EndEffector> getAllEndEffectors()
Returns the complete arraylist with EndEffectors

Returns:
the EndEffectors

addEndEffector

public void addEndEffector(EndEffector eff)
Adds an endeffector

Parameters:
eff - endeffector to add

removeEndEffector

public void removeEndEffector(String name)
Removes all endeffectors with target name

Parameters:
name - the target

getRotations

public HashMap<String,Rotation> getRotations()
Returns:
Returns the rotations.

getRotation

public Rotation getRotation(String target)
Returns the Rotation of the given target

Parameters:
the - target
Returns:
the rotation.

getPositions

public void getPositions(float[] lf,
                         float[] rf,
                         float[] lh,
                         float[] rh,
                         float[] root,
                         double[] swivels)
Get the current endeffector IK info

Parameters:
lf - output: left foot vector
rf - output: right foot position
lh - output: left hand position
rh - output: right hand position
root - output: root position
swivels - output: swivel rotations of respectively left foot, rightfoot, lefthand, right hand

getParameters

public Collection<Parameter> getParameters()
Gets the parameters

Returns:
the parameters

setupEndEffectors

private void setupEndEffectors()

setup

public void setup(Collection<Parameter> params,
                  IKBody b)
Links the ProcAnimation to a body and a set of parameters Filters out the joints to animate based on the set Rotations, end effectors, keyframes and skeletoninterpolators


filterBodyParts

private void filterBodyParts()

findMissingParameters

private void findMissingParameters()

containsOnlyLetters

private boolean containsOnlyLetters(String str)
Checks if the given String only contains letters


isConstantParameter

private boolean isConstantParameter(String str)

parameterExists

private boolean parameterExists(String str)
Checks if a parameter exists with the given name


play

private void play(double t,
                  VJoint v)

play

public void play(double t)
Play the IKAnimation at time 0 < t < 1 First plays all skeletoninterpolators, then sets the joints starting at the root as specified by IK and keyframes

Specified by:
play in interface MotionUnit
Parameters:
t - 0 <= t <= 1 the time position

getMaxDuration

public double getMaxDuration()
Returns:
Returns the maxDuration in seconds

setMaxDuration

public void setMaxDuration(double maxDuration)
Parameters:
maxDuration - The new maxDuration in seconds

getMinDuration

public double getMinDuration()
Returns:
Returns the minDuration in seconds

setMinDuration

public void setMinDuration(double minDuration)
Parameters:
minDuration - The minDuration to set, in seconds

getPrefDuration

public double getPrefDuration()
Returns:
Returns the prefered duration (in seconds) of this ProcAnimation

setPrefDuration

public void setPrefDuration(double prefDuration)
Parameters:
prefDuration - the prefered duration (in seconds) of this ProcAnimation

toString

public String toString()
Get the id string

Overrides:
toString in class XMLStructureAdapter

setupParser

private void setupParser()

getLeftFootEff

public EndEffector getLeftFootEff()
Returns:
the left foot endeffector, null if not used

getLeftHandEff

public EndEffector getLeftHandEff()
Returns:
the left hand endeffector, null if not used

getRightFootEff

public EndEffector getRightFootEff()
Returns:
the right foot endeffector, null if not used

getRightHandEff

public EndEffector getRightHandEff()
Returns:
the right hand endeffector, null if not used

getRootEff

public EndEffector getRootEff()
Returns:
the root end effector, null if not used

copy

public MotionUnit copy(AnimationPlayer p)
Description copied from interface: MotionUnit
Create a copy of this motion unit and link it to the animationplayer

Specified by:
copy in interface MotionUnit

copy

public MotionUnit copy(VJoint v)
Creates a copy of this ProcAnimation and links is to VJoint v


getPredictor

public MotionUnit getPredictor(VJoint predict)
Creates a copy of this ProcAnimation, but links the parameters of the copy directly to this animation.

Specified by:
getPredictor in interface MotionUnit
Parameters:
predict - VJoint to execute the prediction on
Returns:
predictor motion unit

decodeAttribute

public boolean decodeAttribute(String attrName,
                               String attrValue)
Description copied from class: XMLStructureAdapter
decodes the value from an attribute value String returns true if succesful, returns false for attribute names that are not recognized. Might throw a RuntimeException when an attribute has been recognized, but is ill formatted. MUST BE OVERWRITTEN BY IMPLEMENTATIONS.

Overrides:
decodeAttribute in class XMLStructureAdapter

decodeAttribute

public boolean decodeAttribute(String attrName,
                               String attrValue,
                               XMLTokenizer tokenizer)
Description copied from class: XMLStructureAdapter
decodes the value from an attribute value String returns true if succesful, returns false for attribute names that are not recognized. Might throw a RuntimeException when an attribute has been recognized, but is ill formatted. Moreover, an XMLTokenizer reference is available which can be queried for attributes, like getTokenLine() or getTokenCharPos(), which might be helpful to produce error messages referring to lines/positions within the XML document The default implementation simply calls decodeAttribute(attrName, attrValue) SHOUL BE OVERWRITTEN BY IMPLEMENTATIONS.

Overrides:
decodeAttribute in class XMLStructureAdapter

decodeContent

public void decodeContent(XMLTokenizer tokenizer)
                   throws IOException
Description copied from class: XMLStructureAdapter
decodes the XML contents, i.e. the XML between the STag and ETag of the encoding. MUST BE OVERWRITTEN BY IMPLEMENTATIONS.

Overrides:
decodeContent in class XMLStructureAdapter
Throws:
IOException

appendContent

public StringBuilder appendContent(StringBuilder buf,
                                   XMLFormatting fmt)
Description copied from class: XMLStructureAdapter
Appends a String to buf that encodes the contents for the XML encoding. MUST BE OVERWRITTEN BY IMPLEMENTATIONS. (The default implementation appends nothing). The encoding should start on a new line, using indentation equal to tab. There should be no newline after the encoding.

Overrides:
appendContent in class XMLStructureAdapter

appendAttributeString

public StringBuilder appendAttributeString(StringBuilder buf)
Description copied from class: XMLStructureAdapter
Appends a String to buf that encodes the attributes for the XML encoding. When non empty, the attribute string should start with a space character. Hint: call the appendAttribute(StringBuilder buf, String attrName, String attrValue) for every relevant attribute; this takes care of the leading space as well as spaces in between the attributes) MUST BE OVERWRITTEN BY IMPLEMENTATIONS. (The default implementation appends nothing). The encoding should preferably not add newline characters.

Overrides:
appendAttributeString in class XMLStructureAdapter

getXMLTag

public String getXMLTag()
Description copied from class: XMLStructureAdapter
returns the XML tag that is used to encode this type of XMLStructure. The default returns null.

Specified by:
getXMLTag in interface XMLStructure
Overrides:
getXMLTag in class XMLStructureAdapter

setParameterValue

public void setParameterValue(String name,
                              String value)
Specified by:
setParameterValue in interface MotionUnit

getParameterValue

public String getParameterValue(String name)
Specified by:
getParameterValue in interface MotionUnit

createTMU

public TimedMotionUnit createTMU(BMLBlockPeg bbPeg,
                                 String i,
                                 String bmlId)
Description copied from interface: MotionUnit
Creates the TimedMotionUnit corresponding to this motion unit

Specified by:
createTMU in interface MotionUnit
i - behaviour id
bmlId - BML block id
Returns:
the TMU

getReplacementGroup

public String getReplacementGroup()
Description copied from interface: MotionUnit
Get the motionunit replacement group (=typically the BML behavior) Used to determine the currently active persistent TMU for this group in the player Only one group is active at a time

Specified by:
getReplacementGroup in interface MotionUnit