mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-16 09:13:50 +00:00
fix(rendering): remap M2 vertex bone indices through bone lookup table
M2 vertex bone indices are indices into boneLookupTable, not direct bone array indices. Without remapping, vertices weighted to higher bone indices (cloak, cape, hair) get the wrong bone transform, causing vertices to project wildly outward from the character.
This commit is contained in:
parent
1feb6ea63f
commit
04ad88330f
2 changed files with 19 additions and 5 deletions
|
|
@ -1158,10 +1158,14 @@ bool M2Renderer::loadModel(const pipeline::M2Model& model, uint32_t modelId) {
|
|||
vertexData.push_back(w1);
|
||||
vertexData.push_back(w2);
|
||||
vertexData.push_back(w3);
|
||||
vertexData.push_back(static_cast<float>(std::min(v.boneIndices[0], uint8_t(127))));
|
||||
vertexData.push_back(static_cast<float>(std::min(v.boneIndices[1], uint8_t(127))));
|
||||
vertexData.push_back(static_cast<float>(std::min(v.boneIndices[2], uint8_t(127))));
|
||||
vertexData.push_back(static_cast<float>(std::min(v.boneIndices[3], uint8_t(127))));
|
||||
// Remap bone indices through the bone lookup table.
|
||||
// M2 vertex bone indices are lookup table indices, not direct bone indices.
|
||||
for (int j = 0; j < 4; j++) {
|
||||
uint8_t idx = v.boneIndices[j];
|
||||
uint16_t actual = (idx < model.boneLookupTable.size())
|
||||
? model.boneLookupTable[idx] : 0;
|
||||
vertexData.push_back(static_cast<float>(std::min(actual, uint16_t(127))));
|
||||
}
|
||||
}
|
||||
|
||||
// Upload vertex buffer to GPU
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue