Creating a Stereo-Safe Camera

digital representation of built 3d camera
Learn how to make your own stereoscopic camera in Maya with advice and custom coding from our 3D animation expert, David Hixon. It's easier than you think!
two large computer screens with 3D camera code

Last month I talked a little about stereoscopy. Today I’d like to expand a little on this with a tool to make your own stereoscopic camera. Creating a stereo camera in software like Maya can be confusing and difficult to visualize. One of the problems I’ve run into is knowing how close is too close.

However, after playing with it and looking at what others have done, I have come up with a tool that will allow you to create a stereo-safe camera. By that, I mean it helps you aim the camera while giving you a guide on how close is too close. The last thing you want to do (which I used to see all the time in theaters) is to throw something in the face of the viewers which is so close they have a hard time focusing on it. This camera rig gives you a simple guide that may be easier to use than a real-world stereo rig. And you can make it too if you want to play with stereoscopic. Without further ado, here are the steps:

1. You need to make sure the plugin is on in Maya. I am using Maya 2015 currently, I go to Window>Settings/Preferences>Plug-in Manager. In there, just make sure the “stereoCamera.bundle” plugin is turned on.

2. You need to create a stereo camera. Go to Create>Cameras>Stereo Camera (StereoCamera). This will create three cameras in a camera rig: a left and right for your stereo renders and a center, which is used to drive the others and allow you to position your camera.

3. In the center camera, you’ll want to make a few adjustments. Start with turning the Stereo type (in the attributes under Stereo>Stereo) to Off-axis. This makes gives the best 3D effect without as much distortion, and unless you are doing something specific, you should always use this setting. Next, you’ll want to adjust your focal length to whatever you want for that shot.

4. You need to open the Stereo Display Controls and make some adjustments. First, I set Display Frustum to “LeftRight”, so you can see exactly what areas your left and right stereo cameras will see and render. Next, set the Display Near Clip to Center. I’ll explain that later. Now turn on the Safe Viewing Volume. You will also want to turn on the Zero Parallax Plane and set the transparency to zero.  This will let you see a square where the screen plane lies, which is where the 3D effect is zero. Anything in front of this square will come out of the screen, and anything behind it will fall back into the screen.

5. You will want to adjust the “Interaxial Separation”, also known as the distance between the cameras. The exact number you use for this depends on the scale you use in your seen, but typically I find 2.5 works for me. This is about the distance between the eyes of the audience. Just be ready to change this if the 3D effect is too exaggerated and hard to see, or too subdued and not noticeable. I suggest eyeballing this to fit your specific artistic needs.

6. Here comes the tricky part. You want to set your Center Camera’s near clipping plane to half the distance from the camera to the Zero Parallax Plane. In other words, math and expressions.  It’s not really that hard. Just right-click on the Near Clipping Plane under Camera Attributes, and select “Create New Expression…”. Now select the text in the “Selected Object and Attribute” field and copy it into the expression field below, then type ” = ” and paste it again, but this time replace the text that says “.nearClipPlane” with “.zeroParallax”. Yes, it is case sensitive. Finally add a “/2” at the end and his create. If you did it right, it should now automatically move the near clipping plane. I’ll explain why at the end.

7. Because the center camera drives the left and the right, all these changes were applied to the entire rig, but that is a problem now. You need to fix the clipping plane in the left and right cameras, because you don’t want it to accidentally clip something that gets a little too close. To do this, you have to go into the left camera, find the Near Clip Plane field, right-click on it, and select “Break Connection”.  Then type in “.1” to reset it to the default. This will affect the look of the Safe Viewing Volume, but that’s ok. Make sure you do this to the Right camera as well.

in app screen shot of designed 3d camera



And that’s it. Not a complicated setup really. So how does it work? You want to use the Safe Viewing Volume to keep the 3D effect on the subjects on screen, and adjust the camera position, the focal length, and the Zero Parallax Plane, to make sure that the closer an object gets to the camera it is never in front of the near clipping plane indicator. This way you can avoid giving your audience a headache. In the real world, they would have to figure out the math to determine how close a subject can get, or just eyeball it with a 3D monitor setup, but here you can see exactly where the closest cut-off point is. Everything you want the audience to see should be behind the near clipping plane and inside the blue viewing angle.

The best part is you can even view your Maya scene in stereo 3D right in Maya! All you need to do is view from the Stereo Camera, and in the panel menus, go to Stereo>Anaglyph and put on a pair of those red/cyan glasses. Voila! Live interactive stereoscopic 3D!

But you don’t have to go do this all by scratch. If you really want to use my rig and try it out for yourself, just go into your script editor in Maya and paste my code (below) into a MEL tab at the bottom and turn it into a button. My script will even allow for multiple cameras ,each with a unique name without conflict between them.

Now get out there and explore the 3rd dimension. Just don’t make more zombie children.

proc stereoCamECG(){
loadPlugin -qt “stereoCamera”;
catchQuiet(` python(“from maya.app.stereo import stereoCameraRig”) `);
string $rig[] = python(“stereoCameraRig.createStereoCameraRig(‘StereoCamera’)”);
rename “stereoCamera” “stereoCam_ECG”;
rename “stereoCameraRight” “stereoCamRight_ECG” ;
rename “stereoCameraLeft” “stereoCamLeft_ECG” ;

setAttr “stereoCam_ECGCenterCamShape.stereo” 2;
setAttr “stereoCam_ECGCenterCamShape.focalLength” 50;
setAttr “stereoCam_ECGCenterCamShape.safeViewingVolume” 1;
setAttr “stereoCam_ECGCenterCamShape.displayFrustum” 3;
setAttr “stereoCam_ECGCenterCamShape.displayNearClip” 4;
setAttr “stereoCam_ECGCenterCamShape.zeroParallaxPlane” 1;
setAttr “stereoCam_ECGCenterCamShape.zeroParallaxTransparency” 0;
setAttr “stereoCam_ECGCenterCamShape.zeroParallax” 50;
setAttr “stereoCam_ECGCenterCamShape.interaxialSeparation” 2.5;
expression -s “stereoCam_ECGCenterCamShape.nearClipPlane = stereoCam_ECGCenterCamShape.zeroParallax / 2”  -o stereoCam_ECGCenterCamShape -ae 1 -uc all ;
setAttr “stereoCam_ECGCenterCamShape.safeVolumeTransparency” 0.2;

  disconnectAttr stereoCam_ECGCenterCamShape.nearClipPlane stereoCamRight_ECGShape.nearClipPlane;
setAttr “stereoCamRight_ECGShape.nearClipPlane” 0.1;
rename “stereoCamRight_ECG” “stereoCamRight_01”;
disconnectAttr stereoCam_ECGCenterCamShape.nearClipPlane stereoCamLeft_ECGShape.nearClipPlane;
setAttr “stereoCamLeft_ECGShape.nearClipPlane” 0.1;
rename “stereoCamLeft_ECG” “stereoCamLeft_01”;
select “stereoCam_ECG”;
rename “stereoCam_ECG” “ECGStereoCam_01”;
}  

stereoCamECG ();
  scriptEditorInfo -e -suppressWarnings true;
  scriptEditorInfo -e -suppressInfo true;
  scriptEditorInfo -suppressErrors true;
  print “ECG Stereo Safe Camera created”;

One Response

  1. hi, thanks for this info 🙂

    i tried pasting your code into the mel box and i get an error: line 2.16; syntax error.

    I’m a bit new to maya so i have no idea what this means…

Leave a Reply

Your email address will not be published. Required fields are marked *