J3o-file animation problem

Hey,
I have a problem with a j3o file. :sweat:
I have read the Tutorial in the locally Help, but i don’t understand it.
I would animate the model to walk, but if i start the application, it print the error:
Schwerwiegend: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:46)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)

Here ist the Code:

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.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 * test
 * @author normenhansen
 */
public class Main extends SimpleApplication implements AnimEventListener {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
            /** A white, spot light source. */ 
    PointLight lamp = new PointLight();
     lamp.setPosition(Vector3f.ZERO);
    lamp.setColor(ColorRGBA.White);
    rootNode.addLight(lamp); 
    Node monster = new Node("Monsters");
    Spatial monster1;
    monster1 = assetManager.loadModel("Models/Monster1/Monster1.j3o");
    monster1.setName("Monster1");
    monster1.setLocalScale(0.1f);
    Material monster1_mat = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    monster1_mat.setTexture("DiffuseMap", assetManager.loadTexture("Models/Monster1/Monster1.png"));
    monster1_mat.setFloat("DiffuseMap_0_scale",1f);  
    monster1.setMaterial(monster1_mat);
    AnimControl monster1Control;
    monster.attachChild(monster1);
    monster1Control = monster.getChild("Monster1").getControl(AnimControl.class);
    monster1Control.addListener(this);
    AnimChannel channel = monster1Control.createChannel();
    channel.setLoopMode(LoopMode.Loop);
    channel.setAnim("Walk",1f);
    rootNode.attachChild(monster);
    
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }

    public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}

And here the Model:
http://freeuploader.ml/data/Monster.zip

I hope, you can help me
Thanks. :wink:

You didnt put the actual exception since it would Show you the actual line.

100% that one of your controls is wrong since it isnt added to the models rootNode but rather somewhere below

This line is where the bug in your code is.

I know, but I don’t understand, why…
The line is monster1Control.addListener(this);

If I remove
AnimControl monster1Control; monster.attachChild(monster1); monster1Control = monster.getChild("Monster1").getControl(AnimControl.class); monster1Control.addListener(this); AnimChannel channel = monster1Control.createChannel(); channel.setLoopMode(LoopMode.Loop); channel.setAnim("Walk",1f);
It would load the model without any fails, but the program will not start with this code.

Easy enough. monster1Control is null since a method Argument doesnt count.

If you now re read my previous post you know whats wrong.

Hint: open and Explore the model with the sdk

Because this returns null:

I mean, pretty clearly the anim control is not on the node you think it is. It would only take 5 seconds in the scene explorer to find it. Or 5 minutes of coding to dump all of the controls of all of the children to see what’s what.

…either of which is faster than posting back and forth here over a day.

Sorry for my late answare :confused:

I have one, but how to get this?

monster1Control = monster1.getChild(“Armature”).getChild(“Cone.002”).getControl(AnimControl.class);

Scenegraph is a tree, so is your model. And you can see it visualized in your post.

1 Like

It works :smiley:
Thank you :slight_smile:

No problem. I do hope you understood the thing also!!! @pspeed explained it quite well…

You can directly use monster1.getChild("Cone.002").getControl(AnimControl.class);

it does DFS on whole sub nodes.

http://javadoc.jmonkeyengine.org/com/jme3/scene/Node.html#getChild-java.lang.String-

Yes, now i understand it, but I have now an other problem…
This monster (on blender):

is looks in jme like this:

:confused:

But I think, thats only my modelling skills :confused:

You need to bake animation in blender.
In blender select Rig then go to this menu Object → Animation → Backe Action

https://hub.jmonkeyengine.org/uploads/default/original/2X/6/6020a7b8012a569c61cc1fb21432065062ff618e.png

You can watch this tutorial

I have baked the rig to every animation, but it doesn’t solve the problem.

“Cone.004 has vertices with more than 4 weights assigned. The model may not behave as it should.”

The monster still has the problems :confused:

Make sure to apply scale, location and rotation to your model and rig (ctrl + a).

There used to be bugs if the root bone of the model is not at 0,0,0.

1 Like

It works!!!
Thank you :smiley: :smiley: :smiley: