0
$\begingroup$

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.

This is what data is being exported to the json file This is what its supposed to be in blender

$\endgroup$
3
  • $\begingroup$ Hello, I don't understand why you want to convert radians to degrees. It would be helpful if you could edit this question and add a short executable script. $\endgroup$
    – tetii
    Commented Jan 19 at 0:27
  • $\begingroup$ @tetii I have added the code and a short description of what the software needs as a input. I want to export per bone rotations which are relative to its parent. It needs to be in degrees. $\endgroup$
    – Hellaweird
    Commented Jan 19 at 12:28
  • $\begingroup$ Sorry. I can't answer that question because I don't have the means to reproduce your problem and I don't know the importer/exporter specs. $\endgroup$
    – tetii
    Commented Jan 20 at 6:36

0

You must log in to answer this question.

Browse other questions tagged .