Importing a Maya Camera and Locators into After Effects - For 2D and 3D Integration
When you need to add a few simple effects, text or 2D objects within a 3D scene, doing it in Maya can be inconvenient. With the right render passes and workflow you can easily integrate 2D and 3D objects within After Effects. Using the camera data from Maya, you can place 2D objects in 3D space that will use a 3D camera exported from Maya. If you’ve ever imported a Maya Camera into After Effects, then you know it can be a cumbersome process at first. If you have never done this but would like to, then you have come to the right place. There are a few different file types that After Effects can natively open that supports camera data. Discreet RLA/RPF (RLA, RPF; 16 bpc; imports camera data) Maya camera data (MA) To learn about more file types supported by After Effects, take a look at this reference PDF from Adobe. These two file types can be used to import camera data into After Effects. In this article we will focus on using the Maya ASCII file type to import camera data. The best place to start when you want to import Maya camera data into After Effects is after you have finalized any modeling, texturing, animation and render passes in Maya. Depending on your final look for the project you might want to have a depth pass and an alpha or material ID pass. If you are unfamiliar with setting up Maya render passes, take a look at our tutorial on Render Passes that gets you comfortable setting up passes for compositing. Once you have your scene setup, it is time to work on your camera animation. If you want to become more familiar with Maya cameras and start creating custom rigs, watch Introduction to Camera Animation in Maya. For the sake of this article, we will be using a custom camera rig created by one of our tutors. You can use this MEL code to create the same camera rig:
//Cam Path Tool //Instructions: run code :). Feel free to add to shelf "CPT" int $i = $i + 1; //Camera string $camera = `camera`; string $rnm_cam = `rename $camera ("shotCam_0" + $i)`; //Curve string $path_crv = `curve -d 1 -p -12 0 0 -p -9 0 0 -p -6 0 0 -p -3 0 0 -p 0 0 0 -p 3 0 0 -p 6 0 0 -p 9 0 0 -p 12 0 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 `; rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 1 -kep 0 -kt 1 -s 2 -d 3 -tol 0 $path_crv; string $rnm_pathCrv = `rename $path_crv ("pathCurve_" + $rnm_cam)`; //Locators string $loc_pivot1 = `spaceLocator`; string $loc_pivot2 = `spaceLocator`; string $rnm_loc_piv1 = `rename $loc_pivot1 ("locPiv_1_" + $rnm_cam)`; string $rnm_loc_piv2 = `rename $loc_pivot2 ("locPiv_2_" + $rnm_cam)`; //Parenting parent $rnm_loc_piv2 $rnm_loc_piv1; parent $rnm_cam $rnm_loc_piv2; //Point On Curve string $poci_cam = `createNode -n ("poci_" + $rnm_cam) pointOnCurveInfo`; setAttr ($poci_cam + ".turnOnPercentage") 1; //Connect string $getShp_pathCrv = `listRelatives -type shape $rnm_pathCrv`; connectAttr -f ($getShp_pathCrv + ".worldSpace") ($poci_cam + ".inputCurve"); connectAttr -f ($poci_cam + ".position") ($rnm_loc_piv1 + ".translate"); //Controlling attribute addAttr -ln "pathPercentage" -at double -min 0 -max 1 $rnm_cam; setAttr -e-keyable true ($rnm_cam + ".pathPercentage"); connectAttr -f ($rnm_cam + ".pathPercentage") ($poci_cam + ".parameter");This rig creates two locators and one camera then attaches them to a path. A custom attribute is added to the camera titled 'Path Percentage'. This attribute has an editable value from zero to one that can be used to animate the camera along the path. As you see below, the camera is parented to a locator and that locator is parented to a second locator. You can use these two locators to further refine your camera animation along the path. In this article, we will just modify the camera itself to keep it simple. When you run the MEL script, your rig will be create on a path. You add or remove points to the path and move the Control Vertices as needed to guide your camera however you need to. In this example we will be using an Audi R8 that has not been animated, it will just be a static mesh. If you take a look at the video below you will see that the camera is animated along the left side of the vehicle, around the front and then down the right side of the vehicle. Now that our camera animation is setup, it’s time to add a few locators in the scene. These locators will be imported into Maya as Null objects. These will be used as reference points in After Effects on where you would like to have text, particle emitters or anything else you can imagine. These can also be used to establish a ground plane within After Effects. If you render just the vehicle, we can add a plane in After Effects using the position data provided by the locator. Here, a locator is placed at the bottom vertex of the tire and at the center of the car. You can snap the locator's Y position by highlighting the Y axis, holding down V and middle mouse clicking on the vertex you want to snap to. Add a locator for where you would like the text to sit within the 3D space. Here, one was added just a little ways from the driver's side mirror. The locator was also rotated to have the same orientation as the vehicle. This will give us the rotate data we need if we decide to have the text match the orientation of the car. Once the locators are in place, it is time to name them. Then that will be used to give the position of the ground name 'Null_Floor'. On the locator that will provide the position of the text name 'Null_Text'. This is so that you can easily find the null object in After Effects. In this example we only have two locators, but organization is important if you will be using a lot of different locators. The scene is now setup and it’s time to bake the camera animation down before exporting it for After Effects. This is a crucial step, so always remember to bake down your Maya camera before export. If you created a camera that you did not attach to a curve, then all you need to do is back the camera simulation. To do that, select the camera and go to Edit > Keys > Bake Simulation. Using the default settings on bake simulation will work fine. When you attach a camera to a curve, the camera's translate values do not correspond with world values because it is connected to the curve. A few additional steps will be required to get a camera with world values that update each keyframe. To do this, you will need to create a new camera by going to Create > Cameras > Camera. Rename this camera to shotCam2 Select the camera you have attached to the curve, shotCam1, and shift-select the camera you just created, shotCam2. Under the animation toolset, go to Constrain > Parent. This will constrain the shotCam2 to the camera on the path, and allow the new camera to follow the path while also using world values, both position and orientation. If you plan on using this workflow often, it is recommended that you create a custom shelf with all of these tools that you will be using to create this. If you are unsure how to create custom buttons and shelves take a look at this article on Creating Custom Shelves and Buttons in Maya. Select shotCam2 and go to Edit > Keys > Bake Simulation. When the simulation is baked you should see a red line on each frame indicating that a keyframe has be set on the Maya timeline. Cleaning up the Maya file is the last step before you start up After Effects. Before you delete anything in the file save it as a copy, and add 'camera' to the file name so that you know it is only the camera and locators contained in the file. This will allow you to decrease the file size and empty out the file to prevent any read errors from After Effects. With the file named, delete everything in the file except the locators that have been named and the camera that has been baked down. In this instance it would be shotCam2. Start up After Effects and create a new project, or open the project you wish to add the camera data to. Import your render sequence or sequences if you created render passes of your 3D model that you wish to add things to in After Effects. Then, import the MA file with camera in the title name. When this file is imported a composition will be created that matches the length of you Maya scene. In the example below we are just using one color sequence and the composition contains a camera and two null objects. The After Effects Camera and Maya Camera do not use the same unit of measurement to define 3D space. The fastest way to fix this issue is to create a new null object named 'ObjectScale' in After Effects, this will be used to adjust the scale of you imported Maya objects. Parent the imported Maya camera as well as the null objects that were imported, in this instance the two titled Null_Floor and Null_Text, to the null you just created called ObjectScale. On the ObjectScale null, adjust the scale to 10000. This will make the Maya object inherit that scale attribute. Now delete the ObjectScale null. It is important to delete this null with the imported objects still parented to the null. This will allow those objects to inherit the new scale. On the two null objects, Null_Floor and Null_Text, adjust the scale back down to 10 so that they are not large squares floating within the scene. Create your text that you would like to put floating next to the car in this scene and pre-compose the text. Open up the new composition that contains the text and frame the text in the composition nicely and close the composition. From here you will copy the attributes of Null_Text over to the composition containing the text. Make the text composition 3D in After Effects and copy over the X, Y and Z position attributes. Now copy over the rotation or orientation attributes to the corresponding attributes on the text composition. Then adjust the text composition's anchor point to 0,0,0. This will make the top left corner of the composition the origin for the anchor point. If you want to make slight adjustments to the placement of the text composition, use the anchor point to move it in the X, Y and Z space. You can achieve a similar effect with Null_Floor to add a plane for the car to sit on. Take a look below to see what the outcome can look like. With these new techniques, you can start integrating 2D objects with your 3D renders from Maya in just a few clicks. Not a Maya user? Be sure to check out Getting Started with CINEWARE in After Effects if you are a CINEMA 4D user. If you prefer to use 3ds Max take a look at Utilizing State Sets in 3ds Max to learn similar techniques.