尝试实现索具:
<visual_scene id="Scene" name="Scene">
<node id="Armature" name="Armature" type="NODE">
<matrix sid="transform">1 0 0 0 0 0 1 0 0 -1 0 0 0 0 0 1</matrix>
<node id="Armature_Bone" name="Bone" sid="Bone" type="JOINT">
<matrix sid="transform">0.3299372 0.944003 -1.78814e-7 0 -4.76837e-7 0 -1 0 -0.944003 0.3299374 3.8743e-7 0 0 0 0 1</matrix>
<node id="Armature_Bone_001" name="Bone.001" sid="Bone_001" type="JOINT">
<matrix sid="transform">0.886344 -0.4630275 3.31894e-7 2.98023e-8 0.4630274 0.886344 -1.86307e-7 1.239941 -2.07907e-7 3.18808e-7 1 -2.84217e-14 0 0 0 1</matrix>
<node id="Armature_Bone_002" name="Bone.002" sid="Bone_002" type="JOINT">
<matrix sid="transform">0.9669114 0.2551119 -1.83038e-7 -1.19209e-7 -0.2551119 0.9669115 1.29195e-7 1.219687 2.09941e-7 -7.82246e-8 1 0 0 0 0 1</matrix>
<node id="Armature_Bone_003" name="Bone.003" sid="Bone_003" type="JOINT">
<matrix sid="transform">0.8538353 0.5205433 1.0139e-7 -1.19209e-7 -0.5205433 0.8538353 2.4693e-7 1.815649 4.19671e-8 -2.63615e-7 1 5.68434e-14 0 0 0 1</matrix>
现在,如果我将每个骨骼的矩阵设置为 glm::mat4(1),我会得到:但是,如果我尝试乘以关节父变换,就像在 Thin Matrix rigging tutorial 中一样,我会得到非常奇怪的结果:
void SkelManager::setTposeTransforms(std::vector<Joint>& _reference)
{
for (int child = 0; child < _reference.size(); child++)
{
if (_reference[child].parent == -1)
{
//_reference[child].tPose = glm::mat4(1);
_reference[child].tPose = _reference[child].transform;
}
for (int parent = 0; parent < _reference.size(); parent++)
if (_reference[child].parent == parent)
{
//_reference[child].tPose = glm::mat4(1);
_reference[child].tPose = _reference[parent].tPose * _reference[child].transform;
}
}
}
请帮忙,我已经坚持了几个星期,但我没有成功,无论我多么努力地搜索网络,我都找不到任何有用的东西,关于我可能做错了什么的任何想法?
最佳答案
I use glm::make_mat4(tmpFloatArray), and then I transpose it, not sure if this is the correct way):
请参阅 COLLADA 规范中关于矩阵的说明:
Matrices in COLLADA are column matrices in the mathematical sense. These matrices are written in row- major order to aid the human reader. See the example.
所以是的,你需要转置它。
加载 COLLADA 的骨骼动画并不难。跟着这些步骤:
进口方:
渲染面:
FinalJointTrans4x4 = JointTransform * InvBindPose * BindShapeMatrix
union 转换 是与 parent 相乘的变换...绑定(bind)姿势 (或 InvBindMatrix)是您从 skin->joints->INV_BIND_MATRIX 为每个关节读取的变换
绑定(bind)形状矩阵 是您从 skin->bind_shape_matrix 读取的变换
也许(来自 http://github.com/recp/gk ):
...
mat4 skinMat;
skinMat = uJoints[JOINTS.x] * WEIGHTS.x
+ uJoints[JOINTS.y] * WEIGHTS.y
+ uJoints[JOINTS.z] * WEIGHTS.z
+ uJoints[JOINTS.w] * WEIGHTS.w;
pos4 = skinMat * pos4;
norm4 = skinMat * norm4;
...
#ifdef JOINT_COUNT
gl_Position = VP * pos4;
#else
gl_Position = MVP * pos4;
#endif
...
我可能会忘记提及其他细节(稍后我可能会编辑答案),但这必须有很大帮助。PS:有一个名为 AssetKit ( http://github.com/recp/assetkit ) 的库,如果您愿意,可以使用它来加载 COLLADA 文件。
关于c++ - 如何计算 COLLADA 文件的父子 union 变换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62971356/