Merge pull request #255 from Laupetin/feature/omit-default-armature

feat: omit default armature when dumping xmodels
This commit is contained in:
Jan 2024-09-08 15:06:37 +02:00 committed by GitHub
commit d1abb46fc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 5 deletions

View File

@ -114,6 +114,44 @@ namespace
return potentialTextureDefs[0]->image;
}
bool HasDefaultArmature(const XModel* model, const unsigned lod)
{
if (model->numRootBones != 1 || model->numBones != 1)
return false;
const auto* surfs = &model->surfs[model->lodInfo[lod].surfIndex];
const auto surfCount = model->lodInfo[lod].numsurfs;
if (!surfs)
return true;
for (auto surfIndex = 0u; surfIndex < surfCount; surfIndex++)
{
const auto& surface = surfs[surfIndex];
if (surface.vertListCount != 1 || surface.vertInfo.vertsBlend)
return false;
const auto& vertList = surface.vertList[0];
if (vertList.boneOffset != 0 || vertList.triOffset != 0 || vertList.triCount != surface.triCount || vertList.vertCount != surface.vertCount)
return false;
}
return true;
}
void OmitDefaultArmature(XModelCommon& common)
{
common.m_bones.clear();
common.m_bone_weight_data.weights.clear();
common.m_vertex_bone_weights.resize(common.m_vertices.size());
for (auto& vertexWeights : common.m_vertex_bone_weights)
{
vertexWeights.weightOffset = 0u;
vertexWeights.weightCount = 0u;
}
}
void AddXModelBones(XModelCommon& out, const AssetDumpingContext& context, const XModel* model)
{
for (auto boneNum = 0u; boneNum < model->numBones; boneNum++)
@ -438,12 +476,20 @@ namespace
AllocateXModelBoneWeights(model, lod, out.m_bone_weight_data);
out.m_name = std::format("{}_lod{}", model->name, lod);
AddXModelBones(out, context, model);
AddXModelMaterials(out, materialMapper, model);
AddXModelObjects(out, model, lod, materialMapper);
AddXModelVertices(out, model, lod);
AddXModelVertexBoneWeights(out, model, lod);
AddXModelFaces(out, model, lod);
if (!HasDefaultArmature(model, lod))
{
AddXModelBones(out, context, model);
AddXModelVertexBoneWeights(out, model, lod);
}
else
{
OmitDefaultArmature(out);
}
}
void DumpObjMtl(const XModelCommon& common, const AssetDumpingContext& context, const XAssetInfo<XModel>* asset)

View File

@ -89,6 +89,10 @@ namespace
gltf.nodes.emplace();
m_mesh_node = gltf.nodes->size();
if (xmodel.m_bones.empty())
m_root_node = m_mesh_node;
gltf.nodes->emplace_back(std::move(meshNode));
}
@ -96,6 +100,9 @@ namespace
{
JsonNode rootNode;
if (xmodel.m_bones.empty())
return;
if (!xmodel.m_name.empty())
rootNode.name = std::format("{}_skel", xmodel.m_name);
@ -104,8 +111,6 @@ namespace
rootNode.children.emplace();
rootNode.children->push_back(m_mesh_node);
if (!xmodel.m_bones.empty())
rootNode.children->push_back(m_first_bone_node);
m_root_node = gltf.nodes->size();