I'm currently writing a blender addon to export animations to a json format which i can use for my projects.
My current way of exporting is this:
I grab the matrix of the armature bone: mat = bone.matrix_basis.to_euler()
Then i convert it to degrees using: degrees from the math lib
Once converted the rotation vectors are all messed up.
I tried flipping them with -degrees(mat.x)
, which worked for some bones, but not all bones are being flipped correctly. The matrixes are all messed up, and some bone data is changed so that x = z and so on. Does anyone know how to get the right rotation data.
The data needs to be per bone because they use parenting and use the parent when transforming the next. so matrix_basis does what i want. This may be because the bone roll is not correct but im not sure.
The bottom image is the way you see it in blender. The first image is the output.
Current export code:
for f in range(scn.frame_start, scn.frame_end + 1):
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
s = f / fps
vectorcomma = ","
mat = bone.matrix_basis.to_euler()
if f == scn.frame_end:
vectorcomma = ""
out_file.write('"{}":'.format(s) + '{"vector":' + '[{:.3f},{:.3f},{:.3f}]'.format(degrees(mat.x), degrees(mat.y), degrees(mat.z)) + '}' + '{}'.format(vectorcomma))
The program i want to export it to uses degrees for its rotation, and the rotation is relative to the parent rotation, which is done by the program.