Skip to content

Commit 32e8b68

Browse files
authored
Adding getters/setters to AnimComposer (#1376)
* Add getCurrentAction * Add removeCurrentAction (default layer) * Add setTime (default layer) * Add getTime (default layer) * Improve documentation
1 parent eb7aab9 commit 32e8b68

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

jme3-core/src/main/java/com/jme3/anim/AnimComposer.java

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@
4848
import java.util.*;
4949

5050
/**
51-
* Created by Nehon on 20/12/2017.
51+
* AnimComposer is a Spatial control that allows manipulation of
52+
* {@link Armature armature} (skeletal) animation.
53+
*
54+
* @author Nehon
5255
*/
5356
public class AnimComposer extends AbstractControl {
5457

58+
/**
59+
* The name of the default layer.
60+
*/
5561
public static final String DEFAULT_LAYER = "Default";
5662
private Map<String, AnimClip> animClipMap = new HashMap<>();
5763

@@ -63,6 +69,12 @@ public AnimComposer() {
6369
layers.put(DEFAULT_LAYER, new Layer(this));
6470
}
6571

72+
/**
73+
* Tells if an animation is contained in the list of animations.
74+
*
75+
* @param name The name of the animation.
76+
* @return true, if the named animation is in the list of animations.
77+
*/
6678
public boolean hasAnimClip(String name) {
6779
return animClipMap.containsKey(name);
6880
}
@@ -102,6 +114,12 @@ public void removeAnimClip(AnimClip anim) {
102114
animClipMap.remove(anim.getName());
103115
}
104116

117+
/**
118+
* Run an action on the default layer.
119+
*
120+
* @param name The name of the action to run.
121+
* @return The action corresponding to the given name.
122+
*/
105123
public Action setCurrentAction(String name) {
106124
return setCurrentAction(name, DEFAULT_LAYER);
107125
}
@@ -125,6 +143,37 @@ public Action setCurrentAction(String actionName, String layerName) {
125143
return currentAction;
126144
}
127145

146+
/**
147+
* Return the current action on the default layer.
148+
*
149+
* @return The action corresponding to the given name.
150+
*/
151+
public Action getCurrentAction() {
152+
return getCurrentAction(DEFAULT_LAYER);
153+
}
154+
155+
/**
156+
* Return current action on specified layer.
157+
*
158+
* @param layerName The layer on which action should run.
159+
* @return The action corresponding to the given name.
160+
*/
161+
public Action getCurrentAction(String layerName) {
162+
Layer l = layers.get(layerName);
163+
if (l == null) {
164+
throw new IllegalArgumentException("Unknown layer " + layerName);
165+
}
166+
167+
return l.currentAction;
168+
}
169+
170+
/**
171+
* Remove current action on default layer.
172+
*/
173+
public void removeCurrentAction() {
174+
removeCurrentAction(DEFAULT_LAYER);
175+
}
176+
128177
/**
129178
* Remove current action on specified layer.
130179
*
@@ -140,8 +189,19 @@ public void removeCurrentAction(String layerName) {
140189
l.currentAction = null;
141190
}
142191

192+
/**
193+
* Returns current time of the default layer.
194+
*
195+
* @return The current time.
196+
*/
197+
public double getTime() {
198+
return getTime(DEFAULT_LAYER);
199+
}
200+
143201
/**
144202
* Returns current time of the specified layer.
203+
*
204+
* @param layerName The layer from which to get the time.
145205
*/
146206
public double getTime(String layerName) {
147207
Layer l = layers.get(layerName);
@@ -150,9 +210,16 @@ public double getTime(String layerName) {
150210
}
151211
return l.time;
152212
}
213+
214+
/**
215+
* Sets current time on the default layer.
216+
*/
217+
public void setTime(double time) {
218+
setTime(DEFAULT_LAYER, time);
219+
}
153220

154221
/**
155-
* Sets current time on the specified layer.
222+
* Sets current time on the specified layer.
156223
*/
157224
public void setTime(String layerName, double time) {
158225
Layer l = layers.get(layerName);
@@ -221,6 +288,12 @@ public Action makeAction(String name) {
221288
return action;
222289
}
223290

291+
/**
292+
* Tells if an action is contained in the list of actions.
293+
*
294+
* @param name The name of the action.
295+
* @return true, if the named action is in the list of actions.
296+
*/
224297
public boolean hasAction(String name) {
225298
return actions.containsKey(name);
226299
}
@@ -250,12 +323,20 @@ public void removeLayer(String name) {
250323
layers.remove(name);
251324
}
252325

326+
/**
327+
* Creates an action that will interpolate over an entire sequence
328+
* of tweens in order.
329+
*/
253330
public BaseAction actionSequence(String name, Tween... tweens) {
254331
BaseAction action = new BaseAction(Tweens.sequence(tweens));
255332
actions.put(name, action);
256333
return action;
257334
}
258335

336+
/**
337+
* Creates an action that blends the named clips using the given blend
338+
* space.
339+
*/
259340
public BlendAction actionBlended(String name, BlendSpace blendSpace, String... clips) {
260341
BlendableAction[] acts = new BlendableAction[clips.length];
261342
for (int i = 0; i < acts.length; i++) {

0 commit comments

Comments
 (0)