I use this simple python script to export bones transformation:

bones = armature.pose.bones
# for eaach bone in bones
SystemMatrix = Matrix.Scale(-1, 4, Vector((0, 0, 1))) * Matrix.Rotation(radians(-90), 4, 'X')
if (bone.parent):
  Export_babylon.write_matrix4(file_handler, "matrix", bone.parent.matrix.inverted() * bone.matrix)
  Export_babylon.write_matrix4(file_handler, "matrix", SystemMatrix * bone.matrix)

I'm using a left handed Y up system but I should forget something about rotation because the result is not correct :(

enter image description here

Original (under Blender): enter image description here

  • \$\begingroup\$ It's bit unclear what you are asking? \$\endgroup\$ – Katu Sep 7 '13 at 17:02
  • \$\begingroup\$ I would like to know how to get the value of a bone transform from blender to apply it to my meshes Inside my engine \$\endgroup\$ – David Catuhe Sep 8 '13 at 6:42

OK I found the solution :)

It was related to the inversion of the parent bone. For those who have the same question, here is the final exportation code:

def export_bone_matrix(armature, bone, label, file_handler):
  SystemMatrix = Matrix.Scale(-1, 4, Vector((0, 0, 1))) * Matrix.Rotation(radians(-90), 4, 'X')

    if (bone.parent):
        Export_babylon.write_matrix4(file_handler, label, (SystemMatrix * armature.matrix_world * bone.parent.matrix).inverted() * (SystemMatrix * armature.matrix_world * bone.matrix))
        Export_babylon.write_matrix4(file_handler, label, SystemMatrix * armature.matrix_world * bone.matrix)

I am very interested in your bone layout for blender 3D meshes.
Let me guess are you creating meshes and add armature with root bones and
child bones applied to each distinct meshes?
If yes, then
[1]For the root bone controlled mesh, how do you position it in your OpenGL
code? By SystemMatrix * armature.matrix_world * bone.matrix?
[2]For the child bone controlled mesh, do you position the mesh in OpenGL
code by (SystemMatrix * armature.matrix_world * bone.parent.matrix).inverted() *
(SystemMatrix * armature.matrix_world * bone.matrix) ?

I think for both above are for the final world coordinate of all bones, but
the position of meshes should not be identical to the position of bones which
control them.

Are you just write a simple OnenGL code to position the meshes by bones or you
can make the meshes transformed by the translate, rotate and scale of bones?
If you can succeeded in positioning the meshes in OpenGL by above python-exported
coordinate of bones, then there is no doubt that we can export the coordinate
of each bone in each frame in animation.

However, the Blender native build-in python script comes with it. I'd like to
export the displacement of translate, rotate, scale of each bone in each distinct
frame so that I can then transform the mesh by restoring the transformation matrix.

From within the graph editor in Blender, you can easily tell the all displacement
of transformation - translate, rotate, scale are all measured with respect to the
original value in frame 0. Hence, I believe that I can do it. Do you know how?

Many thanks, mjtsai

  • \$\begingroup\$ This answer doesn't seem to fit within the site's Q&A format. Suggest refining your own questions and opening a new question with reference to this one. \$\endgroup\$ – jzx Jun 20 '14 at 16:47
  • \$\begingroup\$ Hello, you can find everything on github.com/BabylonJS/Babylon.js \$\endgroup\$ – David Catuhe Jun 21 '14 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.