Migrate TestOgreAnim to new anim system (#1333)

* Migrate TestOgreAnim to new anim system

* Removing tabs

* Update TestOgreAnim.java
master
Jérôme 5 years ago committed by GitHub
parent d109e4739e
commit 4c8e400a83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 95
      jme3-examples/src/main/java/jme3test/model/anim/TestOgreAnim.java

@ -32,23 +32,30 @@
package jme3test.model.anim; package jme3test.model.anim;
import com.jme3.animation.*; import com.jme3.anim.AnimClip;
import com.jme3.anim.AnimComposer;
import com.jme3.anim.SkinningControl;
import com.jme3.anim.tween.Tween;
import com.jme3.anim.tween.action.Action;
import com.jme3.anim.tween.action.BaseAction;
import com.jme3.anim.tween.action.LinearBlendSpace;
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;
import com.jme3.input.controls.KeyTrigger; import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight; import com.jme3.light.DirectionalLight;
import com.jme3.math.*; import com.jme3.math.ColorRGBA;
import com.jme3.scene.*; import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box; import com.jme3.scene.shape.Box;
//TODO rework this Test when the new animation system is done. public class TestOgreAnim extends SimpleApplication implements ActionListener {
public class TestOgreAnim extends SimpleApplication
implements AnimEventListener, ActionListener {
private AnimChannel channel; private AnimComposer animComposer;
private AnimControl control; private static LoopAction currentAction;
private Geometry geom;
public static void main(String[] args) { public static void main(String[] args) {
TestOgreAnim app = new TestOgreAnim(); TestOgreAnim app = new TestOgreAnim();
@ -66,25 +73,25 @@ public class TestOgreAnim extends SimpleApplication
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f)); dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl); rootNode.addLight(dl);
Spatial model = assetManager.loadModel("Models/Oto/OtoOldAnim.j3o"); Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
model.center(); model.center();
control = model.getControl(AnimControl.class); animComposer = model.getControl(AnimComposer.class);
control.addListener(this); animComposer.actionBlended("Attack", new LinearBlendSpace(0f, 0.5f), "Dodge");
channel = control.createChannel(); for (AnimClip animClip : animComposer.getAnimClips()) {
Action action = animComposer.action(animClip.getName());
for (String anim : control.getAnimationNames()) animComposer.addAction(animClip.getName(), new LoopAction(action, animComposer));
System.out.println(anim); }
currentAction = (LoopAction) animComposer.setCurrentAction("stand"); // Walk, pull, Dodge, stand, push
channel.setAnim("stand"); SkinningControl skinningControl = model.getControl(SkinningControl.class);
geom = (Geometry)((Node)model).getChild(0); skinningControl.setHardwareSkinningPreferred(false);
SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
Box b = new Box(.25f, 3f, .25f); Box b = new Box(.25f, 3f, .25f);
Geometry item = new Geometry("Item", b); Geometry item = new Geometry("Item", b);
item.move(0, 1.5f, 0); item.move(0, 1.5f, 0);
item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m")); item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
Node n = skeletonControl.getAttachmentsNode("hand.right"); Node n = skinningControl.getAttachmentsNode("hand.right");
n.attachChild(item); n.attachChild(item);
rootNode.attachChild(model); rootNode.attachChild(model);
@ -94,35 +101,47 @@ public class TestOgreAnim extends SimpleApplication
} }
@Override @Override
public void simpleUpdate(float tpf) { public void onAction(String binding, boolean value, float tpf) {
super.simpleUpdate(tpf); if (binding.equals("Attack") && value) {
// geom.getMesh().createCollisionData(); if (currentAction != null && !currentAction.equals(animComposer.getAction("Dodge"))) {
currentAction = (LoopAction) animComposer.setCurrentAction("Dodge");
currentAction.setNextAnim("stand");
currentAction.setSpeed(0.1f);
}
}
} }
static class LoopAction extends BaseAction {
@Override final AnimComposer ac;
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) { private boolean loop = false;
if (animName.equals("Dodge")){ private String nextAnim = null;
channel.setAnim("stand", 0.50f);
channel.setLoopMode(LoopMode.DontLoop); public LoopAction(Tween delegate, AnimComposer ac) {
channel.setSpeed(1f); super(delegate);
this.ac = ac;
} }
public void setLoop(boolean loop) {
this.loop = loop;
} }
@Override public void setNextAnim(String nextAction) {
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) { this.nextAnim = nextAction;
} }
@Override @Override
public void onAction(String binding, boolean value, float tpf) { public boolean interpolate(double t) {
if (binding.equals("Attack") && value){ boolean running = super.interpolate(t);
if (!channel.getAnimationName().equals("Dodge")){ if (!loop && !running) {
channel.setAnim("Dodge", 0.50f); setSpeed(0);
channel.setLoopMode(LoopMode.Cycle); ac.removeCurrentAction(AnimComposer.DEFAULT_LAYER);
channel.setSpeed(0.10f); if (nextAnim != null && ac.hasAction(nextAnim)) {
currentAction = (LoopAction) ac.setCurrentAction(nextAnim);
} }
} }
return running;
} }
} }
}

Loading…
Cancel
Save