113 lines
4.3 KiB
Java
113 lines
4.3 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.jme3.animation.AnimChannel
|
|
* com.jme3.animation.AnimControl
|
|
* com.jme3.animation.AnimEventListener
|
|
* com.jme3.animation.LoopMode
|
|
* com.jme3.app.SimpleApplication
|
|
* com.jme3.input.controls.ActionListener
|
|
* com.jme3.input.controls.InputListener
|
|
* com.jme3.input.controls.KeyTrigger
|
|
* com.jme3.input.controls.MouseButtonTrigger
|
|
* com.jme3.input.controls.Trigger
|
|
* com.jme3.light.DirectionalLight
|
|
* com.jme3.light.Light
|
|
* com.jme3.material.Material
|
|
* com.jme3.math.ColorRGBA
|
|
* com.jme3.math.Vector3f
|
|
* com.jme3.scene.Node
|
|
* com.jme3.scene.Spatial
|
|
* com.jme3.scene.debug.SkeletonDebugger
|
|
*/
|
|
package jme3.hello;
|
|
|
|
import com.jme3.animation.AnimChannel;
|
|
import com.jme3.animation.AnimControl;
|
|
import com.jme3.animation.AnimEventListener;
|
|
import com.jme3.animation.LoopMode;
|
|
import com.jme3.app.SimpleApplication;
|
|
import com.jme3.input.controls.ActionListener;
|
|
import com.jme3.input.controls.InputListener;
|
|
import com.jme3.input.controls.KeyTrigger;
|
|
import com.jme3.input.controls.MouseButtonTrigger;
|
|
import com.jme3.input.controls.Trigger;
|
|
import com.jme3.light.DirectionalLight;
|
|
import com.jme3.light.Light;
|
|
import com.jme3.material.Material;
|
|
import com.jme3.math.ColorRGBA;
|
|
import com.jme3.math.Vector3f;
|
|
import com.jme3.scene.Node;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.debug.SkeletonDebugger;
|
|
|
|
public class HelloAnimation
|
|
extends SimpleApplication
|
|
implements AnimEventListener {
|
|
private AnimChannel channel;
|
|
private AnimControl control;
|
|
Node player;
|
|
private ActionListener actionListener = new ActionListener(){
|
|
|
|
public void onAction(String name, boolean keyPressed, float tpf) {
|
|
if (name.equals("Walk") && !keyPressed && !HelloAnimation.this.channel.getAnimationName().equals("Walk")) {
|
|
HelloAnimation.this.channel.setAnim("Walk", 0.5f);
|
|
HelloAnimation.this.channel.setLoopMode(LoopMode.Loop);
|
|
}
|
|
if (name.equals("Dodge") && !keyPressed && !HelloAnimation.this.channel.getAnimationName().equals("Push")) {
|
|
HelloAnimation.this.channel.setAnim("push", 1.0f);
|
|
HelloAnimation.this.channel.setLoopMode(LoopMode.DontLoop);
|
|
}
|
|
}
|
|
};
|
|
|
|
public static void main(String[] agrs) {
|
|
HelloAnimation app = new HelloAnimation();
|
|
app.start();
|
|
}
|
|
|
|
public void simpleInitApp() {
|
|
this.viewPort.setBackgroundColor(ColorRGBA.LightGray);
|
|
this.initKeys();
|
|
DirectionalLight dl = new DirectionalLight();
|
|
dl.setDirection(new Vector3f(-0.1f, -1.0f, -1.0f).normalizeLocal());
|
|
this.rootNode.addLight((Light)dl);
|
|
this.player = (Node)this.assetManager.loadModel("Models/Oto/Oto.mesh.xml");
|
|
this.player.setLocalScale(0.5f);
|
|
this.rootNode.attachChild((Spatial)this.player);
|
|
this.control = (AnimControl)this.player.getControl(AnimControl.class);
|
|
this.control.addListener((AnimEventListener)this);
|
|
this.channel = this.control.createChannel();
|
|
this.channel.setAnim("stand");
|
|
SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", this.control.getSkeleton());
|
|
Material mat = new Material(this.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
mat.setColor("Color", ColorRGBA.Green);
|
|
mat.getAdditionalRenderState().setDepthTest(false);
|
|
skeletonDebug.setMaterial(mat);
|
|
this.player.attachChild((Spatial)skeletonDebug);
|
|
}
|
|
|
|
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
|
|
if (animName.equals("Walk")) {
|
|
channel.setAnim("stand", 0.5f);
|
|
channel.setLoopMode(LoopMode.DontLoop);
|
|
channel.setSpeed(1.0f);
|
|
}
|
|
if (animName.equals("push")) {
|
|
channel.setAnim("stand", 1.0f);
|
|
channel.setLoopMode(LoopMode.DontLoop);
|
|
channel.setSpeed(1.0f);
|
|
}
|
|
}
|
|
|
|
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
|
|
}
|
|
|
|
private void initKeys() {
|
|
this.inputManager.addMapping("Walk", new Trigger[]{new KeyTrigger(57)});
|
|
this.inputManager.addMapping("Dodge", new Trigger[]{new MouseButtonTrigger(0)});
|
|
this.inputManager.addListener((InputListener)this.actionListener, new String[]{"Walk", "Dodge"});
|
|
}
|
|
}
|