Jump to content
  • Advertisement
Sign in to follow this  

MD3 Tags

This topic is 4149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm experimenting problems with MD3 Model format , i've a parser that parse geometric data , uv coords , and the normals but i can't figure how the models fit together with the tags i think i misunderstand something... I use Direct3D with Left handed here is in pseudocode what i do for clarity : Create a mesh Read all the keyframes data( verts,tris,uvs,) depending on the mesh name , read the tags wich consist of the three axes and the origin needed to construct a 4x4 Matrix and i build it like this : X.x | Y.x | Z.x | 0 X.y | Y.y | Z.y | 0 X.z | Y.z | Z.z | 0 dx | dy | dz | 1 with dx be the dot product between the origin and the X axis dy...ect... unfortunately this doesn't work , i've tried to inverse y and z values since quake uses Z as Y ... i have 2 questions , how tags are related to the models ? is the matrix that i build is correct ? does anyone has done an md3 parser for direct3D (ie left handed) and could give me some infos ? Thanx in advance for your interest in this topic...

Share this post

Link to post
Share on other sites
Basically the tags are used to link parts of a model into a full model. Generally, there is a torso model, legs model, head model and sometimes a weapon model.

The tags describe the position and orientation of other models that can be attached to a model. The way I handled the tags is using quaternions and spherically interpolating between the current frame and the next.

If you want to link models together and then render the full model, you have to create a set of pointers in the "base" model and make them point to the other model parts and draw things recursively. Here is the code I used to draw a linked MD3 model:
The code should help you understand how the tags are used

//render the linked models
for(int i=0; i<head.numTags; i++){
if(links != NULL){
Quaternion qQuat, qNextQuat, qInterpolatedQuat;

float *pMatrix, *pNextMatrix;

float finalMatrix[16] = {0};

//find the interpolated tag position
pos[0] = tags[offset+i].origin[0] + this->t*(tags[nextOffset+i].origin[0] - tags[offset+i].origin[0]);
pos[1] = tags[offset+i].origin[1] + this->t*(tags[nextOffset+i].origin[1] - tags[offset+i].origin[1]);
pos[2] = tags[offset+i].origin[2] + this->t*(tags[nextOffset+i].origin[2] - tags[offset+i].origin[2]);

//get pointers to the rotation matrices for the tags
pMatrix = &tags[offset+i].axis[0][0];
pNextMatrix = &tags[nextOffset+i].axis[0][0];

//create quaternions from the matrices

//interpolate between the quaternions and make into a matrix
qInterpolatedQuat = qQuat.slerp(qQuat, qNextQuat, this->t);
qInterpolatedQuat.createMatrix( finalMatrix );

finalMatrix[12] = pos[0];

finalMatrix[13] = pos[1];

finalMatrix[14] = pos[2];

//multiply the matrices to get to the tag position with rotation
//and draw the linked model

glMultMatrixf( finalMatrix );



If you have any more problems, just ask.

Share this post

Link to post
Share on other sites
Thanx for the reply , but when i parse the model :

i load head.md3 and i got tag inside for the head...
i load upper.md3 i got tag inside for the torso and the head too...
i load lower.md3 i got tag for just torso

wich tags to use in rendering ?
in fact i think there is an order in attachments ? , i attach the head to torso using the tags named tag_head found in upper.md3
i attach the legs to torso using the tags named tag_torso found in lower.md3

My other question is , is the matrix well builted for D3D (i know opengl is column major wereas D3D is rowmajor)

Thank you for your help.

Share this post

Link to post
Share on other sites
You can attach the models in any order, it doesn't matter. The way I set up my links was having the torso as the "base" model, and attach the head and legs to it. Then when I render the torso, I check if there is head model and render the head if its there, similarly for the legs. The tags are only there to show where and what orientation the attached models should be, they are usually NOT rendered. The only time a tag might be rendered is if you are creating a Model Viewer, just to show where the tags are.

What you should do is have a base MD3Mesh class or something that loads the .md3 files, then create another class called something like Character that has 3 MD3Mesh variables, one for the head, torso and legs (and if you want one for the weapon). That would be the easiest way to "link" a model together.

As for the matrix, I don't know if you have to modify it for D3D (I did mine in OpenGL). But if you use quaternions, it shouldn't matter whether it is in D3D or OpenGL. It would be simple to try, see if the matrix pulled from the tags will work in D3D without modifications.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!