# MD3 Tags

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

## 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 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:
EDIT:

//render the linked modelsfor(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		qQuat.createFromMatrix(pMatrix,3);		qNextQuat.createFromMatrix(pNextMatrix,3);		//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		glPushMatrix();                	glMultMatrixf( finalMatrix );					                	links->render();            		            	glPopMatrix();				}}

If you have any more problems, just ask.

##### Share on other sites
Thanx for the reply , but when i parse the model :

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)

##### 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.

• 10
• 18
• 14
• 18
• 15