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