1
1
/*
2
- * Copyright (c) 2009-2022 jMonkeyEngine
2
+ * Copyright (c) 2009-2024 jMonkeyEngine
3
3
* All rights reserved.
4
4
*
5
5
* Redistribution and use in source and binary forms, with or without
35
35
import com .jme3 .anim .tween .ContainsTweens ;
36
36
import com .jme3 .anim .tween .Tween ;
37
37
import com .jme3 .util .SafeArrayList ;
38
-
39
38
import java .util .List ;
40
39
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
+ */
41
61
public class BaseAction extends Action {
42
62
43
63
final private Tween tween ;
44
64
private boolean maskPropagationEnabled = true ;
45
65
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
+ */
46
72
public BaseAction (Tween tween ) {
47
73
this .tween = tween ;
48
74
setLength (tween .getLength ());
@@ -52,33 +78,35 @@ public BaseAction(Tween tween) {
52
78
subActions .toArray (actions );
53
79
}
54
80
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
-
66
81
/**
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.
68
85
*/
69
86
public boolean isMaskPropagationEnabled () {
70
87
return maskPropagationEnabled ;
71
88
}
72
89
73
90
/**
91
+ * Determines whether to apply the animation mask to the wrapped or child actions {@link BaseAction#actions}.
74
92
*
75
93
* @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).
77
95
*/
78
96
public void setMaskPropagationEnabled (boolean maskPropagationEnabled ) {
79
97
this .maskPropagationEnabled = maskPropagationEnabled ;
80
98
}
81
99
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
+ */
82
110
@ Override
83
111
public void setMask (AnimationMask mask ) {
84
112
super .setMask (mask );
@@ -94,4 +122,21 @@ public void setMask(AnimationMask mask) {
94
122
public boolean interpolate (double t ) {
95
123
return tween .interpolate (t );
96
124
}
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
+ }
97
142
}
0 commit comments