SirKnight

11-24-2002, 07:25 PM

I found some code recently on flipcode that loads the doom 3 md5mesh files and there seems to be a few things I don't quite understand. I searched around but all I found is the math to animate a skin based off of the bones and weights which is not what I'm confused about. Ok in this md5mesh loading code it has a function called BuildVertices which some how computed the vertices of the mesh from the weights and bones. This is what I'm confused about. Before I say any more here is that code:

void BuildVertices(void)

{

for (int i = 0; i < g_NbMeshes; i++)

{

Mesh& mesh = g_Meshes[i];

for (int j = 0; j < mesh.nb_vertices; j++)

{

Vertex& v = mesh.vertices[j];

v.x = 0;

v.y = 0;

v.z = 0;

for (int k = 0; k < v.weight_count; k++)

{

Weight& w = mesh.weights[v.weight_index + k];

Bone& b = g_Bones[w.bone];

v.x += (b.rot[0] * w.x + b.rot[3] * w.y + b.rot[6] * w.z + b.pos[0]) * w.t;

v.z += (b.rot[1] * w.x + b.rot[4] * w.y + b.rot[7] * w.z + b.pos[1]) * w.t;

v.y += (b.rot[2] * w.x + b.rot[5] * w.y + b.rot[8] * w.z + b.pos[2]) * w.t;

}

}

}

}

Its the last part where they compute the vertices from the bone's rotations and the weights and whatever w.t is. I don't seem to understand how the vertices are being computed like this. Could someone explain this to me or show me a paper that talkes about this? Like I say all I have found is papers talking about how to transform each vertex by the bones and weights in the vertex program, not anything about this.

Thanks.

-SirKnight

void BuildVertices(void)

{

for (int i = 0; i < g_NbMeshes; i++)

{

Mesh& mesh = g_Meshes[i];

for (int j = 0; j < mesh.nb_vertices; j++)

{

Vertex& v = mesh.vertices[j];

v.x = 0;

v.y = 0;

v.z = 0;

for (int k = 0; k < v.weight_count; k++)

{

Weight& w = mesh.weights[v.weight_index + k];

Bone& b = g_Bones[w.bone];

v.x += (b.rot[0] * w.x + b.rot[3] * w.y + b.rot[6] * w.z + b.pos[0]) * w.t;

v.z += (b.rot[1] * w.x + b.rot[4] * w.y + b.rot[7] * w.z + b.pos[1]) * w.t;

v.y += (b.rot[2] * w.x + b.rot[5] * w.y + b.rot[8] * w.z + b.pos[2]) * w.t;

}

}

}

}

Its the last part where they compute the vertices from the bone's rotations and the weights and whatever w.t is. I don't seem to understand how the vertices are being computed like this. Could someone explain this to me or show me a paper that talkes about this? Like I say all I have found is papers talking about how to transform each vertex by the bones and weights in the vertex program, not anything about this.

Thanks.

-SirKnight