www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: zammbi on July 08, 2008, 12:09:14 pm

Title: Animation help for md2
Post by: zammbi on July 08, 2008, 12:09:14 pm
I have basic animation working, but have a problem with some frame names.
I'm using models which name there frames like so for walking:
WB01, WB02, WB03F, WB04....
F meaning play the footstep sound.
Is there a way to get the animation name?
Also the above example jpct splits that up into 3 seq, how would I play this smoothly?
Title: Re: Animation help for md2
Post by: EgonOlsen on July 08, 2008, 02:45:13 pm
You are using different model files for different parts of the animation? Or did i get you wrong?
Title: Re: Animation help for md2
Post by: zammbi on July 08, 2008, 02:50:51 pm
I'm using only 1 model. Just having problems with frame names.
Title: Re: Animation help for md2
Post by: EgonOlsen on July 08, 2008, 07:33:03 pm
Well, then...the names won't be preserved, but the order doesn't change. You can access you sub-animations at the corresponding index. However, i don't think that it is a good idea to split a walk animation in sub-animations.
Title: Re: Animation help for md2
Post by: zammbi on July 09, 2008, 01:54:01 am
Well its not split up in sub-animations, its just that jpct doesn't like the last letter at the end so it does split them up.
All the models that I'm using do this, to hold extra info. I want to keep to the software side and not worry about modeling just yet. So much to do atm  :-\
Wondering if this could be updated to handle this? To have access to the frame name, and to handle extra letters at the end of the frame number without splitting the animation or choose how to split the animation?
If not then I will just have to edit the models manually and keep the extra info in a separate file.
Thanks for the help.
Title: Re: Animation help for md2
Post by: EgonOlsen on July 09, 2008, 10:29:36 am
I see...i have never seen such a model execpt for one, that used the names to store some blahblah instead of real names. I've written a converter for this IIRC that takes this model after loading and converts it into one that uses the default frame deltas for Quake2-MD2 files. I once introduced the splitting based on names to handle MD2 files that don't follow the format's convention about which frames represent which animation, and i don't think that i'm going to change this. I'll look out for that conversion code later...
Title: Re: Animation help for md2
Post by: zammbi on July 09, 2008, 11:15:55 am
Heres an example (http://www.pokemonworldonline.net/Downloads/other/tris.txt) (need to rename to md2).
That converter sounds good. Then I wont need to manually rename the frames.
Title: Re: Animation help for md2
Post by: EgonOlsen on July 09, 2008, 07:15:08 pm
I've looked into the converter code...problem is, that it requires an extended Animation class that isn't part of the official 1.16 distribution. I've created an 1.16/pre1.17-hybrid-release which comes as a jar-file only (i.e. no documentation for some new stuff). It can be found here: http://www.jpct.net/download/beta/jpct.jar (http://www.jpct.net/download/beta/jpct.jar)

Here's the converter's code:

SimpleStream is a simple Wrapper around an InputStream. This code doesn't process the whole file, but the comment includes the other offsets. You just have to extend the groups-array accordingly if needed. Keep in mind that this code is taken directly from my latest project, so it may do some things that aren't appropriate for you, but it shouldn't be too hard to remove that parts. I hope this helps.

Code: [Select]
            SimpleStream ss = new SimpleStream("data/weapon.md2");
            bluePrint = new Object3D(Loader.loadMD2(ss.getStream(), 0.22f));//
            bluePrint.translate(0, 4.5f, 0);
            bluePrint.translateMesh();
            bluePrint.getTranslationMatrix().setIdentity();
            bluePrint.setTexture("weapon");
           
            // This invader weapon file doesn't follow the standard naming convention. We have to
            // regroup the animations...that sux!
           
            /*
                {   0,  39,  9 },   // STAND
    {  40,  45, 10 },   // RUN
    {  46,  53, 10 },   // ATTACK
    {  54,  57,  7 },   // PAIN_A
    {  58,  61,  7 },   // PAIN_B
    {  62,  65,  7 },   // PAIN_C
    {  66,  71,  7 },   // JUMP
    {  72,  83,  7 },   // FLIP
    {  84,  94,  7 },   // SALUTE
    {  95, 111, 10 },   // FALLBACK
    { 112, 122,  7 },   // WAVE
    { 123, 134,  6 },   // POINT
    { 135, 153, 10 },   // CROUCH_STAND
    { 154, 159,  7 },   // CROUCH_WALK
    { 160, 168, 10 },   // CROUCH_ATTACK
    { 169, 172,  7 },   // CROUCH_PAIN
    { 173, 177,  5 },   // CROUCH_DEATH
    { 178, 183,  7 },   // DEATH_FALLBACK
    { 184, 189,  7 },   // DEATH_FALLFORWARD
    { 190, 197,  7 },   // DEATH_FALLBACKSLOW
    { 198, 198,  5 },   // BOOM
             */

            int[] groups=new int[]{39,45,53,57,71,83,94,111,122,134,153,159,168,172};
           
            Animation anim=bluePrint.getAnimationSequence();
            Mesh[] meshs=anim.getKeyFrames();
           
            Animation re=new Animation(173);
           
            int s=0;
            for (int i=0; i<groups.length; i++){
            re.createSubSequence("anim_"+i);
            for (int p=s; p<=groups[i]; p++) {
            re.addKeyFrame(meshs[p]);
            }
            s=groups[i]+1;
            }
            bluePrint.setAnimationSequence(re);
           
            ss.close();
Title: Re: Animation help for md2
Post by: zammbi on July 10, 2008, 04:05:32 am
Ok cool. But this way I will still need to manually change the frames?
Is it possible to read the frames names and just remove the letters at the end of its name then just use them as normal?
Title: Re: Animation help for md2
Post by: EgonOlsen on July 10, 2008, 07:12:30 am
Ok cool. But this way I will still need to manually change the frames?
You mean the names? Why do you still need to change them with this converter? After the conversion, the resulting model behaves as if it has been loaded by a MD2-loader which ignores the naming but relies on default offsets in the format. Isn't that sufficient for your model?
Title: Re: Animation help for md2
Post by: zammbi on July 10, 2008, 08:05:03 am
Sorry didn't explain clear enough. I'm currently using a lot of models from a open source game which use the same system as the model above. If I read right, your converter you still need to know all about the frame seq so you can change it correctly right? Meaning I would have to load up each model in a modeler looking up the frame names. Just thought it would be an easy way just to convert WB04F to WB04. Just was trying to cut the amount of work in this area but doesn't matter too much.
Title: Re: Animation help for md2
Post by: EgonOlsen on July 10, 2008, 09:01:04 am
The frame distribution in a standard MD2 is fixed in the way the comment in the code explains it. In theory, there shouldn't be a MD2 that doesn't match this distribution. In your case, that means that WB02, WB03F...should all be part of the walk-animation between 40 and 45. If that's not the case, our file doesn't follow this convention.
Title: Re: Animation help for md2
Post by: zammbi on July 10, 2008, 09:59:44 am
Ok thanks for all the help.
Not sure what I'll do atm, but when ever I redo the models, I'll make sure there in the right name format  ::)