md3 question

Not really sure where to put this, I think we need a general 3d graphics or opengl forum… well this will do for now.

I’m writing an md3 loader/renderer and I’ve come to a problem when it comes to attaching separate model pieces. I’m hoping someone who has used md3s before can help me, but first some review on the issue: md3s use something called ‘tags’ to attach separate model pieces, generally the pieces are: head, torso, and legs but could be anything I assume. Each model part has a set of tags, each of which has a name that specifies what model part the tag effects. The tag itself stores a position and orientation (as a 3x3 matrix). Its my understanding that if a model part has a tag with a name specifying another piece, than that other piece’s position and orientation are always dependant on the piece with the tag.

The part I’m having trouble with is keeping the pieces synced together. I know how to transform the pieces according to the matrix and translate them into place, but I don’t understand how I can update the pieces when the ‘controller’ piece animates. For example, there is a ‘torso’ model part with a tag: tag_weapon and there is a weapon model part. When the torso (which actually makes up the midsection and both arms of the model) animates, the arms move up and down and the gun should stay oriented relative to the position of the right hand. I don’t understand how I can detect the change in the torso’s position and orientation in order to update the pieces which are dependant on it. The problem seems even more complex since the gun should really be positioned relative to the hand (which is a part of the torso), but the weapon is only attached to the torso piece, the file itself says nothing about the model’s hand.

This is the sort of problem that makes me think I’m missing something big because I just see no solution. Is there some other part to the md3 format that gives more info about how these various pieces are connected? or maybe I’m supposed to calculate the change in position and orientation of model parts in order to apply it to its dependancies? I have seen this model animated correctly with another program, so the file itself (or files rather) is valid. Hopefully someone can give me some insight :slight_smile: thanks.

Well, you need some kind of hashtable for the tags that points to the right objects.

If this is Java3D you can look at what I did for NWN mdl files which are very similar, at least in concept, to what you described.

Thats all in the JNWN codebase. If your curious abt various parts I can answer questions…

I’ve already got the hashtable bit taken care of :slight_smile: the problem I’m having is detecting the change in orientation and position of the controller model part so that I can apply it to dependant model parts. When the md3 animates, its just switching between complete sets of vertices, I don’t see how I can derive the transformation thats taking place. I also think it may not be possible to do that… the torso is dependant on the position and orientation of the legs for example, but there can be no single transformation that takes place from frame to frame because the legs move independantly of one another, one leg may bend a bit forward and the other a bit backward in a single frame. Perhaps I’m missing something so fundamental that my question isn’t quite making sense :-[

I believe in the MD3 format there are actually multiple transforms/matricies per tag, i.e. as the key frame changes so does the transform for a tag (which you’d have to interpolate between as well).

Just checking my own Java3D loader code…

Yep - the tags segment is built up of:

F * T * Tag

Where F is the number of frames, T is the number of tags in the model and Tag is the tag structure.

So you’ve got say your 3 parts… when a a remote part is updated you pick out the transform you need for the current animation frame. This means of course that your weapon model and torso model for instance need to be synced.

Kev

problem solved on irc, thanks to kev :slight_smile:

the problem was that tags for every frame are indeed stored in the file, I just didn’t notice it before because there is a field in the header that says NUM_TAGS which is equal to 3, but there are really 3 for every frame. So I was only reading in 3 and then skipping to the next section of the file :frowning:

Oh its THAT kind of animation.

The answer is you dont do it with transforms. These are effectively morphs.

You might want to look at the MorphBehavior in J3D. basically it takes 2 seperate models that have the same number of verticies and interpolates a third model that also has the same point count between the point positions of the two targets

I see what you mean, but in this case it really is transforms.

You have a series of models - gun - body - head, each is a mesh that has a series of keyframes that you are morphing between (thats how I did it in the Java3D loader too :)). However, the relationship between the parts is decribed in the model format as transforms… i.e. if the body has changed to the keyframe where the arm is at angle X the gun model should be at this angle/transform to the body.

Kev

Okay, well he said it wasnt.

So I was right answering hsi question, he was just wrong about his data (or describing it in a very confused manner) ;D

LOL! Absolutely - dead on. :slight_smile:

Kev