Unexpected bone rotation

While writing an animation exporter for a custom format, I keep stumbling over the rotation of the bones.

( bone object ).matrix_local.to_euler()

For some reason, X is coming out as 1.57 when it should be zero (I assume) in resting position. When I import it into my application, the relative pitch is grossly thrown off. Is there an explanation for the rotation? Is subtracting 1.57 from X the only way around this?

On a side note, the arguments for .to_euler() don’t appear to be working yet. I tried some different ways of sorting the axes and the results are all (1.57, 0.00, 0.00).

can’t help, this retured correctly for me:
bpy.context.object.pose.bones[1].matrix_local.to_euler()
Euler((0.0, -0.0, 0.0))

good luck

Oh- that’s strange.

bpy.context.object.data.bones[0].matrix_local.to_euler()
# Output: Euler((1.570796251296997, -0.0, 0.0))

bpy.context.object.pose.bones[0].matrix_local.to_euler()
# Output: Euler((0.0, -0.0, 0.0))

Why aren’t they the same? Am I not accessing the bone’s local matrix in the first line?

Ok, I think I am beginning to make sense of this now.

bpy.context.object.data.bones - - > Resting transform of the bone
bpy.context.object.pose.bones - - > Transform relative to the resting bone (Set by the pose)

This takes me back to where I started, because I need to export the resting transform, but it still has a curious 90 degree rotation. I have tried applying rotation, but still no luck. Does anyone know why the bones don’t have 0.0, 0.0, 0.0 rotation by default?

I guess, the whole armature’s been rotated 90 degrees on X…

That may be, but why do I not see this anywhere in the transform window? This is only showing up in python. If you want to see what I’m confused about, try the following:

  • Open Blender 2.54
  • Delete cube
  • Press Shift+A -> Armature -> Single Bone
  • Press N … Rotation is zero
  • Tab into edit mode … Rotation is zero
  • Open console
  • Type “bpy.context.object.data.bones[0].matrix_local.to_euler()”
  • You will see “Euler((1.570796251296997, -0.0, 0.0))”

Why is this? I just think it’s strange that this doesn’t show in the interface and the default rotation for a new bone isn’t zero. If I have a misunderstanding of the math involved or missed an option in the interface then I would love to learn where I am being mislead so that I can get past this.

Again, the whole reason I am concerned is because my application expects rotation to start at 0,0,0. I would rather not perform an ugly hack if it can be avoided.