Animation Problem

Hey All,



I am trying to load a model in my game (currently just a slightly modified helloaniamtion). The model is one that comes as an example with the Ogre exporter script for Blender that you can download here: http://blender2ogre.googlecode.com/files/blender2ogre-0.5.4.zip (examples/armature-test.blend is the file I am talking about). I use Ogre Exporter 0.5.4 in Blender to convert the file to the Ogre file format (I use the default options to export, except from the options ‘Export Scene’ and ‘Export Selected Only’, which I untick). Than I load it in to JMP (nightly build, because I have troubles with the stable version). Until here everything goes fine. I can see it in the Scene Composer. But when I try to load it in my ‘game’ and I hit the Spacebar to start the animation, nothing happens. Here is the code that I use:



[java]/*

  • Copyright © 2009-2010 jMonkeyEngine
  • All rights reserved.

    *
  • Redistribution and use in source and binary forms, with or without
  • modification, are permitted provided that the following conditions are
  • met:

    *
    • Redistributions of source code must retain the above copyright
  • notice, this list of conditions and the following disclaimer.

    *
    • Redistributions in binary form must reproduce the above copyright
  • notice, this list of conditions and the following disclaimer in the
  • documentation and/or other materials provided with the distribution.

    *
    • Neither the name of ‘jMonkeyEngine’ nor the names of its contributors
  • may be used to endorse or promote products derived from this software
  • without specific prior written permission.

    *
  • THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  • "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  • TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  • PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  • CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  • EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  • PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  • PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  • LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  • NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  • SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    /



    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;



    /
    * Sample 7 - how to load an OgreXML model and play an animation,
  • using channels, a controller, and an AnimEventListener. /

    public class HelloAnimation extends SimpleApplication

    implements AnimEventListener {



    Node player;

    private AnimChannel channel;

    private AnimControl control;



    public static void main(String[] args) {

    HelloAnimation app = new HelloAnimation();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    viewPort.setBackgroundColor(ColorRGBA.LightGray);

    initKeys();



    /
    * Add a light source so we can see the model /

    DirectionalLight dl = new DirectionalLight();

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

    rootNode.addLight(dl);



    /
    * Load a model that contains animation /

    player = (Node) assetManager.loadModel("Models/Cube/Cube.j3o");

    player.setLocalScale(0.5f);

    rootNode.attachChild(player);



    /
    * Create a controller and channels. /

    control = player.getControl(AnimControl.class);

    control.addListener(this);

    channel = control.createChannel();

    channel.setAnim("my_animation");

    }



    /
    * Use this listener to trigger something after an animation is done. /

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

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

    /
    * After "walk", reset to "stand". /

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

    channel.setLoopMode(LoopMode.DontLoop);

    channel.setSpeed(1f);

    }

    }



    /
    * Use this listener to trigger something between two animations. /

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

    // unused

    }



    /
    * Custom Keybindings: Mapping a named action to a key input. /

    private void initKeys() {

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

    inputManager.addListener(actionListener, "Walk");

    }



    /
    * Definining the named action that can be triggered by key inputs. /

    private ActionListener actionListener = new ActionListener() {

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

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

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

    /
    * Play the "walk" animation! */

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

    channel.setLoopMode(LoopMode.Loop);

    }

    }

    }

    };



    }

    [/java]



    Can sombody tell me what I am doing wrong?:slight_smile:

Hm, code looks fine from what I can see… You get no errors I suppose? Only thing is you check for an animation called “Walk” and then set one called “my_animation”, tho if thats the correct animation it should work (tho it will “reset” the animation when pressed while its running).



private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Walk") && !keyPressed) {
if (!channel.getAnimationName().equals("Walk")) {
/** Play the "walk" animation! */
channel.setAnim("my_animation", 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};



At line 111 It should be :

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

Yea, I wasn’t that clear in my question. When I open my model in the Scenecomposer, I can see the properties of it down left. There is a tree displayed with one of the elements (leafs) in it called AnimControl. When I click on it, on the right side of the screen the properties appear. There is a dropdownlist with as label ‘Animation Control’ where I can switch between the different animations. There is one animation called ‘my_animation’. So In my code I try to play ‘my_animation’ instead of ‘walk’. I have only changed ‘walk’ into ‘my_animation’ where I think it is nessessary to do a quick test.



http://imageshack.us/photo/my-images/833/jmeproblem.png/



But I’m gonna try another model now. Hope this will work better. I just wanted to know why it didn’t work, but I see it isn’t that simply as I thought it would be:)



Thanks anyway:)

What’s your problem? Aren’t your model being animated? Try updating to the lastest build.

Edit: Is it animated properly in blender?

Hmm, now I got what is your problem. You can play the “my_animation” in OpenGl Window, but you can’t play it in source code!? right?

Edit: Your code doesn’t do anything, only play the default animation.

If it works in the SceneComposer it works in code too, its not the model and not jME.

Can you play animations in Scenecomposer? It works fine in Blender, but not in my code…

They play when you select them. If the model isn’t animating when you select it the animation has no keyframes/data.

normen said:
They play when you select them. If the model isn't animating when you select it the animation has no keyframes/data.

Ok, it doesn't play when I select it. I am trying to create another model now. Thanks for the help all!

@normen: It looks imported models of the newest dotscene version are having problems with animations :/, I can’t play animations of an model which was imported using the newest dotscene version. Anyway I can play the Sinbad’s animations very well. I’ll keep testing it. Also, animations aren’t played properly of imported .blend models(sometimes the model disapears when an animation is played, and if the animation is played, it’s not played like in blender).

What is ‘the newest dotscene version’? The SDK comes with an export script that should be working for Blender 2.5+. You can install it via Tools->OgreXML

I’ve tested both via OgreXmlTools and googlecode. The AnimControl and SkeletonControl appears in SceneComposer, but the loaded node in source code has 0 num of controls. And animations of converted blend files aren’t played properly, and in source code it has 0 num of controls too.

I’ll create a test case.

@Kaelthas: Can it be you broke serialization more severely when doing the changes to the animation system?

The Track classes changed so I guess some serialization may fail :frowning:



In BoneAnimation nothing was changed though in read and write methods.

But in MeshAnimation there is the same issue with casting when reading tracks.

I guess there may be problems with the track array too.



SpatialAnimation was also changed but I guess it was not widely used.

I’ve made some tests:

-If I convert the sinbad.mesh.xml to sinbad.j3o and open it in SceneComposer, I can play its animation very well.

-If I convert a custom model I did Cube.mesh.xml to Cube.j3o and open it in SceneComposer I can play its animation too, but it doesn’t follow the bone movements…I’ve loaded the animated cube in source code, and attached a SkeletonDebugger, and I can see the bone being animated, but the cube keeps static. Also, converting the whole scene(.scene) to j3o and opening it in SceneComposer, I can see the AnimControl and SkeletonControl, but when I load it in source code, it has 0 controls. The same for .blend models.

:cry: :cry: :cry: :cry: :cry: :cry: :cry:

Hey, I toogled line breakpoints on write and read method of the MeshAnimation class from my jMonkeyEngine3 working copy so I can check what’s going wrong, but I don’t know how to debug it on SDK. How can I do it?

You can’t really, since its different projects and one references the other only via a jar file…

Edit: Oh, but you should be able to put break points into jme3 if you reference it as a library with sources as well.

glaucomardano said:
@normen: It looks imported models of the newest dotscene version are having problems with animations :/, I can't play animations of an model which was imported using the newest dotscene version. Anyway I can play the Sinbad's animations very well. I'll keep testing it. Also, animations aren't played properly of imported .blend models(sometimes the model disapears when an animation is played, and if the animation is played, it's not played like in blender).


Yeah, and I was true, I've made several tests and now finally I found the problem -.-. The problem is in dotscene for blender 2.59(that one provided by jMonkeyPlataform via OgreXml tools), the dotscene for blender 2.49 works fine. If you install it in blender 2.59 and export the animated model to jmp, jMonkeyEngine will don't import the animations properly, then the animations will doesn't work(the animcontrol and skeletoncontrol will be there, and the animations too, but they will don't work). The dotscene for blender 2.49 works fine in jmp :), then my solution is to use it at moment(that's not really good news, the old blender is a shit :D). Then the problem is probably in OgreXmlImporter, or in blender2ogre itself :/. Also, I've checked the .mesh.xml files both for 2.49 and 2.59, and I already know what's the problem: In 2.49 .mesh.xml files there are [xml]<geometry></geometry>[/xml] tags, and in 2.59 .mesh.xml files there are [xml]<sharedgeometry></sharedgeometry>[/xml] tags, then the problem is probably OgreXmlImporter doesn't supporting [xml]<sharedgeometry></sharedgeometry>[/xml] tags.
I've made some tests with the BlenderLoader too, it does load an animated model in jmp, but whenever an animations is played, the model disapears or the animation is not played properly(bugged). Although OgreXmlImporter does work fine with blender 2.49, it doesn't mean BlenderLoader does too. Then:

-Have to be done a fix in OgreXmlImporter(or in blender2ogre itself) for animation support.
-Have to be done a fix in BlenderLoader for animation support.

I think @Momoko_Fan have to be invited to this conversation too.

Cheers.