Adding getters/setters to AnimComposer (#1376)

* Add getCurrentAction

* Add removeCurrentAction (default layer)

* Add setTime (default layer)

* Add getTime (default layer)

* Improve documentation
master
René Kraneis 5 years ago committed by GitHub
parent eb7aab9704
commit 32e8b68ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 85
      jme3-core/src/main/java/com/jme3/anim/AnimComposer.java

@ -48,10 +48,16 @@ import java.io.IOException;
import java.util.*; import java.util.*;
/** /**
* Created by Nehon on 20/12/2017. * AnimComposer is a Spatial control that allows manipulation of
* {@link Armature armature} (skeletal) animation.
*
* @author Nehon
*/ */
public class AnimComposer extends AbstractControl { public class AnimComposer extends AbstractControl {
/**
* The name of the default layer.
*/
public static final String DEFAULT_LAYER = "Default"; public static final String DEFAULT_LAYER = "Default";
private Map<String, AnimClip> animClipMap = new HashMap<>(); private Map<String, AnimClip> animClipMap = new HashMap<>();
@ -63,6 +69,12 @@ public class AnimComposer extends AbstractControl {
layers.put(DEFAULT_LAYER, new Layer(this)); layers.put(DEFAULT_LAYER, new Layer(this));
} }
/**
* Tells if an animation is contained in the list of animations.
*
* @param name The name of the animation.
* @return true, if the named animation is in the list of animations.
*/
public boolean hasAnimClip(String name) { public boolean hasAnimClip(String name) {
return animClipMap.containsKey(name); return animClipMap.containsKey(name);
} }
@ -102,6 +114,12 @@ public class AnimComposer extends AbstractControl {
animClipMap.remove(anim.getName()); animClipMap.remove(anim.getName());
} }
/**
* Run an action on the default layer.
*
* @param name The name of the action to run.
* @return The action corresponding to the given name.
*/
public Action setCurrentAction(String name) { public Action setCurrentAction(String name) {
return setCurrentAction(name, DEFAULT_LAYER); return setCurrentAction(name, DEFAULT_LAYER);
} }
@ -125,6 +143,37 @@ public class AnimComposer extends AbstractControl {
return currentAction; return currentAction;
} }
/**
* Return the current action on the default layer.
*
* @return The action corresponding to the given name.
*/
public Action getCurrentAction() {
return getCurrentAction(DEFAULT_LAYER);
}
/**
* Return current action on specified layer.
*
* @param layerName The layer on which action should run.
* @return The action corresponding to the given name.
*/
public Action getCurrentAction(String layerName) {
Layer l = layers.get(layerName);
if (l == null) {
throw new IllegalArgumentException("Unknown layer " + layerName);
}
return l.currentAction;
}
/**
* Remove current action on default layer.
*/
public void removeCurrentAction() {
removeCurrentAction(DEFAULT_LAYER);
}
/** /**
* Remove current action on specified layer. * Remove current action on specified layer.
* *
@ -140,8 +189,19 @@ public class AnimComposer extends AbstractControl {
l.currentAction = null; l.currentAction = null;
} }
/**
* Returns current time of the default layer.
*
* @return The current time.
*/
public double getTime() {
return getTime(DEFAULT_LAYER);
}
/** /**
* Returns current time of the specified layer. * Returns current time of the specified layer.
*
* @param layerName The layer from which to get the time.
*/ */
public double getTime(String layerName) { public double getTime(String layerName) {
Layer l = layers.get(layerName); Layer l = layers.get(layerName);
@ -150,9 +210,16 @@ public class AnimComposer extends AbstractControl {
} }
return l.time; return l.time;
} }
/**
* Sets current time on the default layer.
*/
public void setTime(double time) {
setTime(DEFAULT_LAYER, time);
}
/** /**
* Sets current time on the specified layer. * Sets current time on the specified layer.
*/ */
public void setTime(String layerName, double time) { public void setTime(String layerName, double time) {
Layer l = layers.get(layerName); Layer l = layers.get(layerName);
@ -221,6 +288,12 @@ public class AnimComposer extends AbstractControl {
return action; return action;
} }
/**
* Tells if an action is contained in the list of actions.
*
* @param name The name of the action.
* @return true, if the named action is in the list of actions.
*/
public boolean hasAction(String name) { public boolean hasAction(String name) {
return actions.containsKey(name); return actions.containsKey(name);
} }
@ -250,12 +323,20 @@ public class AnimComposer extends AbstractControl {
layers.remove(name); layers.remove(name);
} }
/**
* Creates an action that will interpolate over an entire sequence
* of tweens in order.
*/
public BaseAction actionSequence(String name, Tween... tweens) { public BaseAction actionSequence(String name, Tween... tweens) {
BaseAction action = new BaseAction(Tweens.sequence(tweens)); BaseAction action = new BaseAction(Tweens.sequence(tweens));
actions.put(name, action); actions.put(name, action);
return action; return action;
} }
/**
* Creates an action that blends the named clips using the given blend
* space.
*/
public BlendAction actionBlended(String name, BlendSpace blendSpace, String... clips) { public BlendAction actionBlended(String name, BlendSpace blendSpace, String... clips) {
BlendableAction[] acts = new BlendableAction[clips.length]; BlendableAction[] acts = new BlendableAction[clips.length];
for (int i = 0; i < acts.length; i++) { for (int i = 0; i < acts.length; i++) {

Loading…
Cancel
Save