【发布时间】:2021-03-04 10:30:33
【问题描述】:
我正在尝试让动画适用于复杂的 glTF 模型我正在尝试RiggedFigure。
特别是我正在尝试计算globalTransformOfJointNode,如下所述:https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_020_Skins.md
为此我有这个功能:
std::vector<Eigen::Matrix4f> GetGlobalJointMatrices(
const std::vector<Eigen::Matrix4f>& local_matrices,
const std::vector<Eigen::Matrix4f>& animation_matrices,
const std::map<int, int>& skeleton,
const int start_joint)
{
std::vector<Eigen::Matrix4f> skeleton_matrices(skeleton.size());
skeleton_matrices[0] = Eigen::Matrix4f::Identity();
for(auto [child, parent]: skeleton)
{
skeleton_matrices[child - start_joint] = skeleton_matrices[parent - start_joint] *
local_matrices[child - start_joint] * animation_matrices[child - start_joint];
}
return skeleton_matrices;
}
这里的local_matrices指的是骨架中每个节点的局部变换,如nodes数组中描述的那样。
animation_matrices 只是针对皮肤中节点的动画。
对于两个数组,由于节点是连续的,索引i 包含与节点i + start_joint 对应的值。我已验证动画加载正确且顺序正确。
这是这样做的结果:
skeleton_matrices[child - start_joint] = skeleton_matrices[parent - start_joint] * local_matrices[child - start_joint];
如果我尝试应用动画矩阵,我会得到:
将动画矩阵放在其他点会导致类似的行为。 我确定我没有错误地加载矩阵,例如这些是针对节点 6 和 10 的矩阵:
animation targetting node:10
rotation: 0.0245355 -0.319997 0.9446 0.0687827
translation: -0.00234646 -0.0661734 0.0278567
scales: 1 1 1
node 6:
animation targetting node:6
rotation: -0.0341418 -0.319178 0.946171 -0.0414678
translation: -0.00145852 -0.0661988 0.0278567
我去手动验证了这些值是正确的,它们是正确的。
我不明白出了什么问题。
【问题讨论】:
标签: c++ json animation graphics gltf