The current version of the code just shifts the problem I tried to fix one level down the hierarchy: Instead of having the -90 degree rotation on the root node it is on the first child.
This applies the bake throughout the whole hierarchy. Additionally I made it apply to armatures and bones. In my tests in Unity this produces exactly the result I expected, but I can provide example Blender and Unity scenes and a write up as well.
I tried to refactor the matrix calculation code a bit to make clearer what happens:
- first it calculates the Blender global space matrix
- then it converts into FBX global space
- if the local matrix is expected it gets the calculated parent matrix and applies the inverse
(That way it should handle any odd mixed hierarchy)
For the non-baked case I didn't see any changes in my tests, but if there are cases where the result is different please reject this patch and I'll find a solution.