Page 1 of 1

My camera locator script for Maya

Posted: Thu Oct 22, 2009 5:35 pm
by cgbeige
This might exist already but I was tired of creating these by hand so I made a script to automate linking of a distance locator with the selected camera's Maxwell focus distance. Before you run the script, you have to enable use manual focus distance in the camera shape node and – VERY IMPORTANT – change the value to something before running the script. It seems that the mxFocusDistance attribute isn't actually created or enabled until you change the value – I tried adding "setAttr ($each + ".mxUseFocusDistance" ) 1" to the script but it fails so you have to do this manually. Anyway, with a distance tool created and locator2 (the default second locator in a distance tool) to be moved to your camera location, select your camera and run this script.
Code: Select all
string $mySelection[] = `ls -sl`;
string $shapes[] = `listRelatives -shapes -noIntermediate $mySelection`;
for($each in $shapes) 
{
	float $p[]= `xform -q -ws -t`; move -a $p[0] $p[1] $p[2] locator2;
	connectAttr distanceDimensionShape1.distance ($each + ".mxFocusDistance" );
	select -af locator2;
	Parent;
}
You will now have your Maxwell focus point always on the first locator.

Re: My camera locator script for Maya

Posted: Thu Oct 22, 2009 6:08 pm
by Mihnea Balta
The custom attributes (camera focus distance, the checkboxes on the mesh nodes etc.) aren't added until you change them from their default value because we don't want to bloat the scene with them, and to simplify their management (otherwise we'd have to install a hook when nodes are created or scenes are loaded, and inject the attributes, which can cause performance and stability problems). Anyway, you can add the attributes from your script if they don't exist with something like this:
Code: Select all
if(!`attributeQuery -node $each -exists "mxUseFocusDistance"`)
    addAttr -longName "mxUseFocusDistance" -attributeType "long" -defaultValue 0 $each;
setAttr ($each + ".mxUseFocusDistance") 1;

if(!`attributeQuery -node $each -exists "mxFocusDistance"`)
    addAttr -longName "mxFocusDistance" -attributeType "double" -defaultValue 50.0 $each;

connectAttr distanceDimensionShape1.distance ($each + ".mxFocusDistance" );
/* etc. */
You can also change the "Controls" attribute to "Camera and Aim" and uncheck "Manual Focus Distance", in which case the focus point will be the aim locator of the camera, but I don't know if that's convenient for your purposes.

Re: My camera locator script for Maya

Posted: Thu Oct 22, 2009 6:22 pm
by cgbeige
awesome - thanks Mihnea.

Re: My camera locator script for Maya

Posted: Tue Feb 02, 2010 4:18 pm
by powercreative
I have issues where the camera preview in Maya is not the same as the render. It either looks really zoomed in or out. What causes this? I tried adjusting the horizontal and vertical aperture which seems to adjust it, but what is the relevant math to get it to match the viewport preview? Also, does overscan affect this? Any input appreciated.

Someone should try to integrate something like Reticle into Maya for use with maxwell, that would be interesting and likely quite helpful.
http://vimeo.com/6186489


Thanks Joel E.

Re: My camera locator script for Maya

Posted: Tue Feb 02, 2010 5:16 pm
by Mihnea Balta
Maxwell renders what you see when you select "Resolution Gate" in the View -> Camera Settings menu. It's a good idea to match the aspect ratio of the film gate (Camera attributes -> Film Back -> Aperture) to that of the resolution, but the framing you get with Maxwell shouldn't be different from what you get with Maya Software or mental ray. If you see differences, please post your camera and resolution settings, or a sample scene which exhibits the problem.

Re: My camera locator script for Maya

Posted: Tue Feb 02, 2010 6:41 pm
by powercreative
Okay, it is overscan which created my issue. If it is not set to 1, it will offset the camera on render. I use overscan to frame my shot because the aspect ratio doesn't fit in the viewport comfortably. I just have to remember to set the overscan property back to 1 before rendering or it screws up the render.

Also note that i tried adding setAttr shot2Shape.overscan 1; to the prerender mel script in the render settings dialogue, but it doesn't seem to fire that code when using the maxwell renderer. Not sure if this is a plugin bug or what, but wanted to mention it. The actual attr is defaultRenderGlobals.preMel

Re: My camera locator script for Maya

Posted: Tue Feb 02, 2010 8:40 pm
by Mihnea Balta
But as far as I can tell, overscan also produces a mismatch between the viewport and the render with Maya Software. It's supposed to be a display only parameter, without any influence on the rendered output (regardless of the value you set there, the same image will be rendered always). Am I wrong?

About the prerender script, I've just tried it with 2008 and 2010 and it seems to work. Which Maya version are you using?

Re: My camera locator script for Maya

Posted: Tue Feb 02, 2010 10:56 pm
by powercreative
I've always used overscan to more easily work with odd render sizes. It helps fit everything in the viewport so you can frame your shot. With Mental Ray and Maya Software it doesn't affect the render at all, but with Maxwell it seems to inherit overscan somehow, zooming your frame in or out according to the overscan value. A test scene can easily be made with some boxes. Set the render size to letter, 2550x3300 and correct the camera aperture to .773x1, same as the aspect ratio. if you frame your shot with overscan at like 2(to see everything), and render they will not match. If you set overscan to 1, they will match. It seems like other renderers know to ignore the display only flag but maxwell is utilizing it. I am fine with that, but I had to figure it out first. Maxwell 2.0.1 with plugin 2.0.33 and Maya 2010.

Re: My camera locator script for Maya

Posted: Wed Feb 03, 2010 1:07 pm
by Mihnea Balta
Sorry, but I really can't reproduce this. I've made a scene with your settings (except I'm using 255x330 instead of 2550x3300) and I get the same rendered image no matter what I set overscan to. Here's a screenshot from Maya (resolution gate enabled):

Image

Here's what I get out of Maxwell, regardless of the overscan value:

Image

Here's the same scene rendered with Maya Software, identical framing:

Image

Do you have any camera plug-ins or anything else that could affect this?

Re: My camera locator script for Maya

Posted: Wed Feb 03, 2010 7:32 pm
by powercreative
I got the same results when starting a new. Totally baffled, I started running a series of tests and the scenes that were doing that same issue for 3 days are no longer doing it. I can not repeat the problem. I hate when scenes do that... it's like they are mocking me!

Totally weird. If it happens again, I will save the scene and post it here.

Arg.