I started learning the joint animation thing on jme, and I have a problem. I typed in the following code. The main function is a standard one, and createJointMesh generates a JointMesh that looks like a box with 12 vertices. Vertices 0-3 form a square of 2x2 on the x and z axes, with the center of (0,0,0), and vertices 4-7 and 8-11 form the same square with the centers of (0,4,0) and (0,6,0). You can get my useless Extrusion class from here.
import someboddy.jme.shape.Extrusion;
import com.jme.util.geom.BufferUtils;
import java.nio.*;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.math.Quaternion;
import com.jme.scene.*;
import com.jme.scene.shape.*;
import com.jmex.model.JointMesh;
import com.jmex.model.animation.JointController;
public class JointLearn extends SimpleGame
{
public static void main(String[] args)
{
JointLearn app=new JointLearn();
app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
public JointMesh createJointMesh()
{
FloatBuffer crossSection=BufferUtils.createVector2Buffer(4);
crossSection.rewind();
crossSection.put(-1).put(-1);
crossSection.put(1).put(-1);
crossSection.put(1).put(1);
crossSection.put(-1).put(1);
FloatBuffer spine=BufferUtils.createVector3Buffer(3);
spine.put(0).put(0).put(0);
spine.put(0).put(4).put(0);
spine.put(0).put(6).put(0);
Extrusion e=new Extrusion("Extrusion",crossSection,spine);
e.getLocalTranslation().set(-20,0,0);
JointMesh jm=new JointMesh("JointMesh");
jm.reconstruct(e.getVertexBuffer(),null,null,null,e.getIndexBuffer());
return jm;
}
protected void simpleInitGame()
{
JointMesh jm=createJointMesh();
rootNode.attachChild(jm);
jm.jointIndex=new int[12];
for(int i=0;i<3;++i)
for(int j=0;j<4;++j)
jm.jointIndex[4*i+j]=0;
JointController jc=new JointController(3);
jc.addJointMesh(jm);
jc.parentIndex[0]=-1;
jc.parentIndex[1]=0;
jc.parentIndex[2]=1;
jc.localRefMatrix[0].setTranslation(0,0,0);
jc.localRefMatrix[1].setTranslation(0,4,0);
jc.localRefMatrix[2].setTranslation(0,2,0);
jc.setTranslation(1,0,0,0,0);
jc.setTranslation(1,0.5f,1,0,0);
jc.setTranslation(1,1,0,0,0);
jc.processController();
jm.addController(jc);
}
}
When I run it, I get a null pointer exception. The stack trace looks something like this(I removed the package info):
at JointController.udpateData
at JointController.update
at Spatial.updateWorldData
and so on.
I think I forget a function I need to call, but I have no idea which.
Help?