Rotation axis in posebone.matrix for OpenGL

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
ravenclaw_78
Posts: 0
Joined: Thu May 09, 2013 10:40 pm

Rotation axis in posebone.matrix for OpenGL

Post by ravenclaw_78 » Thu May 09, 2013 11:03 pm

I'm writing a custom exporter (mesh, bones, actions) for use with android and skeletal animation (vertex skinning).

To counteract blenders Z-Up instead of OpenGLs Y-UP i rotated the vertices X-90.

What does not work is the animation using the matrix from the poseBones. My test object, a twoboned cubesnake (looks like 4 cubes in a row) behaves wrong. All movement happens around the wrong axis.
* look to the left becomes a twist like a screw
* up look becomes a look to the Right
* the wrist becomes a up looking movement

I capture the actions by setting it

Code: Select all

armature.animation_data.action = action
bpy.context.scene.update()
iterating trough the frames reading the poseBones matrix.

Is there a way I can fix this axis missalignment ?

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Thu May 09, 2013 11:22 pm

i guess you would need to change coordinate stuff for every location / rotation on export, not just for the objects / meshes, but also the pose bones. Maybe have a look at the stock exporters, they provide axis conversion option.
I'm sitting, waiting, wishing, building Blender in superstition...

ravenclaw_78
Posts: 0
Joined: Thu May 09, 2013 10:40 pm

Post by ravenclaw_78 » Mon May 13, 2013 9:26 pm

CoDEmanX wrote:Maybe have a look at the stock exporters, they provide axis conversion option.
The exporters that i've seen multiply with one of the following

Code: Select all

Matrix(((1.0, 0.0, 0.0, 0.0),(0.0, 0.0, 1.0, 0.0), (0.0, -1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0)))
mathutils.Matrix.Rotation(radians(-90.0), 4, 'X')
That works well for the Object itself (multiplying the vertices, or the modelMatrix) but not for the poseBone.matrix.

I calculate the skinningMatrix like this:

Code: Select all

skinningMatrix = poseBone.matrix * poseBone.bone.matrix_local.inverted()
in the shader i do: skinningMatrix * vertex

I thought about rotating the skinningMatrix, but this also rotates the Vertex.

I must be missing some Space convertions ... can someone give me a hint.

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Tue May 14, 2013 9:00 am

how about
skinningMatrix = poseBone.matrix * poseBone.bone.matrix_local.inverted() * mathutils.Matrix.Rotation(radians(-90.0), 4, 'X')
?
I'm sitting, waiting, wishing, building Blender in superstition...

ravenclaw_78
Posts: 0
Joined: Thu May 09, 2013 10:40 pm

Post by ravenclaw_78 » Wed May 22, 2013 4:52 pm

although this is not tested with a full model... the following works for my cube sample ...

Code: Select all

poseBoneMatrix = poseBoneMatrix * boneMatrix.inverted()
                    
rotation = poseBoneMatrix.to_euler("XYZ")
y = rotation.y
x = rotation.x
rotation.y = x
rotation.x = -rotation.z
rotation.z = -y
m = rotation.to_matrix().to_4x4()
m.translation = poseBoneMatrix.to_translation()
trans = poseBoneMatrix.to_translation()
m.translation = mathutils.Vector((trans[2], trans[0], -trans[1]))
poseBoneMatrix = m

Post Reply