Friday, 16 February 2007

3D camera tracking data import into After Effects troubleshooting

Almost everyone trying to import 3D camera data created in matchmove programs into AE has run into some problems from time to time. I hope this article can be helpful to solve some of these problems.
In this troubleshooting article i'm not gonna write about import from Maya. Primarily because i don't own the software and also since it seems that with the right settings in Maya the import into AE is very reliable.
That reliability was and is unfortunately not always given with the export from a matchmove program (because of AE or the matchmove program?).
The usual import route to AE is via the Maya ma format. The only exception i know of is the import from Boujou via the Boujou ban format with a free AE plug in from 2d3 (for me this worked pretty well sometimes and sometimes it didn't work at all).
The import via the ma file format can create a lot of problems. It seems that Maya can read the exported files from matchmove programs well but AE is a little bit more demanding. This results in the usual 320x240 comps with missing tracking marker nulls etc.. Very annoying to say the least.
The workaround for this for many people was to import the file into Maya and then export a Maya file that AE can import properly.
Now with newer versions of Boujou and also SynthEyes there's an export option called AE Maya format that puts out a ma file that AE can read well (if you know other 3d tracking software with this feature let me know).
Although i always wanted to know why the standard ma import didn't work well with AE, the availability of the new AE Maya format export options made me forget about this problem.
A recent discussion at fxphd reawakened my interest in that topic.
As a result i checked the differences between the AE Maya and standard Maya format to find out what causes the indigestion in AE and how to change the standard maya file to make it work.

So this is designed as a help if you only have matchmoving software that doesn't feature an AE Maya export option ( like Realviz's Matchmover ) or if you're just stranded with a standard maya file.

For my testing i only had 2d3's Boujou Bullet PXC and Realviz's Matchmover 4 Pro available ( thanks to the Pixelcorps ).
The example code below is from an standard maya file exported from Matchmover Pro 4 but the solutions are easily applicable to files exported from other matchmove programs.

Overall tips:
- don't export 2000 tracks etc.. only export a couple hundred or the ones
you need. Otherwise AE won't be able to handle it.
- try to use the scaling with a coordinate system in the matchmove program to get a proper scene scale.
- try to set the coordinate axis in your tracking program to y-up and also set up a coordinate system for your solve.
Still if the tracks and camera aren't positioned and oriented properly after import you can always parent all tracks and the camera to a null and rotate and move this around.

How to make a standard Maya ma file work with AE:

1. Backup your ma file (at a safe place!) and then open it in a standard text editor ( i know you don't want to do this
but hey it's easy... trust me :) ).
In case the file isn't formatted properly use a different editor.

2. Go to this line:

// edit this line to change the current units
currentUnit -l cm -a deg -t film;

Check if the word after -t is set to film for 24fps, to ntsc for 30fps or to pal for 25fps;
This should usually be set to the framerate that was used in the matchmoving program.
In one test with Matchmover it was set to film instead of ntsc.

3. Go to this line:

// the five next lines set global render attributs
// comment or edit these lines as necessary
select -ne defaultResolution;
setAttr ".w" 720;
setAttr ".h" 480;
setAttr ".dar" 1.34997;
setAttr ".ldar" yes;

Add a colon before “defaultResolution” so you get this ( if you use Matchmover also correct the typo in attributs ;) ):

// the five next lines set global render attributes
// comment or edit these lines as necessary
select -ne :defaultResolution;
setAttr ".w" 720;
setAttr ".h" 480;
setAttr ".dar" 1.34997;
setAttr ".ldar" yes;

Now this little colon solved the 320*240 comp issue. If you save now and import to AE your comp should be the correct size and framerate and you should have a correct camera motion (only the tracking points are still missing).
What would interest me is if the Maya ma format specification actually requires this colon and Maya is just more forgiving on import or if the AE import is too unforgiving?

Ok let's continue with making the tracking points show up in AE.

4. Check out this line which stands for one track (different programs put out different naming and parenting, also in this example it is an Auto track while there could also be differently named tracks like locators, manual tracks etc.) :

createNode transform -n "Auto0000" -p "Auto_Tracks";
setAttr ".t" -type "double3" 7.86996 4.28757 -15.3173;
setAttr ".s" -type "double3" 1 1 1;
createNode locator -n "Auto0000Shape" -p "Auto0000";
setAttr -k off ".v";

To make it work properly it should look like this:

createNode transform -n "Auto0000";
setAttr ".t" -type "double3" 7.86996 4.28757 -15.3173;
setAttr ".s" -type "double3" 1 1 1;
createNode locator -n "null_Auto0000Shape" -p "Auto0000";
setAttr -k off ".v";

AE won't create a null for your tracking point if the locator name doesn't start with “null_”.
If you leave the “-p "Auto_Tracks" “ in there (which is a command for parenting) AE will create 2 nulls or more with loads of parenting for every single Track which is unnecessary.
Test it out yourself and get rid of it.
The first attribute is the position of the null and the second the scaling. Scaling will determine the scaling percentage of the nulls created in AE during import. Every track you exported from your matchmoving program will result in the creation of a null with a size of 100x100 pixels.
Scaling set to 1 ( 1% ) will result in a reasonable null size in your comp (although this depends a lot on your scene scale, in a large helicopter shot this could need to be set higher). You can of course also change this in AE after import. In the Matchmover Pro export dialog, point scale will set this value. In Boujou i think it defaults to 5.

Changing those names etc. is best done with the replace function in your favorite editor where you should have an interface similar to this:

Replace: createNode locator -n "
by: createNode locator -n "null_


Replace: -p "Auto_Tracks"

Clicking "replace all" will make the computer do all the work on the hundreds of tracks.

5. Save the file. Import into AE and be happy! :) In case something doesn't work, play around with the file some more or write me a comment that my instructions are crap ;).

Disclaimer: I'm not responsible for messed up maya files. Make a copy of the file to a safe place before playing with it.