# Matrix right hand to left hand problem

This topic is 1179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello,
I am doing export animation data from Blender to DirectX.
In Blender, it is right hand system.
The final matrix of bind pose: offset*bone_to_parent[n]*bone_to_parent[n-1]... == identity matrix
It is OK.

Because Blender uses column vector, DirectX uses row vector, thus DirectX uses transposed matrices of Blender's.
But the result is wrong: offset^T*bone_to_parent[n]^T*bone_to_parent[n-1]^T... != identity matrix

I found some method convert right hand matrix to left hand before transpose, but not work.

Is there other reason cause it fail?
How to make the final matrix to be idenity matrix in left hand without change the order of multiplication?
Thanks,

##### Share on other sites
You also have to flip the order of all multiplications. In fact, (A*B)^T = B^T * A^T != A^T * B^T.

##### Share on other sites

I am doing export animation data from Blender to DirectX.

First, I personally am not very familiar with the Blender API, so I can't help you specifically with the API or the Python language.

Second, if you're not already doing it, you should be testing with the simplest mesh/armature combination you can create - possibly just 2 boxes and 2 bones. That will allow you to examine the actual values in each matrix, both on export and import, to determine if the matrices are being calculated exactly the way you expect.

So...

Are you writing an export script for Blender in Python? If so, you may want to examine this exporter to see how someone else has done it. It was written against the Blender 2.69 API, but the method should still be appropriate.

I found some method convert right hand matrix to left hand before transpose, but not work.

The general approach is correct. If it doesn't work, you'll have to determine where your code is incorrect. Perhaps examining the exporter linked above will help.

N.B., even when you get the matrix conversion working, conversion of the mesh data itself will have to be done. E.g., vertex normals, texture coords, etc., must also be converted. Again, the linked exporter script is well-commented and the various conversions are explicitly coded. EDIT2: You may have to invert the order of the face indices from CCW to CW if you want to use CCW culling mode in D3D.

EDIT:

The final matrix of bind pose: offset*bone_to_parent[n]*bone_to_parent[n-1]... == identity matrix

Although that will tell you if your matrices are correct, it won't provide you any useful information if the matrices are not correct. It's likely you'll find the problem(s) much more quickly if, as suggested above, you examine the matrix values themselves.

Edited by Buckeye

##### Share on other sites
Thanks all,
I use 2 box for test, just bind pose.
My to_parent matrix formula is wrong when in column vector:
to_child = pose_bones[ix-1].matrix.inverted()*pose_bones[ix].matrix
to_parent = to_child.inverted()

It should be flip the order of multiplication, that cause my final matrix wrong.
(Formula still not all right)

The final matrix is different between column vector and row vector:
column vector final matrix: bone_to_parent[0]*bone_to_parent[1]* ... *bone_to_parent[n]*offset == identity matrix

row vector, column vector, right hand, left hand, they are confused

bind pose OK now: (but motion pose is wrong)

Edited by endrollex