Author Topic: Md2 animation on Android problem [solved]  (Read 1988 times)

Offline haijin

  • byte
  • *
  • Posts: 37
    • View Profile
Md2 animation on Android problem [solved]
« on: April 29, 2011, 06:11:27 pm »
[Just before posting this I had a last shot, thinking it might be the strip() call (which prevents future modification). It wasn't that but the compile() call, which I also commented, because... well, had to try. So the conclusion is not to call compile if you have animations... I saw on the docs that it's not meant to be called, kind of a legacy method or something but no further explanation. If somebody wants to add the reasoning, that would be great.
I just went ahead and posted this because it might be handy to some, point a possible problem or well... just as a Hello World!]

Hi,

I've just started with jpct and I'm having trouble getting the animations to work on Android. The md2 model loads fine, it displays properly and transformations apply, but the animation just won't work. I've followed the advanced example, the logs says it processes the animations (stand, run, etc...) but the mesh doesn't change... also tried a couple of md2 files, with same results...
Here's the code... but I can't see any relevant difference to the examples:
Code: [Select]
[...] on creation
        try {
            zombie = Loader.loadMD2(ctx.getResources().getAssets().open("zombie.md2"), 0.1f);
            zombie.translate(0, 7, -3);
            zombie.rotateX((float) (-Math.PI / 2));
            zombie.rotateZ((float) (Math.PI / 2));
            zombie.setTexture("zombieskin");
            zombie.compile();// SOLUTION: that line was the problem, so just remove this line!
            zombie.strip();
            zombie.build();
        } catch (IOException ex) {
            Logger.getLogger(GameRenderer.class.getName()).log(Level.SEVERE, null, ex);
        }
[...] on draw
    float anim = 0;
    public void onDrawFrame(GL10 gl) {
        if (running){
//System.out.println(zombie.getAnimationSequence().getSequence("run"));
            zombie.animate(anim, zombie.getAnimationSequence().getSequence("stand"));
            zombie.rotateZ(0.01f);
            anim += 0.1;
            if (anim >= 1)
                anim = 0;
            fb.clear(BLACK);
            world.renderScene(fb);
            world.draw(fb);
            fb.display();
        } else
            fb.dispose();
    }

Any ideas on what's the problem?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Md2 animation on Android problem [solved]
« Reply #1 on: April 29, 2011, 09:12:31 pm »
The reason is pretty simple. If you don't call compile(), jPCT-AE will do this at runtime. Because the object contains an animation, it'll compile it as a dynamic object and all is fine. If you call it yourself, you'll simply compile the object as static. If you don't want that but still want to call compile() yourself, do compile(true, false); instead.