fix: auto generate armature when imported gltf has none

This commit is contained in:
Jan 2024-09-08 13:55:50 +02:00
parent bc81245322
commit 63556848c1
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C

View File

@ -262,6 +262,33 @@ namespace
return nullptr;
}
static void AutoGenerateArmature(XModelCommon& common)
{
assert(common.m_bones.empty());
assert(common.m_bone_weight_data.weights.empty());
assert(common.m_vertex_bone_weights.size() == common.m_vertices.size());
XModelBone rootBone{
"root",
std::nullopt,
{1.0f, 1.0f, 1.0f},
{0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 0.0f, 1.0f},
};
common.m_bones.emplace_back(rootBone);
XModelBoneWeight rootWeight{0, 1.0f};
common.m_bone_weight_data.weights.emplace_back(rootWeight);
for (auto& vertexBoneWeights : common.m_vertex_bone_weights)
{
vertexBoneWeights.weightOffset = 0u;
vertexBoneWeights.weightCount = 1u;
}
}
static void ApplyBasePose(DObjAnimMat& baseMat, const XModelBone& bone)
{
baseMat.trans.x = bone.globalOffset[0];
@ -713,6 +740,9 @@ namespace
return false;
}
if (common->m_bones.empty())
AutoGenerateArmature(*common);
if (lodNumber == 0u)
{
if (!ApplyCommonBonesToXModel(jLod, xmodel, lodNumber, *common))