Sitemap
Press enter or click to view image in full size

Matrix Splines in Maya

13 min readDec 20, 2020

Overview

Before getting into the details of the setup, here’s a demo of the results in Maya. Note the absence of any nurbsCurve nodes in the outliner:

Press enter or click to view image in full size
Just meshes and matrices, not a nurbsCurve node in sight!
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Surfaces can be implemented with only one additional node!

Usage

While the actual node network setup is fairly simple, the matrix weights themselves are best generated through code. Fortunately I’ve wrapped all the math in as a python module.

Advantages and Limitations

This method has a lot of advantages but its not the solution for every problem. While I’ve tested a similar method in production for the past year, I think its important to consider the pros and cons before implementing it.

Advantages

  • Node Simplicity. There are many alternative methods to attach transforms to curves, but they often involve awkward conversions to and from NURBS nodes. All the heavy lifting here is done with a couple matrix nodes.
  • Matrix Friendly. This method includes matrix inputs and outputs rather than vectors so its is perfect for use with the new matrix nodes in Maya 2020.
  • No DAG Nodes. While hiding DAG nodes from your animators isn’t a huge problem, eliminating them certainly reduces outliner clutter and avoids infamous DO_NOT_TOUCH groups. This is also helpful when building rigs through code as there are no residual DAG nodes to worry about.
  • Performance. I’m not an expert on testing performance but in my simple tests using dgtimer this setup performs almost 40x faster than using curveInfo nodes. Optimization wasn’t the goal of this workflow, but it is a nice perk!

Limitations

  • Static parameter and knots. This is probably the biggest deal-breaker for anyone looking to implement this method. This means you cannot create rigs that slide along splines, or splines with locked lengths.
  • Built-in Tool Support. Maya’s spline nodes include a lot of built-in utilities and tools that are incompatible with this workflow. This means we cannot drive curves with deformers or simulations, or use Maya’s API for querying curve data.
  • Python Setup. While the provided module should be trivial to copy and paste where needed, if you’re used to rigging by hand this can be a bit of a burden.

Math Time

So far I’ve focused primarily on the practical applications of this method. But in the process of figuring this all out I’ve learned a lot about the math behind splines. While there are some great resources available online(this primer in particular was a huge help), they are often generalized or require extensive prior knowledge. So while I’m no expert, I feel like I should at least do my best to explain the math from a Maya rigging perspective.

Bezier Curves

Before I discuss splines, I should first go over Bezier curves. While these aren’t the same, understanding curves is fundamental to understanding splines.

Get Cole O'Brien’s stories in your inbox

Join Medium for free to get updates from this writer.

There’s really nothing too crazy about this formula, and should be pretty simple to convert into python code. Unfortunately, this format isn’t the most convenient to represent as a node network in Maya. Getting a single point will require around a dozen nodes just to add and multiply everything. Instead if we use a static time value we can simplify the equation into a weighted sum like this:

Press enter or click to view image in full size
Press enter or click to view image in full size
Note that scale and rotation work as well! A neat side effect of blending matrices.
Scale is removed in this version, but the rotation is still used for an up vector.
Press enter or click to view image in full size
Press enter or click to view image in full size
Note that every cube is highlighted, even when its not being affected!

Spline Curves

While Bezier curves can be interpreted as a method of interpolating points, NURBS can be considered a method of interpolating Bezier curves. NURBS stands for Non-Uniform Rational B-Splines, which is a lengthy way of saying it’s a type of spline. Splines solve our control point problem by using several curves blended together. So we can still have a degree three curve with more than four control points.

Press enter or click to view image in full size
Press enter or click to view image in full size
Also note how each control point only highlights a sub-set of cubes!

Knots

If you’ve ever written a curve serialization tool in Maya, you probably have worked with knots. Knots essentially describe the amount of influence each control point has on each part of a curve. They also allow us to modify our curves shape by adding corners or form loops. A basic knot vector might look something like this:

Press enter or click to view image in full size

Evaluating Splines

With an explanation of the knots out of the way, we can actually get into calculating a point on a spline. This is where things get a bit more complicated, and unlike Bezier curves I don’t think it’s very helpful to show the formula. Unlike Bezier curves we often use an algorithm to generate points on spline curves. Personally I used de Boor’s algorithm as the wikipedia page actually provided simple python code to implement it.

Spline Surfaces

With the bulk of the math explanation over with, I’d like to conclude with a quick explanation of surfaces as well. While they might seem to be more complicated than spline curves, they’re actually quite similar and only require one additional matrix node.

Conclusion

Before this experiment I expected splines to much more complex than they actually are. After investigating it turns out they can be distilled into simple weighted sums. And once I realized this, I started to notice this pattern everywhere in rigging. Dot products, matrix multiplication, RBF solvers, and skin weights are all just forms of weighted sums!

Cole O'Brien

Written by Cole O'Brien

Cole is a technical animator at Respawn Entertainment working on Apex Legends.

Responses (1)

Write a response

Hi Cole,
This is very cool stuff, thanks for sending me down a rabbit hole of youtube videos regarding B-Splines and Bezier curves :)
I tried your example code, and cannot recreate your last example of a spline with 9 control points. In fact, anything…