Python Using custom exports matrix


We’re working on a custom exporter for mocha pro.
What we’re going for is a json style “data sheet”. Where we get transform (position, rotation, scale) per tracked layer and per frame.

The alternatives seem to be “surface” which look like a corner pin with 4 2d positions per frame. Or “matrix” which look like a 3x3 matrix of some sort.
I’m stuck trying to decompose it to position, rotation and scale values.
Any hints on how to move forward is greatly appreciated.


My python-fu is weak, but I will tag @martinb in who might have more insight. I assume you are already using our Python guide?

I will see what Martin has to say about it.


What system are you ultimately wanting to import the JSON file to?
The easiest path forward may just be accessing an existing export format and converting it, such as the After Effects Transform Data export.

The ultimate goal is to have a tool to transfer 2d trackers to Maya, Nuke and Houdini.
So we’ll write tools for those softwares to create locators and cameras based on the transforms from Mocha. Sort of a 2.5d setup.

Yes! The After Effects Transform Data Export is pretty close to what we’re looking for. Ideally I’d like to export all the tracked layers into one file and have nicer formatting, so we don’t have to treat everything as strings down the line.
I was under the impression that the ae exporter wasn’t written in python and hence not really accessible to us to change?

How can I create a similar exporter or adapt that exporter to do what I want? :smile:

The exporters in Python are accessible by creating a copy of that exporter then adapting it.

All exporter objects are accessible via the Mocha Python API.

Search for “Customising Existing Exporters” in the Python guide and you can see a basic example of how to set this up.

We also show you how to create a basic CSV exporter based on the surface corners in the example above that, which may help you get in the right direction.

Thanks for taking time to help me out with this!

Yes, I’m aware of those parts of the documentation.
I was sort of hoping there would be a more straightforward way to get to the data than going through the ae exporter. But I’m open to do that.

I did a quick test with the csv example, but for me it looked like the data in the csv corner pin didn’t line up with what the nuke corner pin exporter outputs, might have missed something.
But what I’m really interested in is the transform data and not really a corner pin.

I spent some time yesterday looking at algorithms to decompose matrices, like this one for example:

But, yeah didn’t get anything useful out of that.

I have a hard time letting this go. Here is the matrix for a frame in my track (but with alot less decimals).

[0.9915, -0.0022,  -0.0513]
[9.0306,  0.9971,  -0.0138]
[ 0.0,       0.0,   1.0]

The way I understand it is that the last column will be my transforms x -0.0513, y -0.0138
But how do I get that back to screen space pixel values?