I'm having trouble finding the final bone matrices for my skeleton.
I know my bind pose matrices work, and I know my transform matrices work, but I figured multiplying them (which I'm calling the composite matrix) then multiplying them by its parents composite matrix (then by its parents parent, etc.) would get me the correct matrix.
Its worth noting I'm using gl-matrix.js as my vector / matrix math library, its matrix math works in reverse, getting a world matrix requires, PositionMatrix * RotationMatrix * ScaleMatrix, instead of the other way around. so I may be getting the orders mixed up,
I've tried changing the multiplication orders of the bind pose matrices and the bone transform matrices, as well as the order of final matrix and parent matrices, but I'm just mind boggled now.
Anyway to wrap this question up in a bow, Given a mesh where every vertex is pre-transformed to its relative bone(s) space, each bones bind pose matrix and each bones per frame transform matrix how would I find the final bone matrix?
EDIT:
still having issues but it may help to say where I am at the moment, the following psuedo code gets the model perfectly into its bind pose
finalBones = []
foreach bone in bones
mat = bone.poseMatrix
parent = bone
while (parent.parent != null)
parent = parent.parent
mat *= parent.poseMatrix
finalBones.push(mat)
the above snippest is exactly whats going on without needing to explain the matrix functions (its javascript so its done via functions like mat4.copy and mat4.mul)
I figured if I did something like
finalBones = []
foreach bone in bones
mat = bone.poseMatrix
mat *= bone.transformMatrix
parent = bone
while (parent.parent != null)
parent = parent.parent
mat *= parent.poseMatrix
mat *= parent.transformMatrix
finalBones.push(mat)
I would get the final matrix (and I have tried using the transformMatrices before the poseMatrices) but all I get is a model with a broken spine and inside out legs
EDIT 2:
so on further inspection, the bone transform matrices on an idle frame have the middle 2 rows inverted? odd, but I'm looking into what happens if I swap them back now