Load jme3 Animation - Java Game

Java examples for Game:JME3

Description

Load jme3 Animation

Demo Code

package IOmethods;

import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

/**//from w  ww  .  jav a2 s.  c  o m
 * test
 *
 * @author normenhansen
 */
public class LoadAnimation extends SimpleApplication {

    public static void main(String[] args) {
        LoadAnimation app = new LoadAnimation();
        app.start();
    }

    private Node FlySnakeCar;
    private AnimControl control;
    private AnimChannel channel;

    private static final String ANI_FLY = "my_animation";

    @Override
    public void simpleInitApp() {
        FlySnakeCar = (Node) assetManager
                .loadModel("Textures/NewAniModel/FlySnakeCar.mesh.xml");
        control = FlySnakeCar.getControl(AnimControl.class);

        for (String anim : control.getAnimationNames()) {
            System.out.println(anim);
        }

        channel = control.createChannel();
        channel.setAnim(ANI_FLY);

        rootNode.attachChild(FlySnakeCar);
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)));
        sun.setColor(ColorRGBA.White);
        rootNode.addLight(sun);
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
}

Related Tutorials