mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
chore: fix invalid sign when loading gltf
This commit is contained in:
parent
0bd581ef75
commit
36bc3cf7a3
@ -467,8 +467,8 @@ namespace
|
|||||||
if (node.rotation)
|
if (node.rotation)
|
||||||
{
|
{
|
||||||
bone.localRotation.x = (*node.rotation)[0];
|
bone.localRotation.x = (*node.rotation)[0];
|
||||||
bone.localRotation.y = (*node.rotation)[2];
|
bone.localRotation.y = -(*node.rotation)[2];
|
||||||
bone.localRotation.z = -(*node.rotation)[1];
|
bone.localRotation.z = (*node.rotation)[1];
|
||||||
bone.localRotation.w = (*node.rotation)[3];
|
bone.localRotation.w = (*node.rotation)[3];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -210,46 +210,46 @@ namespace
|
|||||||
return textureIndex;
|
return textureIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateSkeletonNodes(JsonRoot& gltf, const XModelCommon& xmodel)
|
void CreateSkeletonNodes(JsonRoot& gltf, const XModelCommon& common)
|
||||||
{
|
{
|
||||||
if (xmodel.m_bones.empty())
|
if (common.m_bones.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!gltf.nodes.has_value())
|
if (!gltf.nodes.has_value())
|
||||||
gltf.nodes.emplace();
|
gltf.nodes.emplace();
|
||||||
|
|
||||||
const auto boneCount = xmodel.m_bones.size();
|
const auto boneCount = common.m_bones.size();
|
||||||
m_first_bone_node = gltf.nodes->size();
|
m_first_bone_node = gltf.nodes->size();
|
||||||
for (auto boneIndex = 0u; boneIndex < boneCount; boneIndex++)
|
for (auto boneIndex = 0u; boneIndex < boneCount; boneIndex++)
|
||||||
{
|
{
|
||||||
JsonNode boneNode;
|
JsonNode boneNode;
|
||||||
const auto& bone = xmodel.m_bones[boneIndex];
|
const auto& bone = common.m_bones[boneIndex];
|
||||||
|
|
||||||
Eigen::Vector3f translation(bone.globalOffset[0], bone.globalOffset[2], -bone.globalOffset[1]);
|
Eigen::Vector3f translation(bone.globalOffset[0], bone.globalOffset[1], bone.globalOffset[2]);
|
||||||
Eigen::Quaternionf rotation(bone.globalRotation.w, bone.globalRotation.x, bone.globalRotation.z, -bone.globalRotation.y);
|
Eigen::Quaternionf rotation(bone.globalRotation.w, bone.globalRotation.x, bone.globalRotation.y, bone.globalRotation.z);
|
||||||
if (bone.parentIndex)
|
if (bone.parentIndex)
|
||||||
{
|
{
|
||||||
const auto& parentBone = xmodel.m_bones[*bone.parentIndex];
|
const auto& parentBone = common.m_bones[*bone.parentIndex];
|
||||||
const auto inverseParentRotation =
|
const auto inverseParentRotation =
|
||||||
Eigen::Quaternionf(parentBone.globalRotation.w, parentBone.globalRotation.x, parentBone.globalRotation.z, -parentBone.globalRotation.y)
|
Eigen::Quaternionf(parentBone.globalRotation.w, parentBone.globalRotation.x, parentBone.globalRotation.y, parentBone.globalRotation.z)
|
||||||
.normalized()
|
.normalized()
|
||||||
.inverse()
|
.inverse()
|
||||||
.normalized();
|
.normalized();
|
||||||
|
|
||||||
translation -= Eigen::Vector3f(parentBone.globalOffset[0], parentBone.globalOffset[2], -parentBone.globalOffset[1]);
|
translation -= Eigen::Vector3f(parentBone.globalOffset[0], parentBone.globalOffset[1], parentBone.globalOffset[2]);
|
||||||
translation = inverseParentRotation * translation;
|
translation = inverseParentRotation * translation;
|
||||||
rotation = inverseParentRotation * rotation;
|
rotation = inverseParentRotation * rotation;
|
||||||
}
|
}
|
||||||
rotation.normalize();
|
rotation.normalize();
|
||||||
|
|
||||||
boneNode.name = bone.name;
|
boneNode.name = bone.name;
|
||||||
boneNode.translation = std::to_array({translation.x(), translation.y(), translation.z()});
|
boneNode.translation = std::to_array({translation.x(), translation.z(), -translation.y()});
|
||||||
boneNode.rotation = std::to_array({rotation.x(), rotation.y(), rotation.z(), rotation.w()});
|
boneNode.rotation = std::to_array({rotation.x(), rotation.z(), -rotation.y(), rotation.w()});
|
||||||
|
|
||||||
std::vector<unsigned> children;
|
std::vector<unsigned> children;
|
||||||
for (auto maybeChildIndex = 0u; maybeChildIndex < boneCount; maybeChildIndex++)
|
for (auto maybeChildIndex = 0u; maybeChildIndex < boneCount; maybeChildIndex++)
|
||||||
{
|
{
|
||||||
if (xmodel.m_bones[maybeChildIndex].parentIndex && *xmodel.m_bones[maybeChildIndex].parentIndex == boneIndex)
|
if (common.m_bones[maybeChildIndex].parentIndex && *common.m_bones[maybeChildIndex].parentIndex == boneIndex)
|
||||||
children.emplace_back(maybeChildIndex + m_first_bone_node);
|
children.emplace_back(maybeChildIndex + m_first_bone_node);
|
||||||
}
|
}
|
||||||
if (!children.empty())
|
if (!children.empty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user