|
@@ -31,11 +31,12 @@
|
|
*/
|
|
*/
|
|
package jme3test.model.anim;
|
|
package jme3test.model.anim;
|
|
|
|
|
|
-import com.jme3.animation.AnimChannel;
|
|
|
|
-import com.jme3.animation.AnimControl;
|
|
|
|
-import com.jme3.animation.AnimEventListener;
|
|
|
|
-import com.jme3.animation.LoopMode;
|
|
|
|
-import com.jme3.animation.SkeletonControl;
|
|
|
|
|
|
+import com.jme3.anim.AnimComposer;
|
|
|
|
+import com.jme3.anim.SkinningControl;
|
|
|
|
+import com.jme3.anim.tween.Tween;
|
|
|
|
+import com.jme3.anim.tween.Tweens;
|
|
|
|
+import com.jme3.anim.tween.action.Action;
|
|
|
|
+import com.jme3.anim.util.AnimMigrationUtils;
|
|
import com.jme3.app.SimpleApplication;
|
|
import com.jme3.app.SimpleApplication;
|
|
import com.jme3.input.KeyInput;
|
|
import com.jme3.input.KeyInput;
|
|
import com.jme3.input.controls.ActionListener;
|
|
import com.jme3.input.controls.ActionListener;
|
|
@@ -56,15 +57,16 @@ import com.jme3.scene.shape.Box;
|
|
* Derived from {@link jme3test.model.anim.TestOgreAnim}.
|
|
* Derived from {@link jme3test.model.anim.TestOgreAnim}.
|
|
*/
|
|
*/
|
|
public class TestAttachmentsNode extends SimpleApplication
|
|
public class TestAttachmentsNode extends SimpleApplication
|
|
- implements AnimEventListener, ActionListener {
|
|
|
|
|
|
+ implements ActionListener {
|
|
|
|
+
|
|
|
|
+ private Action punchesOnce;
|
|
|
|
+ private AnimComposer control;
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
TestAttachmentsNode app = new TestAttachmentsNode();
|
|
TestAttachmentsNode app = new TestAttachmentsNode();
|
|
app.start();
|
|
app.start();
|
|
}
|
|
}
|
|
|
|
|
|
- private AnimChannel channel;
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void simpleInitApp() {
|
|
public void simpleInitApp() {
|
|
flyCam.setMoveSpeed(10f);
|
|
flyCam.setMoveSpeed(10f);
|
|
@@ -75,23 +77,40 @@ public class TestAttachmentsNode extends SimpleApplication
|
|
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
|
|
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
|
|
dl.setColor(ColorRGBA.White);
|
|
dl.setColor(ColorRGBA.White);
|
|
rootNode.addLight(dl);
|
|
rootNode.addLight(dl);
|
|
-
|
|
|
|
|
|
+ /*
|
|
|
|
+ * Load the Jaime model and convert it
|
|
|
|
+ * from the old animation system to the new one.
|
|
|
|
+ */
|
|
Spatial model = assetManager.loadModel("Models/Jaime/Jaime.j3o");
|
|
Spatial model = assetManager.loadModel("Models/Jaime/Jaime.j3o");
|
|
- AnimControl control = model.getControl(AnimControl.class);
|
|
|
|
- SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
|
|
|
|
|
|
+ model = AnimMigrationUtils.migrate(model);
|
|
|
|
+ /*
|
|
|
|
+ * Play the "Idle" animation at half speed.
|
|
|
|
+ */
|
|
|
|
+ control = model.getControl(AnimComposer.class);
|
|
|
|
+ control.setCurrentAction("Idle");
|
|
|
|
+ control.setGlobalSpeed(0.5f);
|
|
|
|
+ /*
|
|
|
|
+ * Define a "PunchesOnce" action sequence to play the "Punches"
|
|
|
|
+ * animation for one cycle before returning to idle.
|
|
|
|
+ */
|
|
|
|
+ Action punches = control.action("Punches");
|
|
|
|
+ Tween doneTween
|
|
|
|
+ = Tweens.callMethod(control, "setCurrentAction", "Idle");
|
|
|
|
+ punchesOnce = control.actionSequence("PunchesOnce", punches, doneTween);
|
|
|
|
|
|
model.center();
|
|
model.center();
|
|
model.setLocalScale(5f);
|
|
model.setLocalScale(5f);
|
|
|
|
|
|
- control.addListener(this);
|
|
|
|
- channel = control.createChannel();
|
|
|
|
- channel.setAnim("Idle");
|
|
|
|
-
|
|
|
|
Box box = new Box(0.3f, 0.02f, 0.02f);
|
|
Box box = new Box(0.3f, 0.02f, 0.02f);
|
|
Geometry saber = new Geometry("saber", box);
|
|
Geometry saber = new Geometry("saber", box);
|
|
saber.move(0.4f, 0.05f, 0.01f);
|
|
saber.move(0.4f, 0.05f, 0.01f);
|
|
Material red = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
|
|
Material red = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
|
|
saber.setMaterial(red);
|
|
saber.setMaterial(red);
|
|
|
|
+ /*
|
|
|
|
+ * Create an attachments node for Jaime's right hand,
|
|
|
|
+ * and attach the saber to that Node.
|
|
|
|
+ */
|
|
|
|
+ SkinningControl skeletonControl = model.getControl(SkinningControl.class);
|
|
Node n = skeletonControl.getAttachmentsNode("hand.R");
|
|
Node n = skeletonControl.getAttachmentsNode("hand.R");
|
|
n.attachChild(saber);
|
|
n.attachChild(saber);
|
|
rootNode.attachChild(model);
|
|
rootNode.attachChild(model);
|
|
@@ -100,27 +119,11 @@ public class TestAttachmentsNode extends SimpleApplication
|
|
inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
|
|
inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
|
|
|
|
- if (animName.equals("Punches")) {
|
|
|
|
- channel.setAnim("Idle", 0.5f);
|
|
|
|
- channel.setLoopMode(LoopMode.DontLoop);
|
|
|
|
- channel.setSpeed(1f);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void onAction(String binding, boolean value, float tpf) {
|
|
public void onAction(String binding, boolean value, float tpf) {
|
|
- if (binding.equals("Attack") && value) {
|
|
|
|
- if (!channel.getAnimationName().equals("Punches")) {
|
|
|
|
- channel.setAnim("Punches", 0.5f);
|
|
|
|
- channel.setLoopMode(LoopMode.Cycle);
|
|
|
|
- channel.setSpeed(0.5f);
|
|
|
|
- }
|
|
|
|
|
|
+ if (value && binding.equals("Attack")
|
|
|
|
+ && control.getCurrentAction() != punchesOnce) {
|
|
|
|
+ control.setCurrentAction("PunchesOnce");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|