Need help for basic animation of an arm

Does anyone have an idea ?

Can you provide the mesh.xml file in addition to the skeleton?

Why do you want to import one object of an animated model? Try just creating the object w/o animation in blender.

Momoko_Fan said:
Can you provide the mesh.xml file in addition to the skeleton?

Yes, this is a rar containing all the meshes and skeletons and scene and material for the animated robotic arm (with blender file).
http://www.megaupload.com/?d=AQ01TYQ0

normen said:
Why do you want to import one object of an animated model? Try just creating the object w/o animation in blender.

Just to see if the .scene was the problem for the animation. You want me to export the part of the arm without the skeleton ?

Best regards,

rXp>!<

Still can’t figure out what I do wrong.

I dont know whats your problem, the model loads and animates… The AnimControl is only at the root node of the loaded model, all is correct.

So you mean that you tried, so the issue is with my sdk ? Maybe you use a nightlybuild ?

No, you are just doing it wrong somehow, read again the wiki manuals and the pdf about blender to jme.

Hello once again,



I reread everything :

  1. How to export from Blender and import properly into the SDK : https://docs.google.com/fileview?id=0B9hhZie2D-fENDBlZDU5MzgtNzlkYi00YmQzLTliNTQtNzZhYTJhYjEzNWNk&hl=en
  2. How to load the models/scene and animate : https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_animation


  3. There is my code :

    [java]package mygame;



    import com.jme3.animation.AnimChannel;

    import com.jme3.animation.AnimControl;

    import com.jme3.animation.AnimEventListener;

    import com.jme3.animation.LoopMode;

    import com.jme3.app.SimpleApplication;

    import com.jme3.input.KeyInput;

    import com.jme3.input.controls.ActionListener;

    import com.jme3.input.controls.KeyTrigger;

    import com.jme3.light.DirectionalLight;

    import com.jme3.math.ColorRGBA;

    import com.jme3.math.Vector3f;

    import com.jme3.scene.Node;



    /** Test 5
  • Control the animation of a robotic arm /

    public class Main extends SimpleApplication

    implements AnimEventListener {



    private AnimChannel channel;

    private AnimControl control;

    Node scene;



    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    /
    background /

    viewPort.setBackgroundColor(ColorRGBA.LightGray);

    initKeys();



    /
    simple direction light /

    DirectionalLight dl = new DirectionalLight();

    dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());

    rootNode.addLight(dl);



    /
    load the scene /

    scene = (Node) assetManager.loadModel("Scenes/Test/Scene.j3o");

    System.out.println(scene.getChildren().size()); // = 12

    /
    attach the scene to the rootnode /

    rootNode.attachChild(scene);

    /
    get a part of the model to take the contol over it /

    Node arm2 = (Node) scene.getChild("arm2");



    /
    create the control on the arm2 /

    control = arm2.getControl(AnimControl.class);

    System.out.println(arm2.getNumControls()); // = 0

    control.addListener(this); // nullPointerException since the arm2 has 0 control

    channel = control.createChannel();

    channel.setAnim("Action");

    }



    public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

    if (animName.equals("Action")) {

    channel.setAnim("Action", 0.50f);

    channel.setLoopMode(LoopMode.DontLoop);

    channel.setSpeed(1f);

    }

    }



    public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {

    // -

    }



    /
    * Keybinding */

    private void initKeys() {

    inputManager.addMapping("Action", new KeyTrigger(KeyInput.KEY_SPACE));

    inputManager.addListener(actionListener, "Action");

    }



    private ActionListener actionListener = new ActionListener() {

    public void onAction(String name, boolean keyPressed, float tpf) {

    if (name.equals("Action") && !keyPressed) {

    if (!channel.getAnimationName().equals("Action")) {

    channel.setAnim("Action", 0.50f);

    channel.setLoopMode(LoopMode.Loop);

    }

    }

    }

    };



    }[/java]
  1. The screenshot :



    Still 0 control for the upperarm. And I follow the instructions line after line.



    Best regards,



    rXp>!<

Dude, you never set up the AnimChannel and try to call a method on the null variable… The NPE is in your code.

Okey the issue comes from me and I missed something…



The channel is created here, right ?

[java]channel = control.createChannel();[/java]



But the problem comes from here :

[java]control.addListener(this); // nullPointerException since the arm2 has 0 control[/java]



I believe you, there is a NPE but where ? I import the scene without problem and I get a child without problem.

Oh, I was deluded by the syntax highlighter… Yeah, the thing is, theres only one AnimControl per model and that contains all animation, you are accessing a single geometry of the whole model and try to get an AnimControl, there is none. The AnimControl of the model is in the root node of it.

Okey so theoretically the animcontrol is on the scene itself ? (the node that contains all node is the scene) ? See the screenshot.

Yes, not just in theory, as said the model works fine for me.

[java]/* load the scene /

scene = (Node) assetManager.loadModel("Scenes/Test/Scene.j3o");

/
attach the scene to the rootnode /

rootNode.attachChild(scene);



/
create the control on the scene */

control = scene.getControl(AnimControl.class);

System.out.println(scene.getNumControls()); // = 0[/java]



So like this (if I want to controls of the all scene) ? Because it has 0 controls.

If you’re loading it from a .scene file you will have to search the scene graph for AnimControls, there are visit methods on the Node that you can use to do that

I discovered where the animation are attached :

Scene node > wristbase:0 > wristbase-entity:0 > wristbase-ogremesh:1

Scene node > arm2:0 > arm2-entity:0 > arm2-ogremesh:1

So in the child of a child of a child.

Is that weird ? And is distorted, it doesn’t animate right.



Best regards,



rXp>!<

Apply all rotations and scales before exporting. Read the pdf at the bottom of hello assets again.

You mean this :

https://docs.google.com/fileview?id=0B9hhZie2D-fENDBlZDU5MzgtNzlkYi00YmQzLTliNTQtNzZhYTJhYjEzNWNk&hl=en

Well, it says to check the Fix up axis to y and to put an empty. That’s it :confused:

No I mean this: