www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on July 25, 2010, 02:59:46 am

Title: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 25, 2010, 02:59:46 am
I'm writing a MD2 fixer (sometimes an animation is short a frame and the next, therefore, has one too many). Since I decided to use jPCT so we can see the changes in real-time, it would be helpful if I could have the above-mentioned methods to work with, lest I be forced to identify the animation names and lengths from the MD2 bytes themselves.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 25, 2010, 09:48:26 pm
I'll see what i can do...but what is Object3D.getAnimationSequence(int index) supposed to return exactly?

Edit: Looking at the Animation class, most of the stuff you want seems to be there already. You can get the complete list of keyframes, the start and end positions in that list for each sequence and each sequence has a name...you just can't get that name back from the Animation. Would it be sufficient to add just that?
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 26, 2010, 12:04:40 am
Sure, if I can identify to whose animation (by name) each frame belongs, it will suffice. Thanks a lot.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 26, 2010, 08:39:09 pm
I've uploaded a version with the added method (Animation.getName(<int>)) here: http://www.jpct.net/download/beta/jpct.jar (http://www.jpct.net/download/beta/jpct.jar)

That, combined with the option to return the animation's meshes and the start and end positions of each sequence should do the trick.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 26, 2010, 08:48:53 pm
Thanks a whole lot, Egon.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 27, 2010, 08:27:27 pm
So here's a question: I take it that the MD2 format has a header of 68 bytes, and each frame, I believe, is 40 bytes plus 4*numberOfVertices. Is that right, and could I safely say that, say, frame 3 of a mesh with 100 vertices starts at byte 469 (array index 468)?
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 27, 2010, 08:49:03 pm
I don't think that you can be 100% sure about this. The md2-header contains the offset positions where each type of data can be found in the file. It's better to use that information IMHO.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 27, 2010, 09:04:46 pm
I meant 869+80, by the way, in my previous post (forgot to multiply!).

So is the offset an absolute value? Say the offset is 1000, would I just go, again for frame 3 , by 2*4*numberOfVertices+1000 +80?
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 27, 2010, 09:51:23 pm
I'm not sure about the numbers, but basically yes. Starting at the offset, the size of each frame is the same.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: zammbi on July 29, 2010, 06:26:04 am
What about a method that gets an animation sequence by name? That might be handy too.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 29, 2010, 05:13:26 pm
What is that supposed to return? A part of the animation array or just the start and end position in that array?
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: zammbi on July 29, 2010, 06:27:29 pm
Return a int of the sub sequence so can do something like this:

character.animate(0.0, character.getAnimationSequence().getAnimationSubSequence("walk"));

I hope that makes more sense.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 29, 2010, 09:08:08 pm
I see. I've added it (getSequence(<String>)) and uploaded a new jar. Download location is the same as posted above.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: zammbi on July 30, 2010, 06:49:58 am
Thanks that will help a lot.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 31, 2010, 10:19:22 pm
How big is struct vec3_t, do you know? Because the little bastard is set before the frame names, and for the life of me I could not find its declaration by googling it. I need to know it so I can get the proper indentation to the animation's char array.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 31, 2010, 11:12:06 pm
By the way, I tried 6, 12, and 24 (for 1 byte per axis, 2, and 4 in two ve3_ts), but it seems that vec3_t has more data than that.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 31, 2010, 11:26:36 pm
If we are talking about the 6 floats that come right before the actual name, then that's...well...6 floats, i.e. 24 bytes.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on July 31, 2010, 11:42:54 pm
Are you sure it's just 3 floats per vec3_t (6 total)? If so, there's something wrong with what I'm doing...
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: EgonOlsen on July 31, 2010, 11:53:39 pm
No, i'm not sure because i'm not sure if we are talking about the same thing here. I'm talking about the section whose offset is stored at position 56 in the header. That one contains 6 floats (scaling and translation), the name of the frame and the actual vertex data for each frame.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: AGP on August 01, 2010, 03:16:26 am
Yes, we're talking about the same thing, which makes something I'm doing wrong and my question answered.

So anyway, here's the only definition of frame that I got:
struct md2_frame_t
{
  vec3_t scale;               /* scale factor */
  vec3_t translate;           /* translation vector */
  char name[16];              /* frame name */
  struct md2_vertex_t *verts; /* list of frame's vertices */
};
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: zammbi on August 15, 2010, 05:27:27 am
Question... I have a model which has broken up its walking animation into many animations. I know how to get all the walking animations sequences, but how do I merge these into 1 animation sequence? Or a helpful method could be
animate(float index,int[] seq) which temp merges(and caches) all those sub sequences in order to animate.
Title: Re: Object3D.getAnimationSequence(int index) and Animation.getName()
Post by: zammbi on August 16, 2010, 01:38:38 pm
Think I got it right, here's the code if anyone wants it.


Code: [Select]
public static void mergeAnimation(Object3D model){

ArrayList<Integer> sub = new ArrayList<Integer>();
       
        Animation anim = model.getAnimationSequence();
        int count = anim.getSequenceCount();
       
        int s=0;
        boolean firstFrame = false;
        for(int i = 1; i <= count; i++){ //0 is all animations.
        if(anim.getName(i).toLowerCase().startsWith("wb")){
        if(!firstFrame){
        s = anim.getSequenceBorders(i)[0];
        firstFrame = true;
        }
        sub.add(anim.getSequenceBorders(i)[1]);
        }
        }
               
        Mesh[] meshs=anim.getKeyFrames();
       
        Animation re=new Animation(sub.get(sub.size()-1));
       
       
        re.createSubSequence("walk");
        for (int i=0; i<sub.size(); i++){
        for (int p=s; p<=sub.get(i); p++) {
        re.addKeyFrame(meshs[p]);
        }
        s=sub.get(i)+1;
        }
        model.setAnimationSequence(re);
}

Edit: Fixed a bug.