2016-11-25 121 views
1

我正在從本教程中脫離http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html 不幸的是,它並不能解釋Assimp如何派生它的骨骼數據。 我知道全局逆變換是默認的矩陣值混合器用於將y值設置爲z值,將z值設置爲-y。 (或者至少這是我的測試車型的MD5用什麼)骨骼動畫:如何手動派生Assimp骨骼偏移矩陣

GlobalInverseTransform = aiScene->mRootNode->mTransformation; 

我想了解如何Assimp派生偏移矩陣或反綁定從MD5文件存在。例如BobLampClean.md5mesh有32個關節和32偏移矩陣

aiMesh->mBones[i]->mOffsetMatrix; 

從我通過他們計算它是這樣的偏移矩陣其他樣品在網上看到...

void ComputeQuatW(glm::quat& quat) 
{ 
float t = 1.0f - (quat.x * quat.x) - (quat.y * quat.y) - (quat.z * quat.z); 
if (t < 0.0f) 
    quat.w = 0.0f; 
else 
    quat.w = -sqrtf(t); 
} 

glm::mat4 rotation, rotationInv, translationInv, offsetmatrix; 
glm::quat MyQuaternion; 
//here I chose an arbitrary joint and hard coded its orientation and position 
MyQuaternion = glm::quat(glm::quat(-0.535591, -0.462288, -0.534983, 1)); 
ComputeQuatW(MyQuaternion); 
glm::mat4 RotationMatrix = glm::toMat4(MyQuaternion); 
rotationInv = glm::transpose(RotationMatrix); 
translationInv = glm::translate(translationInv, glm::vec3(-0.014076, -2.592741, -30.241238)); 
offsetmatrix = rotationInv*translationInv; 

我已經輸出每個這些偏移矩陣comapre與Assimp的骨骼矩陣,但無濟於事。我不太確定我在做什麼錯...

編輯更新:好所以我做我的操作不正確,我正在調試一個工作代碼示例,不使用Assimp,它可以複製與Assimp的數據相同的值。我將更新如何正確計算數據。

回答

1

答案:要創建綁定姿勢,我使用了下面的代碼。數學類和函數由本系列的作者創建,這就是他如何創建offsetMatrices,這是Assimp如何構建它的骨骼偏移矩陣。他的數學函數可以在這裏找到https://www.youtube.com/watch?v=AqavYcdB7tg&t=3474s在評論部分。對於通過將四元數轉換爲旋轉矩陣來創建它的每個骨骼,進行轉置,然後將翻譯矩陣轉換爲位置的倒數,然後將兩者結合起來。

"sheath" 0 (11.004813 -3.177138 31.702473) (0.307041 -0.578614 0.354181) 
//Example bone offset matrix. 

四元數是最後一組3個數字,您計算W分量然後執行操作。

mlQuaternionToMat4(rotation, joint.orientation); 
mlTransposeMat4(rotationInv, rotation); 

這裏您將使用第一組3個數字作爲關節位置。

mlTranslationMat4(translationInv, -joint.position[0], -   
joint.position[1], -joint.position[2]); 
mlMultiplyMat4_2(finalmatrix, rotationInv, translationInv); 
//finalMatrix = aiMesh->bone[sheath]->offsetMatrix