After sleeping on this debacle it had dawned on me that the transpose at the end (then asking for the rows) was pointless. At the same time I hadn't caught that I was copying the mat4, just to get another copy again with the transpose(). Good catch. Sadly, I had originally expected it would take a 10 - 20 minutes to set up a test scene and learn how to get the data in and out of Maya...instead it took the day. *sigh* How could something so simple become one of my more frustrating scripting experiences. I think this is right up there with my pain of doing a custom grid control in wxPython, but that's another story :)

Nathaniel

On Sun, Apr 3, 2011 at 12:59 PM, Matthias Baas <matthias.baas@gmail.com> wrote:

Hi Nathaniel,

it seems you got it all working now, but just to recap:

Whenever you deal with separate packages that use matrices to store

transformations, you need to check what their conventions are with

respect to how points are transformed. You can transform them by either

multiplying them to the left or the right of the matrix:

1) Maya: transformedPoint = point*Matrix

(in this case, the translation part is the 4th *row* of the matrix)

2) cgkit: transformedPoint = Matrix*point

(in this case, the translation part is the 4th *column* of the matrix)

It's straightforward to switch from one convention to the other, you

just have to transpose the matrix.

If those packages store matrices as flat lists instead of dedicated

matrix objects, then there's an additional stumbling block. You need to

know the order of the values, they are either in column-major or

row-major order (which has nothing to do with the above convention about

the order of the multiplication). If you get this wrong, you end up

having a transposed matrix. If you get both things wrong (the above

transformation convention and the value ordering), you are actually fine

again as one mistake cancels out the other one (which may actually

further increase the confusion).

That looks correct to me.

> def cgkit_matrix( xform_list ):

> """

> takes a 16 element list (assumed to be the result of a xform query)

> and returns a cgkit.cgtypes.mat4 in proper form

> """

> matrix = cgkit.cgtypes.mat4( xform_list )

> matrix = matrix.transpose( )

> return matrix

The transpose() method returns a copy anyway, so there's no need to copy

> def maya_xform_list( matrix ):

> """

> converts a cgkit.cgtypes.mat4 into a row list that can be used with

> mays.cmds.xform.

> The original matrix is left unaltered.

> """

> #create a copy of the original matrix

> matrix = cgkit.cgtypes.mat4( matrix )

> matrix = matrix.transpose( )

> return matrix.toList( rowmajor = True )

the matrix at the beginning.

Also note that this function could even be far simpler, you could just

return matrix.toList() (using the default column-major order) in which

case the transpose will be done implicitly by toList().

- Matthias -

------------------------------------------------------------------------------

Create and publish websites with WebMatrix

Use the most popular FREE web apps or write code yourself;

WebMatrix provides all the features you need to develop and

publish your website. http://p.sf.net/sfu/ms-webmatrix-sf

_______________________________________________

cgkit-user mailing list

cgkit-user@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/cgkit-user