Jmonkey blender animation sample

tags: .blend, .j3o, blender import, chanel, null pointer exception

package sample;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 * Load and animate blender model jmonkey
 * @author Padaboo I.B. Aleksandrov
 */

public class BlenderModelSample extends SimpleApplication {
    //animation channel
    private AnimChannel channel;
    //animation control
    private AnimControl control;
    public static void main(String[] args) {
    	BlenderModelSample app = new BlenderModelSample();
        app.start();
    }
    @Override
    public void simpleInitApp() {
        //add light
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
        dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
        rootNode.addLight(dl);
        
        //load spatial
        Spatial player = (Spatial) assetManager.loadModel("Models/human.j3o");
        //attach to root node
        player.setMaterial( assetManager.loadMaterial("Materials/humanmaterial.j3m"));
        //add player to child node
        rootNode.attachChild(player);

        //cast to node
        Node playerNode = (Node)player;
        //get child (model scene mesh)
        //tree: human.j3o -> armature -> Plane
        control = playerNode.getChild("Plane").getControl(AnimControl.class);
        //create chanel
        channel = control.createChannel();
        
        //set animation walk
        channel.setAnim("walk");
    }
}

Please provide some log .

I guess the null pointer is at control:

Make sure Node “Plane” has AnimControl on it.

In below example if i want to get control i need to get it from node “Kachujin”. if i get it from other node it will cause null error.

Hub
https://github.com/Padaboo/javasamples/blob/master/src/sample/BlenderModelSample.java

can you upload your model “golova.j3o” to somewhere so i take a look at it ?

ok assets https://github.com/Padaboo/javasamples/tree/master/assets

WOW!!!

Please rename golova.j3o to human.j3o in your code.

Fixed. :smile: