Blender, models and animation

I am trying to create a very simple model and animation and import it into a simple project.

I created my model and animation in Blender and it works as I want it to there, it is a single mesh with a single bone that rotates the mesh on the Z-axis. I have it saved in a .blend file, which as I understand it JME does not support directly reading the .blend file and it must be exported to a Ogre .mesh.xml and .skeleton.xml.

When I attempt to export the .blend file through the Ogre exporter I only get a .scene file and a .mesh.xml file. I assume I must be missing something really simple, but I have been struggling with trying to export this simple file for a few days now and no luck.

Also on a related question, I was wondering if there is a way to setup the model, skeleton and animations (one file per animation) as separate files? This way it would be easier to make context sensitive animations and if different skeletons can use those animations (assuming the skeletons follow the same naming conventions) it would reduce the amount of duplicate animation work required, if that is even possible.

You can just copy the .scene and all other exported files into your Models folder (I suggest you create a subfolder) and then double-click the .scene. This will create a .j3o for you. Afterwards you gotta keep the texture files but you can delete the .material files.

You can convert .blend to .j3o via the SDK (like for ogre).
About blender “usage” you can read https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:external:blender

I have added the .scene and .mesh.xml to JME SDK and double clicked the .scene to create the .j3o. When I open the .j3o I can see my model, but when I try to run the application I get a null pointer exception. It seems the AnimControl is not being created. If I comment out all the animation related stuff the application will load up and I can see my mesh, so I must still be missing something. I am using the code from the following link, just changing the model loaded to my .j3o file.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_animation

Edit:
I have also tried to import the .blend file and it seems to be creating the AnimControl now, but I get an error stating that it cannot find my animation. The mesh also has some odd rotations and translations applied to it.

You gotta move down the object tree you will probably see yourModel.j3o and then something like yourmodel-entity and then yourmodel-ogremesh and at one point there is an AnimControl. You will need to go that deep into the object tree. So you have to call Node yourspatialEntity = (Node) ((Node) yourSpatial).getChild(0);
and then continue calling this on yourspatialEntity etc. until you are at the desired depth.

I have managed to get the mesh imported and it is animating now. But there is still a problem and I think it has to do with the fact that Blender uses a Z-up world and JME uses a Y-up world. In Blender I have my mesh rotate around the Blender Z-axis, but when run in JME the mesh is on it’s side and rotates around the JME Y-axis. It appears that JME is correcting the animation by changing the Blender Z-axis to the JME Y-axis, but the mesh appears to still be using the Blender coordinate system, which causes the animation to be very different between the two. Is there any way to correct this?

First, I would like to thank Mathias and David for getting me this far, but I am still stuck and cannot quite figure out what I am doing wrong.

I have recreated my model and at each step I imported it to JME to see where the discrepancy started, I have gone through this same process 3 times to make sure that I am not doing anything else. I found that as soon as I connected the mesh to the bone the model was rotated in JME. These are the steps I took, where am I making the mistake?

  • Create new model in blender and remove the camera and light source and initial box mesh
  • Create a new torus mesh
  • Translate mesh to 0,0,4
  • Create root bone located at 0,0,0
  • Extrude new bone from root bone
  • Disconnect new bone from root bone (new bone is still parented to the root bone)
  • Translate new bone to 0,0,4
  • Parent mesh to new bone

That last step causes the model to diverge from what is seen in Blender when viewed in JME.

I have noticed that if I export the model from Blender through Ogre I do not get a .skeleton file and when I convert the .scene to .j3o and attempt to find the AnimControl on any of the children using a breadthFirstTraversal, it is not found.

If I instead import the .blend file directly and convert from that to .j3o, I am able to get the model to animate, although the location of the mesh is incorrect. I also tried to see if it was creating a skeleton by checking the AnimControl#getSkeleton() method and found that is null. Although this does make me wonder how it is animating at all considering the rotation changes I made while I had my child bone selected in pose mode, so I am not directly animating the mesh.

I assume this has something to do with the way I am creating the armature as neither Ogre or .blend -> .j3o is creating a skeleton.

Is it correct to set the bone positions using edit mode of the armature or should it be set in pose mode. I assume that the bone should be initially set in its proper place using edit mode and then manipulated in pose mode for the animation. If I should be setting the initial position of the non-root bones in pose mode, what should the edit mode position of the bone be?

I have made a little more progress on this, still not quite sure how to get things working correctly. I really thought this would be a lot easier than it is turning out to be.

Anyway I have managed to get animations working, kind of, I have attempted two different approaches. Neither work correctly, but in different yet complementary ways, meaning that they both are doing something that if the other was doing the issue would be put to bed.

The first way (and the one I would actually prefer, because it is loads easier to deal with) is direct from .blend to .j3o. Using this method I am able to scale my mesh with the bone, but it does not do rotations and the skeleton is null, making it rather difficult to see what is going on.

The second is .blend to Orge to .j3o. Using this method I am able to see the skeleton in JME by enabling skeleton debugging. The animation is also working almost entirely correct except that it plays backwards and renames my animation to “my_animation” regardless of what I have it named in blender, I’ve checked and this is in the .blend to Ogre export process. I could deal with the extra steps in this process if I could figure out why the animation is playing backwards.

In both approaches, I use the exact same code. The only things I check, which causes a different execution to occur is the name of the animation (so I can set the animation to play either “my_animation” or the animation as named in Blender) and whether the skeleton is populated in the AnimControl (so I can create the SkeletonDebugger).

I am fairly confident that this whole process is a lot easier than it is proving to be. But with the results of these two methods being close but both failing in odd and quite different ways it is very confusing.