2016-04-10 84 views
0

我一直試圖加載我的皮膚collada網格使用assimp過去幾天,但我有一個非常困難的時間。目前我只是試圖在沒有任何轉換或動畫的情況下將其渲染爲正常的「姿勢」,但網格變形很大。我認爲問題在於我的骨頭,而不是我的體重,所以我只發佈骨骼部分。Assimp計算骨骼

這是我骨加載代碼:

// this is done for every bone in a for loop: 
Bone new_bone; 

new_bone.name = std::string(bone->mName.data); 

aiMatrix4x4 b_matrix = bone->mOffsetMatrix; 
aiMatrix4x4 g_inv = scene->mRootNode->mTransformation; 
g_inv.Inverse(); // according to a tutorial, you have to multiply by inverse root 
b_matrix = b_matrix * g_inv; 
memcpy(new_bone.matrix, &b_matrix, sizeof(float) * 16); 

Bones.push_back(new_bone); 

然後,我只是用

glUniformMatrix4fv(MatrixArray, bone_count, GL_FALSE, &MATRIX_BUFFER[0][0][0]); 

寄這封信給我的着色而在頂點着色器與應用它:

mat4 Bone = V_MatrixArray[int(Indicies[0])] * Weights[0]; 
Bone += V_MatrixArray[int(Indicies[1])] * Weights[1]; 
Bone += V_MatrixArray[int(Indicies[2])] * Weights[2]; 
Bone += V_MatrixArray[int(Indicies[3])] * Weights[3]; 

vec4 v = Bone * vec4(Vertex, 1); 
gl_Position = MVP * vec4(v.xyz, 1); 

此代碼主要工作,但我的網格很變形....它看起來像這樣:

enter image description here

根據迄今所做的啓發式算法IVE:

  • 我不需要轉我的矩陣,因爲assimp使用OpenGL列爲主

  • 我並不需要閱讀但由於它們是 動畫

如果我誤解了最後2件事,請糾正我。

回答

0

我設法解決它。結果你DO需要讀取節點,即使是沒有動畫的簡單綁定姿勢。對於有此問題的任何未來讀者,每個骨骼矩陣= root_node_inverse *矩陣從節點heirechy *骨骼偏移矩陣連接起來。

+0

你還有這個項目的代碼嗎?我很困難類似的問題:( – Andrea

+0

@Andrea y我仍然有它:),它的權利在這裏:https://github.com/Jas03x/GL_Engine/blob/master/src/ColladaLoader.cpp,https:// github .com/Jas03x/GL_Engine/blob/master/src/Animation.h,https://github.com/Jas03x/GL_Engine/blob/master/src/Bone.h。不幸的是我沒有我的着色器,因爲我把它刪除了。它不完美,但它的作品。讓我知道如果你有任何問題:) – Jas