Jme3D alpha-svn - import blender file with skeleton -> NPE

Using git-head (3.1-alpha-svn) code for importing blender model (or converting to j3o via context menu) causes an exception.
The exception stacktrace:

[java]
SEVERE [org.openide.util.Exceptions]
java.lang.NullPointerException
at com.jme3.animation.SkeletonControl.cloneForSpatial(SkeletonControl.java:378)
at com.jme3.scene.Spatial.clone(Spatial.java:1185)
at com.jme3.scene.Node.clone(Node.java:565)
at com.jme3.scene.Node.clone(Node.java:60)
at com.jme3.scene.Spatial.clone(Spatial.java:1172)
at com.jme3.scene.Node.clone(Node.java:565)
at com.jme3.scene.Node.clone(Node.java:60)
at com.jme3.scene.Spatial.clone(Spatial.java:1172)
at com.jme3.scene.Node.clone(Node.java:565)
at com.jme3.scene.Node.clone(Node.java:60)
at com.jme3.scene.Spatial.clone(Spatial.java:1214)
at com.jme3.scene.Spatial.clone(Spatial.java:66)
at com.jme3.asset.CloneableAssetProcessor.createClone(CloneableAssetProcessor.java:48)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:327)
at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:374)
[catch] at com.jme3.gde.core.assets.SpatialAssetDataObject.loadAsset(SpatialAssetDataObject.java:94)
at com.jme3.gde.core.assets.actions.ConvertModel$1.run(ConvertModel.java:60)
at java.lang.Thread.run(Thread.java:745)
[/java]

When using 3.0 stable (code from googlecode svn (branches/3.0final) import finishes successfully.
When using 3.x (code from googlecode svn trunk) -> the same error;
When using head from git -> the same error;

The blender file has to have an armature parented to mesh.

When looking at the SkeletonControl code the code is looking for an AnimControl object in cloned spatial, which has got none (none was cloned during clone spatial?). The code for Spatial (just above in callstack) iterates through spatial Controls (which are available) and run cloneForSpatial on new Spatial.

[java]
AnimControl ctrl = spatial.getControl(AnimControl.class);
SkeletonControl clone = new SkeletonControl();
clone.skeleton = ctrl.getSkeleton(); // !!!NPE!!!
[/java]

It seems that cloning does not copy the control classes or something other happened. I haven’t found simple and easy solution for this error and thus reporting it here. I still will try to find a fix.

I have tried many blender files, but for example the error occurs also in SimpleAnimation.blend from jme3-testdata.

I had that error in one of my files as well, but yeah we should really make sure somehow taht the example stuff does work :confused:

Looking at the AnimControl class and changing appropriate code in SkeletonControl

from
[java]
AnimControl ctrl = spatial.getControl(AnimControl.class);
SkeletonControl clone = new SkeletonControl();
clone.skeleton = ctrl.getSkeleton();
[/java]

to
[java]
if (skeleton != null) {
clone.skeleton = new Skeleton(skeleton);
}
[/java]

seems to fix the issue. Models import directly from blender successfully.

Somehow (not sure why) there has to be animation control associated with the spatial to successful clone. Models that are exported through Ogre by default has an animation (my_animation) and that way the error does not occur. Models, that are imported directly from blender does not have always animation and AnimControl does not exists.

My models are blender meshes and skeleton associated with the meshes. They does not have animations. I’m providing mesh movement in my own application code.

If it is OK, I can provide pull request on github.

Ok, next thing.

Now importing works. The bone hierarchy is applied. But there is a problem with bone rotation/location. Using “attachment node” for bones gives me incorrect values. The location/rotation is not applied to any bone.

It happens to models converted from blender -> j3o, from ogre -> j3o and also loading old j3o models (from 3.0 stable). The j3o model from git-head with above patch does not load in 3.0stable.

Will look at it in the evening more.