Author Topic: Md2 animation on Android problem [solved]  (Read 2570 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!]


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.compile();// SOLUTION: that line was the problem, so just remove this line!
        } 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){
            zombie.animate(anim, zombie.getAnimationSequence().getSequence("stand"));
            anim += 0.1;
            if (anim >= 1)
                anim = 0;
        } else

Any ideas on what's the problem?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12115
    • View Profile
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.