USD XForms Row vs Column Major?

Hey!

So, I’ve had a bit of a mind bending investigation into how USD performs transforms with GfMatrix4d.

It appears, that GfMatrix4d, as documented, is row order.
So m1:

0,   1,   2,   3, 
4,   5,   6,   7,   
8,   9,  10,  11,
12, 13,  14,  15,

Is stored as:
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

Following a matrix where it’s stored in row-major, I would expect 3 (or [3]) to be transformX.
I.e a transformation matrix would be:
m2:

1, 0, 0, Tx, 
0, 1, 0, Ty,   
0, 0, 1, Tz,
0, 0, 0,  1,

However, it appears in USD that 12 is transformX, if we look at the order of values in a matrix where I have translated by 5 in X. This would appear to be column-major.
( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (5, 0, 0, 1) )

So, in the above Translation matrix format, USD is expecting:
m3:

1,   0,  0, 0, 
0,   1,  0, 0,   
0,   0,  1, 0,
Tx, Ty, Tz, 1,

This means when creating a matrix in row order following a typical transformation matrix definition of (matching my first row-major format matrix, m2):
( (1, 0, 0, 5), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
or:

1, 0, 0, 5, 
0, 1, 0, 0,   
0, 0, 1, 0,
0, 0, 0, 1,

I definitely do not get the expected transform (the cube explodes).

Is there somewhere this is documented, such that we can apply the transposition in the best place possible?

Cheers,
James

Treat vectors as horizontal (ie 1x4, not 4x1) and put them on the left when multiplying matricies: V=VM, not V=MV.

Almost all 3D graphics works this way because it makes the individual rows of the matrix useful as vectors themselves (if there is no perspective, they are the xyz axis and location of the origin).

2 Likes

We document what Bill just said here:
https://openusd.org/dev/api/usd_geom_page_front.html#UsdGeom_LinAlgBasics

1 Like

Thank you both, for the documentation and simple explanation as to how it works, apologies for missing the docs on the root page of UsdGeom!

TBH, the UsdGeom documentation should really be in gf’s overview.dox, which was skeletally written probably 22 years ago and not received much love since then…

1 Like