top of page
constraint matrix

Lesson 4 : Constraint Matrix

In this class, we will learn how to avoid using Maya's constraints and instead utilize matrix constraints, which are much more efficient than Maya's default constraints. We will explore how to create these matrix constraints.

Table of Contents

1. Why use matrices constraints ?
2. Basic matrices nodes for Maya
3. Point, scale, rotate matrix
4. Matrix with parent
5. Matrix create Offset

6. Matrix with multiple traget
7. Aim matrix

8. Sources

1. Why use matrices constraints ?

What you need to know is that the default constraints in Maya were created years ago and they are no longer capable of creating reliable and optimized constraints. While they work well in practice, they are very resource-intensive. Having around thirty to fifty constraints will significantly slow down your scene. On the other hand, using matrix constraints will require a lot more before you start noticing a slowdown caused by constraints.

​

That's why it's important from now on to avoid using the basic constraints and create your own. Don't worry, you don't need to be a math expert or have extensive knowledge of matrices to create your constraints. We'll go step by step on how to create them.

What is a matrix?

A matrix is a fundamental concept in mathematics and computer science. It's a data structure that organizes elements into rows and columns. Each individual element in a matrix is called a 'matrix element.' In Maya, we use translation matrices that allow us to manage all the axes and rotations we need.

​

We represent it like this in mathematics.

Translation matrix

matrix maya

In Maya, we can find it when we select a transform and want to access the parent's offset matrix. That's how we see a matrix in Maya.

matrix maya

A translation matrix is a matrix used in 3D graphics and geometry to move objects in space. It's primarily used to represent translations, meaning the movements of an object within a coordinate system.

​

In 3D, a translation matrix is typically a 4x4 matrix where the elements on the upper diagonal (starting from the top-left corner) are equal to 1, and the three elements in the last column (starting from the top) represent the translation values in three dimensions (x, y, z).

​

The standard translation matrix looks like this:

​

​

​

​

​

​

​

Where Tx, Ty, and Tz represent the desired displacements along the x, y, and z axes respectively.

​

To apply a translation to a point or object represented by a vector [x, y, z, 1] (with the last element typically being 1 for homogeneous transformation operations), you multiply this vector by the translation matrix.

​

Let's consider a simple example to illustrate this. If we want to move a point with coordinates (2, 3, 4) by 5 units in the direction of the x-axis, the translation matrix would be:

​

​

​

​

​

​

​

​

If we multiply this translation matrix by the point vector (2, 3, 4, 1), we get:

​

​

​

​

​

​

​

​

The point (2, 3, 4) has been moved 5 units in the x-axis direction to become the point (7, 3, 4).

more information here

matrices
matrices
multiply matrices

12 + 03 + 04 + Tx(5)∗1 = 7

02 + 13 + 04 + Ty(0)∗1 = 3

02 + 03 + 14 + Tz(0)∗1 = 4

02 + 03 + 04 + 11 = 1

matrix             vector

In Maya, each movable node will have several matrices available, as listed below:

  • For each node, we'll find the "matrix" of the node itself, as well as the inverse of the node's matrix, "Inverse Matrix".

  • Additionally, we'll have the ability to retrieve the matrix of the parent node, 'Parent Matrix.' And we'll also have the option to obtain the inverse of the parent matrix, "Parent Inverse Matrix".

  • Finally, we'll also have access to the "World matrix" and the "World inverse matrix".

matrix maya

With this, we'll be able to create all the connections and constraints we desire. With this, we have all the information we need to multiply, add, or blend coordinates together in order to create our constraints.

2. Basic matrices nodes for Maya

We will be using these different matrix nodes in Maya throughout the course.

  • We have the 'multMatrix" that will multiply matrices together.

  • We have the "addMatrix" that will add matrices together.

  • We have the "decomposeMatrix" that will break down the matrix to retrieve translation, rotation, scale, shear, and quaternion—the traditional methods of translation in Maya.

  • We also have the "composeMatrix" that does the opposite of "decomposeMatrix", taking traditional translation methods to convert them into matrices.

  • The "pickMatrix" will allow us to retrieve specific elements like rotation or translation from the matrix.

  • And the "blendMatrix" that will enable us to blend matrices with weights.

matrix maya

3. Point, scale, rotate matrix.

Firstly, we'll start with the absolute basics, without any intermediate nodes, rotations, or different coordinates. We'll begin with the point matrix because it allows us to understand the fundamental concepts of matrices in Maya and is the simplest to execute. To achieve this, we'll only need a single node: the "pickMatrix", with only the "Use Translate" option checked.

​

We'll take a simple scenario where we have a locator at the world center and a cube at the world center without any offsets or rotations between the two nodes, and neither node has a parent (as doing so would require more consideration).

pickmatrix

With this, you'll be able to move your node as much as you want without any issue.

​

And what's convenient, quite handy with the "pickMatrix", is that now if you want a rotation matrix or a scale matrix, you simply need to check only what you want.

matrix contraint

4. Matrix with parent.

Now, let's make things a bit more intricate and realistic by introducing parents into the mix. Up until now, the locator and the cube were parentless, sharing the same positions and rotations at the world center.

matrix maya

We'll encounter a small issue if we do exactly the same thing as before. It might seem like it's working, but in reality, it won't because if we move the parent of the locator, the cube won't move along with it, and that's not what we want. We want the cube to be constrained to this locator.

matrix parent

The issue arises from using only the matrix of the locator node itself. This means that if we move the parent, the locator's matrix won't be modified because theoretically, the node doesn't move, it's the parent of the locator that moves.

​

To address this, we'll use the World Matrix. However, if we solely use the World matrix with the pick matrix, an offset will automatically be created.

matrix constraint

The offset occurs because we're retrieving the World matrix (the global coordinates of the locator). As the cube is also in a group that isn't at the world center, Maya will simply take the coordinates of the parent cube and add them on top of the World matrix of the locator, resulting in this offset.

​

To further illustrate, consider if the parent cube were ultimately at the world center,  then the cube would end up exactly at the locator's position. This happens because we won't have the position of the "parent_cube" in addition to the World matrix of the locator.

matrix offset

If your aim is to achieve precisely what I've shown you above, having the cube exactly at the same location as the locator without any offset between them.

​

it's quite simple in the end., All you need to do is use a "multMatrix" with the World matrix of the locator and the World inverse matrix of the parent_cube, and multiply them together like this.

matrix maya

You can use a "pickMatrix" to retrieve what you want.

parent matrix

Our goal is to keep the cube aligned with the "parent_cube". We want the cube to move if either the locator or the "parent_locator" moves.

Therefore, we'll need to create a reverse offset system to ensure the cube remains at the center of the "parent_cube".

5. Matrix create Offset

To create an offset system, we'll need to generate an attribute that stores the offset we desire. You can create this attribute wherever you prefer, but I'd recommend creating it on the "parent_cube" node. This way, it'll be easier to locate and manage the various offsets.

offset matrix

And then, through various operations we'll perform, we'll be able to calculate this offset and assign it. For this, we'll need to find a calculation method to obtain the matrix between the cube and the "parent_cube".

offset maya

To obtain the inverse of the offset, we'll need to multiply the World matrix of the parent cube with the World inverse matrix of the locator, like this.

calcul matrix

Once these two elements are multiplied, all that's left is to plug the output of the "multMatrix" into the attribute you've created (then you'll need to disconnect it, or else it will create a cycle). Afterward, all you need to do is connect them in this order to obtain the offset.

parent offset

Warning ! The order of connections is crucial. It's imperative to connect the nodes in this specific sequence.

​

Firstly, take the offset, then the World matrix of the target, and finally the World inverse matrix of the cube's parent.

In fact, a simple technique to correctly set up the connections is to initially link the World matrix of the node that will serve as the position for your offset in a "multMatrix". This node determines the offset, enabling you to decide where to place your constrained node. Then, connect the World inverse matrix of your target. Doing just this will create the setup. Afterwards, of course, connect it to your created offset attribute.

​

Using this technique, I can create a locator to select the desired offset for my cube and use this locator to establish my offset.

parent offset

Now, if you want to retrieve a specific type of constraint, whether it's for translation, rotation, or scale, all you need to do is use a "pickMatrix" to acquire what you need. Simply plug it between the "multMatrix" and the cube.

blend offset matrix

Of course, if you've created a rotation or translation offset and use the "pickMatrix" to disable either the translation or rotation, naturally, the offset won't be considered as you've disabled it using the "pickMatrix".

And there you have it! With this, you'll be able to create any kind of setup you desire and playing with different angles in your constraints, adding offsets, removing them, and so on.

​

I know, it's not easy to grasp at first, but the best way to understand is by experimenting with various combinations of connections, plugging, and unplugging to grasp how matrices operate.

Once you've understood how these nodes fit together and how to work with them, it will open up incredible possibilities that will make your life easier when rigging.

6. Matrix with multiple traget

If you have multiple targets for your constraints, it's quite straightforward. All you'll need is one node to handle as many targets as you want. For this, you'll need the "blendMatrix". it will blend all the targets to encapsulate a single matrix.

​

All you have to do is connect your 'blendMatrix' like this.

blend matrix
blend matrix

With the "blendMatrix", you'll be able to do the same thing as the "pickMatrix" but with multiple targets.

Moreover, you'll have more control as you can adjust the 'blendMatrix' as you wish.

blendmatrix

And then, everything I explained above regarding offsets, parents, etc.

will work in exactly the same way with the blendMatrix. You connect the elements in the exact same manner to create your offsets or if you have a parent.

If you have parents in your scene and don't want any offset, you just need to use this.

blen dmatrix

Now, if you want to create an offset, you just need to use the same technique I explained earlier to create offsets in matrices. Choose the location of the offset, retrieve the World matrix of this offset first, then multiply it with the World inverse matrix (you'll need to retrieve the world inverse matrix of the cube), and finally store the result in the created attribute for the offset.

blend offset matrix

7. Aim matrix

To create an aim constraint, Maya already has a well-thought-out feature called "AimMatrix", which works excellently.

You'll just need to use a few nodes or set the aim constraint.

​

Firstly, you'll need to retrieve the translation of your node that will be aimed and convert it into a matrix using the "composeMatrix". Then, multiply it with a "multMatrix" using its parent matrix. Afterward, you can import the "multMatrix" and the node that will serve as your target into the "aimMatrix". Then, simply connect the output of the "aimMatrix" into a "decomposeMatrix" to inject only the rotation into the "rotate" attribute of the node that will be aimed.

aim matrix

We use a "composeMatrix" and a 'decomposeMatrix' because without them, directly connecting to the object's matrix would create a cycle that could completely disrupt the aim. However, Maya provides two ways to position another, allowing us to manage the cycle using the "decompose" and "composeMatrix" nodes.

Then, once you've connected the node as desired, all that's left is to configure the node as needed by modifying the "primary input axis".

​

Once you've done this, like the persistent headache in Maya, occasional flips may occur. To address this, we'll use the "secondary target matrix" this time, which will provide an alignment axis to avoid these flips. You'll connect it like this.

matrix aim

Once done, like the persistent ball headache in Maya, occasional flips may occur.

remedy this, we'll use the "secondary target matrix" this time, which provides an alignment axis to prevent these flips. We'll connect it like this.

connection target

Then you'll need to configure it as you desire. In my example, I'm using a locator aimed along the X-axis and I want to perform a rotation on the Z-axis. So, I just need to connect it this way and set up the matrix like this to achieve the constraint properly.

aimmatrix

Conclusion

Throughout this course, we've explored the scope of matrices and how to use them in general. Of course, practice is key to mastering them. it's not something that comes easily at first. I hope this has helped you better understand matrices in Maya and how to use them effectively to create your own constraints. My advice is to practice extensively, familiarize yourself thoroughly with matrices, and use them on simple objects to get a good grip on them.

​

To recap, the crucial aspect to remember for creating a constraint without an offset is to apply this technique. use the World matrix of the target and the World inverse matrix of the parent.

matrix

It's also essential to know how to successfully create an offset wherever we want using this technique.

parent offset

If you manage to master these two things, creating offsets as desired and understanding how to retrieve parents and the World matrix of each object, and successfully comprehend how to multiply them. the rest will seem straightforward and easily accessible to you.

I hope this lesson has served you well !

8. Sources

bottom of page