Skip to main content
Fixed the code display and the French :)
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

scene->mMeshes[1]->mBones[idx]->mOffsetMatrix)

scene->mMeshes[1]->mBones[idx]->mOffsetMatrix) 

parentTransform(transform, scene->mAnimations[idx]->mChannels[cIdx]->mNodeName); inline void parentTransform(glm::mat4 &result, aiNode* node) { if (node->mParent != 0x0) { glm::mat4 tmp = aiMatrix4x4ToGlm(&node->mParent->mTransformation); result = tmp * result; parentTransform(result, node->mParent); } }

parentTransform(transform, scene->mAnimations[idx]->mChannels[cIdx]->mNodeName); inline void parentTransform(glm::mat4 &result, aiNode* node) { if (node->mParent != 0x0) { glm::mat4 tmp = aiMatrix4x4ToGlm(&node->mParent->mTransformation); result = tmp * result; parentTransform(result, node->mParent); } } 

gl_Position = proj_matrix * mv_matrix * bones[boneId] * vec4(position, 1.0);

gl_Position = proj_matrix * mv_matrix * bones[boneId] * vec4(position, 1.0); 

And violavoilà.

scene->mMeshes[1]->mBones[idx]->mOffsetMatrix)

parentTransform(transform, scene->mAnimations[idx]->mChannels[cIdx]->mNodeName); inline void parentTransform(glm::mat4 &result, aiNode* node) { if (node->mParent != 0x0) { glm::mat4 tmp = aiMatrix4x4ToGlm(&node->mParent->mTransformation); result = tmp * result; parentTransform(result, node->mParent); } }

gl_Position = proj_matrix * mv_matrix * bones[boneId] * vec4(position, 1.0);

And viola.

scene->mMeshes[1]->mBones[idx]->mOffsetMatrix) 
parentTransform(transform, scene->mAnimations[idx]->mChannels[cIdx]->mNodeName); inline void parentTransform(glm::mat4 &result, aiNode* node) { if (node->mParent != 0x0) { glm::mat4 tmp = aiMatrix4x4ToGlm(&node->mParent->mTransformation); result = tmp * result; parentTransform(result, node->mParent); } } 
gl_Position = proj_matrix * mv_matrix * bones[boneId] * vec4(position, 1.0); 

And voilà.

Source Link

I'm just starting to piece this together myself, but I've managed to apply transformations to bones by exporting them as collada files. Nothing else works AFAIK. This does not work for me with fbx.

Here is the "formula" as I understand it:

bone_transform = inverse(mRootNode->mTransformation) * aiBoneNode->parent->mTransformation * animation->RST matrix * aiBone->mOffsetMatrix; gl_Position = MVP * bone_transform * vertex; 

I'll try and elaborate, minus all of the code I used to traverse aiScene... First, you need to get the offset matrix from the bone:

scene->mMeshes[1]->mBones[idx]->mOffsetMatrix)

Next, look up the transform matrices:

parentTransform(transform, scene->mAnimations[idx]->mChannels[cIdx]->mNodeName); inline void parentTransform(glm::mat4 &result, aiNode* node) { if (node->mParent != 0x0) { glm::mat4 tmp = aiMatrix4x4ToGlm(&node->mParent->mTransformation); result = tmp * result; parentTransform(result, node->mParent); } }

Then, get the keyframe transformation:

 glm::quat key_rotate( scene->mAnimations[idx]->mChannels[cIdx]->mRotationKeys[0].mValue.w, scene->mAnimations[idx]->mChannels[cIdx]->mRotationKeys[0].mValue.x, scene->mAnimations[idx]->mChannels[cIdx]->mRotationKeys[0].mValue.y, scene->mAnimations[idx]->mChannels[cIdx]->mRotationKeys[0].mValue.z ); glm::mat4 key_translate = glm::translate( glm::mat4(1.0f), glm::vec3( scene->mAnimations[idx]->mChannels[cIdx]->mPositionKeys[0].mValue.x, scene->mAnimations[idx]->mChannels[cIdx]->mPositionKeys[0].mValue.y, scene->mAnimations[idx]->mChannels[cIdx]->mPositionKeys[0].mValue.z ) ); 

Next, mash it all together:

 m_scenes[mIdx]->m_bones[bIdx].keyframe_transformation = glm::inverse(aiMatrix4x4ToGlm(&scene->mRootNode->mTransformation)) * //aiMatrix4x4ToGlm(&scene->mRootNode->mTransformation) * transform * //aiMatrix4x4ToGlm(&scene->mRootNode->mChildren[0]->mTransformation) * key_translate * glm::mat4_cast(key_rotate) * m_scenes[mIdx]->m_bones[bIdx].offsetMatrix; 

Send it to your vertex shader:

gl_Position = proj_matrix * mv_matrix * bones[boneId] * vec4(position, 1.0);

And viola.