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");
}
}