Blender animation no working

Hi



I have created a model in blender 2.60a. It is very simple, it is a rectangle. The model also has a animation (armature with 3 bones).

When I import the model into jme, the model is ok.

http://i.imgur.com/SfATF.png



But if I run the animation (uncomment [java]channel.setAnim(“ArmatureAction”);[/java] line), the model is wrong and the animation is not executed.

http://i.imgur.com/bUQRl.png



Is animation on blender 2.6 supported? What am I doing wrong?



Thanks in advance,



H



Model:

http://www.2shared.com/file/XnPRwkuL/gusano.html



Texture:

http://i.imgur.com/Gupd4.png



Code:

[java]

package mygame;



import com.jme3.animation.AnimChannel;

import com.jme3.animation.AnimControl;

import com.jme3.app.SimpleApplication;

import com.jme3.asset.BlenderKey;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;

import com.jme3.texture.Texture;



public class Alphonce extends SimpleApplication {



private AnimChannel channel;

private AnimControl control;



public static void main(String[] args) {

Alphonce app = new Alphonce();

app.start();

}



@Override

public void simpleInitApp() {



Material mat_stl = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

Texture tex_ml = assetManager.loadTexture(“Textures/Gupd4.png”);

mat_stl.setTexture(“ColorMap”, tex_ml);



flyCam.setMoveSpeed(10);



BlenderKey blenderKey = new BlenderKey(“Models/gusano.blend”);



Spatial scene = (Spatial) assetManager.loadModel(blenderKey);

rootNode.attachChild(scene);



Spatial model = this.findNode(rootNode, “gusano”);

model.center();

model.setMaterial(mat_stl);



control = model.getControl(AnimControl.class);

channel = control.createChannel();



//channel.setAnim(“ArmatureAction”);



viewPort.setBackgroundColor(ColorRGBA.Gray);

}



private Spatial findNode(Node rootNode, String name) {

if (name.equals(rootNode.getName())) {

return rootNode;

}

return rootNode.getChild(name);

}



}

[/java]

You need a common root bone for blender 2.5/6 animation to work properly afaik. Idk if thats a general problem or if it will be fixed in a later release of the blender importer though. @Kaelthas can you tell us more about this?

Woooh! That was fast. Thanks normen.



What do you mean with “You need a common root bone for blender 2.5/6”?



This is how the model looks on blender:





Thanks in advance,



H

Ah. I misread what you wrote, I thought you had 3 armatures, not 3 bones… Does it work when you do not set the “fix y-up” flag when importing? The blender importer isn’t 100% release ready yet, maybe you can also try and import using OgreXML. You can install the importer in blender via Tools->OgreXML in the SDK.

@H

The problem is that you have to set a key for all bones at least once(!?). You should be fine to make a LocRotScale-Key at the first frame.

The scale-key is at least at the moment also necessary because otherwise it will just set scale to 0 :smiley: (Forgot to tell that the incredible

blender-importer-guy).

Actually you have to start a new blend-file! It was very strange I couldn’t create a working example within your file only after creating a new file! (Might be because I opened a 2.6-file with 2.59!?) Here a working sample: http://dl.dropbox.com/u/11752001/gusano.blend

3 Likes

@ttrocha:

I have to create a new file too, I don’t know why.

The animation is working now, but the rotation of the bones are not the same that on blender. It looks like the rotation point (or rotation pivot) that jme use is different to the rotation point that blender use. Perhaps this is related with the position of the geometry origin point or something like that. I need to do more research about this.

Thanks.



@normen: I will try ogrexml importer.

Thanks.



H

If you use the ogre xml for blende 2.6 you’ll need to see this post : http://hub.jmonkeyengine.org/groups/general-2/forum/topic/animations-arent-working-at-all/?topic_page=2&num=15#post-148647

He’s using the blender importer … But yeah

@Kaelthas should look at this post if he doesn’t know about those issues

@ttrocha said:
The problem is that you have to set a key for all bones at least once(!?). You should be fine to make a LocRotScale-Key at the first frame.

Ah... Thanks! I didn't know this.

It looks like the model’s origin has to be in the same position that the armature’s origin. :?



Anyway, It will be good if someone can check this too.



Thanks,



H

@H: Well, I’m quite sure that this is the case. At least it was with all other t o me known ex/importers. Before you start rigging with blender, select the mesh, shift+s->cursor to selection and then create the rig! But only in edit-mode…at least that is the way I go for rigging…

@ttrocha: Ok, good to know that model’s origin position is important for jme. Thanks very much.



So,the animation (very very simple one) is working. So, I will move to material and textures (colormap and normalmap). More advance animation in the future… :smiley:



Thanks to All,



H

The model’s orign is the crucial point :wink:

@H: How did you solve the animation-problem? Did you use the blender loader or the ogreXML-Exporter? And can you give me a working example like the one in the first post please?



I’m dealing with this problem now for 3 or 4 months and wasn’t able to find a proper way to convert a animated blender modell to a j3o-file.



ceiphren



edit: ah, I got it. I used ttrochas model where I had to load the model like this:



BlenderKey blenderKey = new BlenderKey(“gusano.blend”);



LoadingResults scene = (LoadingResults) assetManager.loadModel(blenderKey);

rootNode.attachChild(scene);



Spatial model = scene.getObjects().get(0).getChild(0);



Looks like crap but good enough for a test.

@ceiphren: I used blender loader first. Then, I converted the .blend file to .j3o file (using th SDK) and tried that too.

According to “03 Hello Assets” Tutorial:

“For testing and for the final release build, you use .j3o files exclusively. J3o is an optimized binary format for jME3 applications, and .j3o files are automatically included in the distributable JAR file by the build script. When you do QA test builds or are ready to release, use the SDK to convert all .obj/.scene/.xml/.blend files to .j3o files, and only load the .j3o versions.”



imports ommited (;))

[java]

public class Gusano2 extends SimpleApplication {



private AnimChannel channel;

private AnimControl control;



public static void main(String[] args) {

Gusano2 app = new Gusano2();

app.start();

}



@Override

public void simpleInitApp() {



flyCam.setMoveSpeed(10);



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



AmbientLight al = new AmbientLight();

al.setColor(new ColorRGBA(0.5f, 0.5f, 1f, 1));

rootNode.addLight(al);



// Blender loader

BlenderKey blenderKey = new BlenderKey(“Models/test1/gusano4.blend”);

Spatial scene = (Spatial) assetManager.loadModel(blenderKey);



// j3o file

// Spatial scene = (Spatial) assetManager.loadAsset(“Models/test1/gusano4.j3o”);



rootNode.attachChild(scene);



Spatial model = this.findNode(rootNode, “Cube”);

TangentBinormalGenerator.generate(model);



control = model.getControl(AnimControl.class);

channel = control.createChannel();



channel.setAnim(“BowAction”);



viewPort.setBackgroundColor(ColorRGBA.LightGray);

}



private Spatial findNode(Node rootNode, String name) {

if (name.equals(rootNode.getName())) {

return rootNode;

}

return rootNode.getChild(name);

}

}

[/java]



Blender file with animation and material (color map and normal map).

http://www.2shared.com/file/m8gD1Zp9/gusano4.html



I hope this help



H

1 Like

@H: Thank you. Now it works fine : )

I’ve found a new problem. If the animation moves the object on the y-axis in blender than jme should move the object on the z axis in the jme, but it’s also the y-axis. If I set “blenderKey.setFixUpAxis” the axis y and z will be correctly inverted, but also my object is inverted, too.



How to solve that?



btw. maybe some of you heard about the discussion which axis should be up in 3D space. Z or Y? What I think? Damn, I couldn’t care less. It really doesn’t matter. What matters is, that everybody should agree to one axis. All this conversion crap costs so much time and resources just because people cannot make a decision between two letters. That’s really annoying.

Okay I’ve found a solution:



Like in this post mentioned:

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/animations-arent-working-at-all/?topic_page=2&num=15#post-148647



you need a root bone which doesn’t change the location. Moving the object-mesh can be done with sub-bones which aren’t connected to the rootbone.



Sometimes the import fails in this method: ArmatureHelper.getCurveType(String rnaPath, int arrayIndex). The rnaPath is “location” which currently seems not to be supported. In most cases this happend with blender 2.6. With blender 2.58 it works (but I had to create a new file).

1 Like

Animations are working with the blender loader? I’m using the ogre xml.

@glaucomardano: yeah, it’s kind a tricky. Looks like that it’s not in a fully release state but it works.