mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-04-21 10:58:44 +00:00
fix: properly dump gltf with root node in models with more than one root bone
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#include <deque>
|
||||
#include <exception>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <numbers>
|
||||
@@ -451,7 +450,7 @@ namespace
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void ApplyNodeMatrixTRS(const JsonNode& node, float (&localOffsetRhc)[3], float (&localRotationRhc)[4], float (&scaleRhc)[3])
|
||||
void ApplyNodeMatrixTRS(const JsonNode& node, float (&localOffsetRhc)[3], float (&localRotationRhc)[4], float (&scaleRhc)[3]) const
|
||||
{
|
||||
const auto matrix = Eigen::Matrix4f({
|
||||
{(*node.matrix)[0], (*node.matrix)[4], (*node.matrix)[8], (*node.matrix)[12]},
|
||||
@@ -492,7 +491,7 @@ namespace
|
||||
scaleRhc[2] = matrix.block<3, 1>(0, 2).norm();
|
||||
}
|
||||
|
||||
void ApplyNodeSeparateTRS(const JsonNode& node, float (&localOffsetRhc)[3], float (&localRotationRhc)[4], float (&scaleRhc)[3])
|
||||
void ApplyNodeSeparateTRS(const JsonNode& node, float (&localOffsetRhc)[3], float (&localRotationRhc)[4], float (&scaleRhc)[3]) const
|
||||
{
|
||||
if (node.translation)
|
||||
{
|
||||
@@ -630,7 +629,7 @@ namespace
|
||||
const auto skinBoneOffset = static_cast<unsigned>(common.m_bones.size());
|
||||
common.m_bones.resize(skinBoneOffset + skin.joints.size());
|
||||
|
||||
const Eigen::Vector3f defaultTranslation(0.0f, 0.0f, 0.0f);
|
||||
constexpr Eigen::Vector3f defaultTranslation(0.0f, 0.0f, 0.0f);
|
||||
const Eigen::Quaternionf defaultRotation(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
constexpr float defaultScale[3]{1.0f, 1.0f, 1.0f};
|
||||
|
||||
|
||||
@@ -164,10 +164,10 @@ namespace
|
||||
|
||||
const auto meshCount = xmodel.m_objects.size();
|
||||
for (auto meshIndex = 0u; meshIndex < meshCount; meshIndex++)
|
||||
rootNode.children->push_back(m_first_mesh_node + meshIndex);
|
||||
rootNode.children->emplace_back(m_first_mesh_node + meshIndex);
|
||||
|
||||
if (!xmodel.m_bones.empty())
|
||||
rootNode.children->push_back(m_first_bone_node);
|
||||
for (auto rootBoneIndex = 0u; rootBoneIndex < m_root_bone_count; rootBoneIndex++)
|
||||
rootNode.children->emplace_back(m_first_bone_node + rootBoneIndex);
|
||||
|
||||
m_root_node = static_cast<unsigned>(gltf.nodes->size());
|
||||
gltf.nodes->emplace_back(std::move(rootNode));
|
||||
@@ -278,6 +278,7 @@ namespace
|
||||
|
||||
const auto boneCount = common.m_bones.size();
|
||||
m_first_bone_node = static_cast<unsigned>(gltf.nodes->size());
|
||||
m_root_bone_count = 0;
|
||||
for (auto boneIndex = 0u; boneIndex < boneCount; boneIndex++)
|
||||
{
|
||||
JsonNode boneNode;
|
||||
@@ -310,6 +311,11 @@ namespace
|
||||
translation = inverseParentRotation * translation;
|
||||
rotation = inverseParentRotation * rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(m_root_bone_count == boneIndex);
|
||||
m_root_bone_count++;
|
||||
}
|
||||
rotation.normalize();
|
||||
|
||||
boneNode.name = bone.name;
|
||||
@@ -679,6 +685,7 @@ namespace
|
||||
unsigned m_first_mesh_node = 0u;
|
||||
unsigned m_root_node = 0u;
|
||||
unsigned m_first_bone_node = 0u;
|
||||
unsigned m_root_bone_count = 0u;
|
||||
unsigned m_position_accessor = 0u;
|
||||
unsigned m_normal_accessor = 0u;
|
||||
unsigned m_uv_accessor = 0u;
|
||||
|
||||
Reference in New Issue
Block a user