KeyFrameController

Hi all,

I successfully loaded the xml animation into my node, and it plays wonderfully. The selection of animation is the trouble.



Here’s my code for loading:



SAXReader sr = new SAXReader();

        Node model = null;
        try {
            URL modelU = ConvertMd2XML.class.getClassLoader().getResource(
                    "com/data/models/player/player.xml");
            model = sr.loadXML(modelU.openStream());
        } catch (IOException ioe) {
            LoggingSystem.getLogger().log(Level.SEVERE,
                    ioe.getCause() + ": " + ioe.getMessage());
        }
       
        kc = new KeyframeController();
        kc.setMorphingMesh((TriMesh)model.getChild(0));
        model.addController(kc);
       
        rootNode.attachChild(model);



and here's my animation selection:


kc.setMinTime(0f);
kc.setMinTime(2f);



Do I have to set the keyframes myself? or are they included in the xml?

if I dont set any keyframes, it exits and I get this error:


java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
   at java.util.ArrayList.RangeCheck(ArrayList.java:507)
   at java.util.ArrayList.get(ArrayList.java:324)
   at com.jme.scene.model.XMLparser.KeyframeController.update(KeyframeController.java:125)
   at com.jme.scene.Spatial.updateWorldData(Spatial.java:352)
   at com.jme.scene.Node.updateWorldData(Node.java:201)
   at com.jme.scene.Spatial.updateGeometricState(Spatial.java:332)
   at com.jme.scene.Node.updateWorldData(Node.java:206)
   at com.jme.scene.Spatial.updateGeometricState(Spatial.java:332)
   at com.jme.app.SimpleGame.initGame(SimpleGame.java:263)
   at com.jme.app.BaseGame.start(BaseGame.java:63)
   at com.volatile7.xv.ConvertMd2XML.main(ConvertMd2XML.java:86)



if I set keyframes, it works fine, but the selection doesn't happen. it just loops like a normal animation.

Any thoughts?[/code]

What is player.xml? If it is a MD2 file, MD2’s make their own KeyframeController because they define their own animations.



When you set the MorphingMesh for kc, you set the mesh that will be displayed (will get morphed), but you didn’t give kc any “frames” to morph to (You didn’t tell it what to look like at time=0 time=5 time=3 ect ect)



If the XML file is a md2 model, then it is setup like this (and the KeyframeController is already defined, so you don’t need to create a new one)



The file is a Node with one child

That one child is the mesh that is displayed (cause it’s a child to the node), and it has a controller that animates it.

That controller is the keyframe controller. It has an array of states at times.


Controller c=model.getChild(0).getController(0);
c.setMinTime(0);
c.setMaxTime(2)




The index error is that KeyframeController assumes you have put in at least two keyframes, otherwise there wouldn't be any animation.

When you say you were setting keyframes, how were you setting them?

The use is still up in the air, so if you think of a more intuitive way to structure how users setup and use the md2 let me know.

One more clarification on what I wrote below, when you load from the XML file you’re not -really- loading a md2 file anymore. You’re loading a TriMesh with a KeyframeController that will look like a md2 file. The purpose of the XML format was to take away the “.md2” and “.ms3d” and others and let users load directly into what jME needs and uses.



To stop the animation you would use

c.setActive(false)


and to speed it up or slow it

c.setSpeed(.5);




My next goal is to allow smooth morphing between one set of keyframes to another. For example if your guy is running then you have him shoot his gun it looks like he teleports to the correct position. I'll try to add a feature to allow users to morph directly between any two units of time

aaah, awsome, and yes, player.xml is an md2 animation. Brilliant!