AnimationControl Null pointer exception

I have no idea why it breaks. The model is a simple box ( 4 vertices) skinned to a dummy (my bone) in 3dsMax. See the xml exported below.



Also, can someone explain me why weaponModel has to be a Node? What is the difference if i use Spatial instead?



[java]

weaponModel = (Node) assetManager.loadModel("Models\weapon.mesh.xml");

mat = new Material( assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");

mat.setTexture("m_ColorMap", texture[2] );

//weaponModel.setMaterial(mat);

weaponModel.scale(0.01f);

weaponModel.setLocalTranslation(0, 3, 0);

weaponModel.setName("Weapon Model");

weaponModel.setLocalRotation(YAW180);

node.attachChild(weaponModel);



control = weaponModel.getControl(AnimControl.class);

if (control == null){

System.out.println("Control null again");

break;

}

control.addListener(this);

channel = control.createChannel();

channel.setAnim("idle");

break;

[/java]

[xml]

<?xml version="1.0"?>

<skeleton>

<bones>

<bone id="0" name="weaponBone" >

<position x="99.566597" y="13.682031" z="-94.615273" />

<rotation angle="-1.181600">

<axis x="0.879972" y="-0.049091" z="-0.472482" />

</rotation>

</bone>

</bones>

<bonehierarchy>

</bonehierarchy>

<animations>

<animation name="idle" length="2.000000">

<tracks>

<track bone="weaponBone">

<keyframes>

<keyframe time="0.000000">

<translate x="0.000000" y="-108.297302" z="80.933243" />

<rotate angle="-0.000000">

<axis x="0.000000" y="0.000000" z="0.000000" />

</rotate>

</keyframe>

<keyframe time="2.000000">

<translate x="0.000000" y="-108.297302" z="80.933243" />

<rotate angle="-0.000000">

<axis x="0.000000" y="0.000000" z="0.000000" />

</rotate>

</keyframe>

</keyframes>

</track>

</tracks>

</animation>

</animations>

</skeleton>

[/xml]

just an idea, can you try getting the anim control before attaching to parent node?

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/animcontrol-addlisterner-gives-null-exception-tho-im-sure-the-object-isnt-null/

Dont remember how I fixed it, but heres the post about the same problem.

@cghislai just tried it, still the same error.



@Addez i’ve read your thread and it ends in “the problem is probably in your code” hehe

Make sure the skeleton.xml file is actually loaded, remember that it doesn’t have to be the same name as the model. In the mesh.xml there’s a specific reference for it like so make sure you have the proper name for your skeleton file

@Momoko_Fan : It is…





[xml]

<?xml version=“1.0”?>

<mesh>

<submeshes>

<submesh material=“01_-_Default” usesharedvertices=“false” use32bitindexes=“0”>

<faces count=“12”>

<face v1=“0” v2=“2” v3=“3” />

<face v1=“3” v2=“1” v3=“0” />

<face v1=“4” v2=“5” v3=“7” />

<face v1=“7” v2=“6” v3=“4” />

<face v1=“0” v2=“1” v3=“5” />

<face v1=“5” v2=“4” v3=“0” />

<face v1=“1” v2=“3” v3=“7” />

<face v1=“7” v2=“5” v3=“1” />

<face v1=“3” v2=“2” v3=“6” />

<face v1=“6” v2=“7” v3=“3” />

<face v1=“2” v2=“0” v3=“4” />

<face v1=“4” v2=“6” v3=“2” />

</faces>

<geometry vertexcount=“8”>

<vertexbuffer positions=“true” normals=“true” colours_diffuse=“false” texture_coords=“1” texture_coords_dimensions_0=“2”>

<vertex>

<position x=“92.267853” y="-75.558441" z=“2.616425” />

<normal x=“0.333933” y="-0.813637" z=“1.301494” />

<texcoord u=“1.000000” v=“1.000000” />

</vertex>

<vertex>

<position x=“115.203735” y="-83.651024" z="-8.327513" />

<normal x=“0.333933” y="-0.813637" z=“1.301493” />

<texcoord u=“0.000000” v=“1.000000” />

</vertex>

<vertex>

<position x=“79.396843” y="-97.745598" z="-7.951601" />

<normal x=“0.333933” y="-0.813636" z=“1.301493” />

<texcoord u=“1.000000” v=“0.000000” />

</vertex>

<vertex>

<position x=“102.332733” y="-105.838188" z="-18.895554" />

<normal x=“0.333933” y="-0.813637" z=“1.301494” />

<texcoord u=“0.000000” v=“0.000000” />

</vertex>

<vertex>

<position x=“57.537460” y=“9.062857” z="-132.743683" />

<normal x="-0.333933" y=“0.813637” z="-1.301494" />

<texcoord u=“0.000000” v=“1.000000” />

</vertex>

<vertex>

<position x=“80.473358” y=“0.970268” z="-143.687637" />

<normal x="-0.333933" y=“0.813636” z="-1.301493" />

<texcoord u=“1.000000” v=“1.000000” />

</vertex>

<vertex>

<position x=“44.666420” y="-13.124321" z="-143.311722" />

<normal x="-0.333933" y=“0.813636” z="-1.301492" />

<texcoord u=“0.000000” v=“0.000000” />

</vertex>

<vertex>

<position x=“67.602325” y="-21.216909" z="-154.255661" />

<normal x="-0.333933" y=“0.813637” z="-1.301494" />

<texcoord u=“1.000000” v=“0.000000” />

</vertex>

</vertexbuffer>

</geometry>

<boneassignments>

<vertexboneassignment vertexindex=“0” boneindex=“0” weight=“1.000000” />

<vertexboneassignment vertexindex=“1” boneindex=“0” weight=“1.000000” />

<vertexboneassignment vertexindex=“2” boneindex=“0” weight=“1.000000” />

<vertexboneassignment vertexindex=“3” boneindex=“0” weight=“1.000000” />

<vertexboneassignment vertexindex=“4” boneindex=“0” weight=“1.000000” />

<vertexboneassignment vertexindex=“5” boneindex=“0” weight=“1.000000” />

<vertexboneassignment vertexindex=“6” boneindex=“0” weight=“1.000000” />

<vertexboneassignment vertexindex=“7” boneindex=“0” weight=“1.000000” />

</boneassignments>

</submesh>

</submeshes>

<skeletonlink name=“weapon.skeleton” />

<submeshnames>

<submeshname name=“Stick” index=“0” />

</submeshnames>

</mesh>



[/xml]

Is there some kind of nomenclature im unaware of? Like does the mesh HAS to have the same name as the filename, for example, maybe?



Also, weaponModel.getNumControls() returns 0…



So, i changed weaponModel to Spatial instead of Node, did this:



[java]weaponModel.addControl(new AnimControl());[/java]



But now, i have an NPE right here:

[java]

channel = control.createChannel();

[/java]



Gives me:

[java]

2011-01-12 14:50:23 com.jme3.app.Application handleError

GRAVE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.animation.AnimControl.resetToBind(AnimControl.java:322)

at com.jme3.animation.AnimControl.controlUpdate(AnimControl.java:372)

at com.jme3.scene.control.AbstractControl.update(AbstractControl.java:88)

at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:502)

at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:619)

at com.jme3.scene.Node.updateLogicalState(Node.java:150)

at com.jme3.scene.Node.updateLogicalState(Node.java:153)

at com.jme3.scene.Node.updateLogicalState(Node.java:153)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:209)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:141)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)

at java.lang.Thread.run(Thread.java:619)

Java Result: -1073741819

[/java]



Seems i have a similar problem to that other guy in that thread:

http://hub.jmonkeyengine.org/groups/import-assets/forum/topic/npe-in-animcontrol-resettobind/

Since you gave me the two files, I can now check this issue myself.

I created a file called Modelsweapon.mesh.xml, and pasted the data you gave me, I created a weapon.skeleton.xml and pasted the other data which you included in the first post. I placed the two files in the same directory, and loaded Modelsweapon.mesh.xml, I was able to retrieve the AnimControl from the model: