• ### Announcements

• #### Wondering what's new and changed at GameDev.net?06/20/17

Check out the latest Staff Blog update that talks about what's changed, what's new, and what's up with these "Pixels".
Followers 0

# MD5 Skinned Mesh

## 6 posts in this topic

I'm following this tutorial: http://3dgep.com/?p=1053

So far everything works, things render as expected. But i'm having a hard time understanding the PrepareMesh method:

void MD5Model::PrepareMesh(MD5Mesh& mesh) {
mesh.m_vPositionBuffer.clear();
mesh.m_vTexCoordBuffer.clear();

for (unsigned int i = 0; i < mesh.m_vVerts.size(); ++i) {
MD5Vertex& vert = mesh.m_vVerts[i];

vert.position = Vector();
vert.normal = Vector();
vert.position.w = 1.0f;
vert.normal.w = 0.0f;

for (int j = 0; j < vert.weightCount; ++j) {
MD5Weight& weight = mesh.m_vWeights[vert.startWeight + j];
MD5Joint& joint = m_vJoints[weight.jointId];

Vector rotPos = joint.orientation.Inverse() * weight.position;
vert.position += (joint.position + rotPos) * weight.bias;
}

mesh.m_vPositionBuffer.push_back(vert.position);
mesh.m_vTexCoordBuffer.push_back(vert.uv);
}
}


The vertex has no position before this method. From what i gather, weight.position is the position of the vertex in bone space local to the bone we're looking at. This leads me to my question, do we have one unique weight for every vertex per bone it attaches to? Or can vertices share weights?

Also, is this standard? Is there perhaps another file format that does vertex with a different approach? This seems so wasteful for some reason, but if it can't be worked around, oh well.

0

##### Share on other sites

What you have there is cpu skinning.

The vertex positions are calculated by the joint data and the weight, usually a vertex can be affected by multiple joints

the weight is giving information about how much a given joint affects a vertex.

If you do not need to access the transformed vertex data you can use GPU skinning,

there is a good article about gpu skinning in this gpu gems article, right after the morph targets.

Also in the comments of the tutorial you mentioned is a link to a gpu skinned version of it, which may be more helpful to you:

http://3dgep.com/?p=1053#comment-1465

Edited by LJ_1102
1

##### Share on other sites

this is actually a pretty typical approach.

one optimization strategy (if not done already) is basically to cache all the vertex positions for a given frame (since a model generally wont move within a frame). this way, if the model is being drawn multiple times, this avoids recalculating it.

similarly, if the model is not moving or is far away, then generally this can be skipped for many frames (say, we only use keyframes rather than interpolated frames, and skip updating positions for if using the same keyframe). likewise, updates can be skipped for models which aren't currently visible, ...

also, when modeling, general things like being conservative with triangle counts and numbers of weights and similar may apply, ...

1

##### Share on other sites

Thanks guys that answered most of my questions, but there is still one glaring thing i don't get.

Why do the weights have a position? And why is the vertex position derived from that?

Wouldn't it make more sense (and take up less data) if a weight was just a float and a joint id?

Then instead of deriving the vertex position from all these offsets, transform the vertex into each joints space, and add up all the transforms (multiplied by the bias) to get a final position?

The format just seems backwards....

0

##### Share on other sites

hy do the weights have a position? And why is the vertex position derived from that?

This is md5 specific, md5 does not store the vertex positions themselfs.

The vertex positions need to be calculated from the weights.

I've never parsed MD5 meshes myself, maybe this link is helpful to you:

http://tfc.duke.free.fr/coding/md5-specs-en.html

Wouldn't it make more sense (and take up less data) if a weight was just a float and a joint id?

Since a vertex can have multiple joints affecting it you'll have multiple weights for each _vertex_.

Checkout the sturcture in the linked gpu gems article, not about morph target but about gpu vertex skinning.

The format just seems backwards....

It is :)

Edited by LJ_1102
1

##### Share on other sites

Thanks LJ, it's the MD5 specific part i was missing.

Are there any formats that are widely used but laid out differently?

I have the MD5 animation working, but i don't like the format very much...

0

##### Share on other sites

You could use collada, but parsing it can become pretty much a pain because its so flexible the different

exporters from tools like 3DS Max, Lightwave, Blender and everything are very inconsistent.

The 3ds fileformat is also widely used for assets and very well documented.

Depending on the language you use you could implement Assimp and let it do the parsing for you.

0