Migrate TestOgreAnim to new anim system (#1333)
* Migrate TestOgreAnim to new anim system * Removing tabs * Update TestOgreAnim.java
This commit is contained in:
parent
d109e4739e
commit
4c8e400a83
@ -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());
|
||||||
|
animComposer.addAction(animClip.getName(), new LoopAction(action, animComposer));
|
||||||
|
}
|
||||||
|
currentAction = (LoopAction) animComposer.setCurrentAction("stand"); // Walk, pull, Dodge, stand, push
|
||||||
|
|
||||||
for (String anim : control.getAnimationNames())
|
SkinningControl skinningControl = model.getControl(SkinningControl.class);
|
||||||
System.out.println(anim);
|
skinningControl.setHardwareSkinningPreferred(false);
|
||||||
|
|
||||||
channel.setAnim("stand");
|
Box b = new Box(.25f, 3f, .25f);
|
||||||
geom = (Geometry)((Node)model).getChild(0);
|
|
||||||
SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
|
|
||||||
|
|
||||||
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);
|
||||||
@ -93,36 +100,48 @@ public class TestOgreAnim extends SimpleApplication
|
|||||||
inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
|
inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void simpleUpdate(float tpf) {
|
|
||||||
super.simpleUpdate(tpf);
|
|
||||||
// geom.getMesh().createCollisionData();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
|
|
||||||
if (animName.equals("Dodge")){
|
|
||||||
channel.setAnim("stand", 0.50f);
|
|
||||||
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 (binding.equals("Attack") && value) {
|
||||||
if (!channel.getAnimationName().equals("Dodge")){
|
if (currentAction != null && !currentAction.equals(animComposer.getAction("Dodge"))) {
|
||||||
channel.setAnim("Dodge", 0.50f);
|
currentAction = (LoopAction) animComposer.setCurrentAction("Dodge");
|
||||||
channel.setLoopMode(LoopMode.Cycle);
|
currentAction.setNextAnim("stand");
|
||||||
channel.setSpeed(0.10f);
|
currentAction.setSpeed(0.1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class LoopAction extends BaseAction {
|
||||||
|
|
||||||
|
final AnimComposer ac;
|
||||||
|
private boolean loop = false;
|
||||||
|
private String nextAnim = null;
|
||||||
|
|
||||||
|
public LoopAction(Tween delegate, AnimComposer ac) {
|
||||||
|
super(delegate);
|
||||||
|
this.ac = ac;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoop(boolean loop) {
|
||||||
|
this.loop = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextAnim(String nextAction) {
|
||||||
|
this.nextAnim = nextAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean interpolate(double t) {
|
||||||
|
boolean running = super.interpolate(t);
|
||||||
|
if (!loop && !running) {
|
||||||
|
setSpeed(0);
|
||||||
|
ac.removeCurrentAction(AnimComposer.DEFAULT_LAYER);
|
||||||
|
if (nextAnim != null && ac.hasAction(nextAnim)) {
|
||||||
|
currentAction = (LoopAction) ac.setCurrentAction(nextAnim);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user