I have some questions on bone-based animating.
The process I got (in short):
- Export the vertices with boneweights and also the skeleton, with the bones as worldmatrices (position, rotation, scale), as a "basemesh" (from the modeling program)
- Export an animation as the bone-worldmatrices for each frame
- For playing an animation, transform every vertex by ((bonematrices of the current frame) - (bonematrices of the baesmesh)) for each bone assigned to it, using the weights
The reason that this isn't working is that, when transforming one vertex of a mesh with a matrix, the rotation and scaling will be applied from the origin of the mesh as the origin, not the position of the bone.
I thought that could be fixed with relative ease, by constructing the worldmatrix for each bone like this:
// Answer from a question on stackoverflow mat4 result = glm::translate(-pivot) * glm::scale(..) * glm::rotate(..) * glm::translate(pivot) * glm::translate(..);
Where pivot would just be the position of the bone. But when applying this, there is no change to the final result. Stuff still uses the center of the model as pivot-point for scaling/rotating.
Also, this method of animating completly ignores the parent-child-relations that bones hold to each other. Is there something gained from using those relations when computing the rendering?
I understand why they are extremly helpful when modeling in the modelingprogram, but is there a reason to also use them when rendering?
Your help is, as always, greatly appreciated!
Have a nice day!