jPCT-AE - a 3d engine for Android => Support => Topic started by: haijin on April 29, 2011, 06:11:27 pm

Title: Md2 animation on Android problem [solved]
Post by: haijin 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?
Title: Re: Md2 animation on Android problem [solved]
Post by: EgonOlsen 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.