fix: parentIndex is relative to current bone index

This commit is contained in:
Jan 2024-08-10 20:47:58 +02:00
parent f653530714
commit 75e22b1750
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
2 changed files with 6 additions and 3 deletions

View File

@ -314,10 +314,13 @@ namespace
// Other boneInfo data is filled when calculating bone bounds
xmodel.boneInfo[boneIndex].collmap = -1;
if (xmodel.numRootBones < boneIndex)
if (xmodel.numRootBones <= boneIndex)
{
const auto nonRootIndex = boneIndex - xmodel.numRootBones;
xmodel.parentList[nonRootIndex] = static_cast<unsigned char>(bone.parentIndex.value_or(0u));
const auto parentBoneIndex = static_cast<unsigned char>(bone.parentIndex.value_or(0u));
assert(parentBoneIndex < boneIndex);
xmodel.parentList[nonRootIndex] = static_cast<unsigned char>(boneIndex - parentBoneIndex);
auto& trans = xmodel.trans[nonRootIndex];
trans.x = bone.localOffset[0];

View File

@ -136,7 +136,7 @@ namespace
if (model->partClassification[boneNum])
{
if (boneNum < model->numRootBones
|| model->partClassification[model->parentList[boneNum - model->numRootBones]] != model->partClassification[boneNum])
|| model->partClassification[boneNum - model->parentList[boneNum - model->numRootBones]] != model->partClassification[boneNum])
{
std::cerr << std::format("Part: {:02} = {}\n", model->partClassification[boneNum], bone.name);
}