我正在使用BREEder的THREE.js导出程序将装配模型导出到我的应用程序中。但是生成的JSON数据中没有骨骼矩阵。作为样本:
{
"name": "W_Hips",
"rotq": [-0.845519,0.00128,5.9e-05,0.533943],
"scl": [1,0.990953,0.959433],
"pos": [0.00022,5.09513,-0.466128],
"parent": -1
}
如何使用此数据为骨骼生成绑定矩阵?
答案 0 :(得分:0)
嗯,一切都太容易了
glm::mat4 l_translate = glm::translate(glm::mat4(1.f),m_vPosition); // "pos" from JSON data
glm::mat4 l_rot = glm::mat4_cast(m_qRotation); // "rotq" from JSON data
glm::mat4 l_scale = glm::scale(glm::mat4(1.f),m_vScale); // "scl" from JSON data
glm::mat4 l_local = l_translate*l_rot*l_scale;
if(m_parent == NULL) m_matrix = l_local;
else m_matrix = m_parent->m_matrix*l_local;
m_bindMatrix = glm::inverse(m_matrix);
for(size_t i=0; i < m_childBoneVector.size(); i++) m_childBoneVector[i]->generateBindPose(); // same calculation for children