Skip to content

Commit 8560c20

Browse files
authored
com.jme3.anim.tween.action.BaseAction: basic javadoc (#2020)
Provides basic JavaDoc for the class com.jme3.anim.tween.action.BaseAction.
1 parent e4a0da8 commit 8560c20

File tree

1 file changed

+60
-15
lines changed

1 file changed

+60
-15
lines changed

jme3-core/src/main/java/com/jme3/anim/tween/action/BaseAction.java

+60-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2022 jMonkeyEngine
2+
* Copyright (c) 2009-2024 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -35,14 +35,40 @@
3535
import com.jme3.anim.tween.ContainsTweens;
3636
import com.jme3.anim.tween.Tween;
3737
import com.jme3.util.SafeArrayList;
38-
3938
import java.util.List;
4039

40+
/**
41+
* A simple implementation for the abstract class {@link Action} to provide a wrapper for a {@link Tween}.
42+
* Internally, it is used as a helper class for {@link Action} to extract and gather actions from a tween and interpolate it.
43+
* <p>
44+
* An example showing two clip actions running in parallel at 2x of their ordinary speed
45+
* by the help of BaseAction on a new Animation Layer :
46+
* <pre class="prettyprint">
47+
* //create a base action from a tween.
48+
* final BaseAction action = new BaseAction(Tweens.parallel(clipAction0, clipAction1));
49+
* //set the action properties - utilized within the #{@link Action} class.
50+
* baseAction.setSpeed(2f);
51+
* //register the action as an observer to the animComposer control.
52+
* animComposer.addAction("basicAction", action);
53+
* //make a new Layer for a basic armature mask
54+
* animComposer.makeLayer(ActionState.class.getSimpleName(), new ArmatureMask());
55+
* //run the action within this layer
56+
* animComposer.setCurrentAction("basicAction", ActionState.class.getSimpleName());
57+
* </pre>
58+
* </p>
59+
* Created by Nehon.
60+
*/
4161
public class BaseAction extends Action {
4262

4363
final private Tween tween;
4464
private boolean maskPropagationEnabled = true;
4565

66+
/**
67+
* Instantiates an action from a tween by extracting the actions from a tween
68+
* to a list of sub-actions to be interpolated later.
69+
*
70+
* @param tween a tween to extract the actions from (not null).
71+
*/
4672
public BaseAction(Tween tween) {
4773
this.tween = tween;
4874
setLength(tween.getLength());
@@ -52,33 +78,35 @@ public BaseAction(Tween tween) {
5278
subActions.toArray(actions);
5379
}
5480

55-
private void gatherActions(Tween tween, List<Action> subActions) {
56-
if (tween instanceof Action) {
57-
subActions.add((Action) tween);
58-
} else if (tween instanceof ContainsTweens) {
59-
Tween[] tweens = ((ContainsTweens) tween).getTweens();
60-
for (Tween t : tweens) {
61-
gatherActions(t, subActions);
62-
}
63-
}
64-
}
65-
6681
/**
67-
* @return true if mask propagation to child actions is enabled else returns false
82+
* Tests whether the animation mask is applied to the wrapped actions {@link BaseAction#actions}.
83+
*
84+
* @return true if mask propagation to child actions is enabled else returns false.
6885
*/
6986
public boolean isMaskPropagationEnabled() {
7087
return maskPropagationEnabled;
7188
}
7289

7390
/**
91+
* Determines whether to apply the animation mask to the wrapped or child actions {@link BaseAction#actions}.
7492
*
7593
* @param maskPropagationEnabled If true, then mask set by AnimLayer will be
76-
* forwarded to all child actions (Default=true)
94+
* forwarded to all child actions (Default=true).
7795
*/
7896
public void setMaskPropagationEnabled(boolean maskPropagationEnabled) {
7997
this.maskPropagationEnabled = maskPropagationEnabled;
8098
}
8199

100+
/**
101+
* Sets the animation mask which determines which part of the model will
102+
* be animated by the animation layer. If the {@link BaseAction#isMaskPropagationEnabled()} is false, setting
103+
* the mask attribute will not affect the actions under this base action. Setting this to 'null' will animate
104+
* the entire model.
105+
*
106+
* @param mask an animation mask to be applied to this action (nullable).
107+
* @see com.jme3.anim.AnimLayer to adjust the animation mask to control which part will be animated
108+
* @see BaseAction#setMaskPropagationEnabled(boolean)
109+
*/
82110
@Override
83111
public void setMask(AnimationMask mask) {
84112
super.setMask(mask);
@@ -94,4 +122,21 @@ public void setMask(AnimationMask mask) {
94122
public boolean interpolate(double t) {
95123
return tween.interpolate(t);
96124
}
125+
126+
/**
127+
* Extracts the actions from a tween into a list.
128+
*
129+
* @param tween the tween to extract the actions from (not null).
130+
* @param subActions a collection to gather the extracted actions (not null).
131+
*/
132+
private void gatherActions(Tween tween, List<Action> subActions) {
133+
if (tween instanceof Action) {
134+
subActions.add((Action) tween);
135+
} else if (tween instanceof ContainsTweens) {
136+
Tween[] tweens = ((ContainsTweens) tween).getTweens();
137+
for (Tween t : tweens) {
138+
gatherActions(t, subActions);
139+
}
140+
}
141+
}
97142
}

0 commit comments

Comments
 (0)