Error while trying to animate model

@gonzalofarias1 said: @pspeed this is the correct stack trace:

[java]ene 22, 2014 7:53:38 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:113)
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:722)[/java]

[java]public void simpleInitApp() {

    // You must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);
    
    Spatial scene = assetManager.loadModel("Scenes/newScene.j3o");
    rootNode.attachChild(scene);
    
    final int SHADOWMAP_SIZE=1024;
    DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);
    dlsr.setLight(sun);
    viewPort.addProcessor(dlsr);
    
    dlsf = new DirectionalLightShadowFilter(assetManager, 1024, 3);
    dlsf.setLight(sun);
    dlsf.setEnabled(true);
    
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(dlsf);
    viewPort.addProcessor(fpp);
    
    player = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.j3o"); 

//I downloaded this model from the official Ogre site (a Blender file), then I
//converted it using the latest exporter.
player.setShadowMode(RenderQueue.ShadowMode.Cast);
scene.setShadowMode(RenderQueue.ShadowMode.Receive);

    Node playerCamContainer = new Node();
    rootNode.attachChild(playerCamContainer);
    
    rootNode.attachChild(player);
    player.setLocalTranslation(10, 10, 10);
    
    // Disable the default flyby cam
    flyCam.setEnabled(false);
    //create the camera Node
    //camNode = new CameraNode("Camera Node", cam);
    //This mode means that camera copies the movements of the target:
    //camNode.setControlDir(ControlDirection.SpatialToCamera);
    //Attach the camNode to the target:
    //player.attachChild(camNode);
    //.getParent().attachChild(camNode);
    //Move camNode, e.g. behind and above the target:
    ChaseCamera chaseCam = new ChaseCamera(cam, player, inputManager);
    //Rotate the camNode to look at the target:
    //camNode.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y);
    
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    
    playerControl = new BetterCharacterControl(1,1.8f,50);

// Attach physical properties to model and PhysicsSpace
player.addControl(playerControl);
bulletAppState.getPhysicsSpace().add(playerControl);
bulletAppState.getPhysicsSpace().add(rootNode.getChild(“terrain-newScene”).getControl(RigidBodyControl.class));

    control = player.getChild(0).getControl(AnimControl.class);
    control.addListener(this);   // <<--This is the line firing the exception
    channel = control.createChannel();
    channel.setAnim("my_animation");
    
    initKeys();
}[/java]</blockquote>

Well, as someone else pointed out trying to guess which line 113 is (probably accurately), your bug is here:
at mygame.Main.simpleInitApp(Main.java:113)

…but we can only guess which line that is. This thread has become too much work for me so I will let others continue helping and I will step out.

@pspeed said: Well, as someone else pointed out trying to guess which line 113 is (probably accurately), your bug is here: at mygame.Main.simpleInitApp(Main.java:113)

…but we can only guess which line that is. This thread has become too much work for me so I will let others continue helping and I will step out.

That line just adds a listener to the animation control. However, @causticcuddles was able to reproduce it.

Okay. So I’ve managed to find the assets for the tests project and fished out Sinbad. Compiling him to j3o and loading him up works just fine so now we know it’s a problem in the models we have and not the IDE.

I’ve also deduced that directly converting the .blend file to J3O means the animations work as intended in the scene composer and in the game, but I’m having separate issues with UVs with that way of doing it.

@causticcuddles said: Okay. So I've managed to find the assets for the tests project and fished out Sinbad. Compiling him to j3o and loading him up works just fine so now we know it's a problem in the models we have and not the IDE.

I’ve also deduced that directly converting the .blend file to J3O means the animations work as intended in the scene composer and in the game, but I’m having separate issues with UVs with that way of doing it.

Take into account that those models I tried work just fine when you open them for example in OgreMeshy. They seem to be valid Ogre mesh files.

I fixed my issue converting .blend files (remove all materials/textures before converting). I suggest you try it that way too. Good luck.

@causticcuddles said: I fixed my issue converting .blend files (remove all materials/textures before converting). I suggest you try it that way too. Good luck.

You mean importing them directly from jMonkey?

Any way, I don’t think that’s a fix… What if I’m using directly the Ogre model files?

@gonzalofarias1 said: That line just adds a listener to the animation control. However, @causticcuddles was able to reproduce it.

It is irrelevant what that line does. For all we care it could try to spawn clowns in outer space, but IT IS at that line that it crashes. There is no ifs, no buts, no argument to be had.

Fix that line then it will be possible to move on and fix other issues.

@gonzalofarias1 said: You mean importing them directly from jMonkey?

Any way, I don’t think that’s a fix… What if I’m using directly the Ogre model files?

Yes. Right clicking the file and choosing Convert to j3o

@madjack said: It is irrelevant what that line does. For all we care it could try to spawn clowns in outer space, but IT IS at that line that it crashes. There is no ifs, no buts, no argument to be had.

Fix that line then it will be possible to move on and fix other issues.

I got that line from an example of how to animate models. With another model it works well, but with this particular one, it doesn’t.

Anyway, the fact is that the model is still not able to reproduce animations in the scene composer. Even if I don’t add a single line of code that could break everything, I get an error whenever and however I try to animate it.

I found what the issue was:

An exported Ogre skeleton with animations has to have translation information on EVERY FRAME.

The ogre exporter I used just deleted translation information if it was x=0, y=0, z=0, causing this error.

To fix it just add to the animation:

<translate x=“0” y=“0” z=“0” />

On every frame that doesn’t have translation.

In notepad++ I do it like this:

Find: >
<rotate

Replace: >
<translate x=“0” y=“0” z=“0” />
<rotate

Now it’s working! =D