Enter the Matrix Knob

Written by Michael Garrett on .

A new feature in Nuke 6.1 is the exposed matrix knob on all 3D nodes that allow a transform (such as ReadGeo, Axis, Camera etc).  This contains all the transformation data for the node in a 4x4 matrix expressed as homogenous coordinates.

matrix01

Local Data and World Data

The transformation data is displayed as a local matrix and a world matrix.  The local matrix contains the local transform data and reflects the values you have set in the regular transform knobs, however you can override them by checking "specify matrix".  Why would you want to do that?  We'll get to that in a minute.  

The world matrix contains the world transform data, which is nifty because it exposes the compound, or absolute xyz transform of the node in world coordinates.  That means it takes into account any transforms from parent 3D nodes.

 

Reading The Matrix

At a glance it's difficult to read how the data is encoded, and in fact you don't need to know how it's done.  But in a simple case, like in the screengrab above, you can see that the translate data is stored in the last three cels of the last column - however that only holds true if you aren't doing any scale, skew or pivot adjustments.  

Rotation is stored as a trigonometric equivalent to the angle as numbers between -1 and 1, for example if you type in a y rotation of 45 degrees it will show up as 0.707 in a number of the cels.  This is the sine or the cosine of 45 degrees.  Again, the value in the cel can be affected by scale, skew and pivot changes.

 

Example Usage Scenario

Here's how you can use both the world matrix and the local matrix together: say you have a hierarchy of parent transforms on an existing camera and you want to create a duplicate new camera that is not dependent on the hierarchy, but instead contains only the collapsed transform data.  This used to be a potentially complicated process but now you can easily expression link the matrices between the two cameras.

In this screengrab we want to move the world transform data of Camera1 to Camera2, where Camera1 is parented to an Axis, therefore we can't just expression link its transform knobs to Camera2 without retaining the heirarchy.

matrix02

Camera 2 is the destination camera, so check the "specify matrix" option under the local matrix group.  Then bring up the Edit Expressions menu item from the animation menu and enter

1
Camera1.world_matrix

matrix03

This will populate all the local matrix cels with the same expression and now Camera2 has inherited all the world transform data from Camera1...done.

matrix04

matrix05

Comments   

 
# Howard Jones 2010-09-17 17:36
Thanks for the explanation - very useful.
2 questions -
1) what is the bottom row for - I cant find anything that changes it
2) Can you get this information from Maya etc or is this intended for Nuke use only

H
 
 
+1 # Michael Garrett 2010-09-17 18:00
1) I think it's not useful in this particular scenario but in say a perspective projection matrix it stores the homogenous coordinate.

2) Yes, although it may need to be reformatted to make sense. For example, you may need to transpose and/or invert the matrix, and account for possible differences in the coordinate system.
 
 
# junho seong 2011-08-02 20:08
Thanks for your detail explanation it's awsome
 
 
# Jesus Diez Perez 2012-02-24 05:59
Hi, thanks a lot for the explanation.
I have a question, though. Is there a way of "inverting" the matrix using expressions? What I want to do is to cancel all the transformations of an object and leave it as it was originally (in the origin, no rotation, etc).
Is this possible?
Thenka a lot!
 
 
+1 # Michael Garrett 2012-02-24 12:22
Have a look at the excellent nuke.math tutorial on this site to see how you can do this in Python:
http://www.nukepedia.com/written-tutorials/using-the-nukemath-python-module-to-do-vector-and-matrix-operations/page-4/
For an expression-base d approach, you can add a multiline Python statement to each cel of the matrix that will return a new matrix based on using nuke.math.Matri x4.inverse(). Then index to the corresponding cel but this will be a bit heavy since you're repeating the function in every matrix cel with just a slight tweak at the end. The most efficient way would be to define a separate matrix inverse function as a callback and then call that function from each cel, indexing to the appropriate value for each cel. Yes, it's a bit convoluted...
 
 
# Michael Garrett 2012-02-24 12:25
BTW I think a matrix inverse checkbox would be a nice function, like on the ColorMatrix node.
 
 
# iMan Javaherypour 2015-08-04 11:22
Excellent!
 

You have no rights to post comments

We have 2429 guests and 107 members online