Hi gamedev.net,
Hope you are all well and healthy. I am working on a personal project in C++ with modern OpenGL.
I have already asked this question on r/gamdev, but I am hoping someone here might be able to help.
I have a problem I am stuck on. I am trying to implement skinning, however it is only almost right. I wondered if you could consider the code, maybe you can see where I am going wrong? I have worked on it all summer, and I am getting a little lazy or desperate at the end I suppose, if you could find the error I would be over the moon. Only if it is easy for you to see what I am doing wrong, of course.
The arms are not attached correctly, and the arms and legs are not animating correctly: https://youtu.be/7h24-j8iY9Q
It is really supposed to look like this when running: https://youtu.be/0Pr-ZEbItWU
The code is partially based on the lovely book Hands on Animation Programming: https://github.com/PacktPublishing/Hands-On-Game-Animation-Programming/blob/master/Chapter15/Sample01/Code/GLTFLoader.cpp
I have tested the book's source code, and it animates my model correctly.
animation.cpp is my code: https://gist.github.com/alanhaugen/6056be162cf92fed3cf3b2119caa7e10
The actual skinning is done in void Animation::ApplyTransform.
I am considering developing a matrix class, Mat, it is used for keyframes and the implementation is mat.cpp: https://gist.github.com/alanhaugen/1872f5950c4912f78cf6be0323614f0e
I do the inverse matrix calculation when I load the model. The animations are in their own gltf files. Here's joint.cpp: https://gist.github.com/alanhaugen/5e81a6ed6ce72c58565079a796ef2c0a
I have tried to debug the way the joint-tree is traversed, I have not found it to be incorrect.
It animates models where each joint has only one child each correctly, such as this worm: https://youtu.be/GJhMtyQInEU
When I disable scale and rotation, the arms and legs end up pointing into the air, which is strange: https://youtu.be/-5dh6gaaaIc
I might not be applying rot * scale* position in the right order in mat.cpp, although I have tried all permutations of those operations. I do the calculation in keyframe.cpp: https://gist.github.com/alanhaugen/8e439048a481878b99e5a0a055afec8c
I have looked at the animation matrices in a GPU profiler, but I don't really know what to look for. I could compare them with the animation transforms from the book code, but the shaders are a little different. Here is my GLSL skinning.vert: https://gist.github.com/alanhaugen/128b217786d310d924a9c1d5f05ed435
I hope this isn't too much to ask. If you have any ideas about what could be wrong, I would really appreciate them. Although, I will surely figure it out eventually :)
Kind regards,
Alan