View Full Version : creating image plane with planes?
05-30-2012, 10:34 PM
Im trying to get a plane in front of my cameras similar to an imagePlane and it needs to match the resolution of the camera.
Here is the script so far
So my question is: How can i get a plane to fit the camera resolution gate?
Iv tried a bunch of the flags with the camera() cmd with no luck.
I was working on that particular problem a long while ago (trying to create a nice camera shot overlay with info).
I'm pretty sure there is a mathematical method to figure it out using the distance of the plane from the camera, the field of view, the focal length and the camera's view vector to figure it out perfectly, but I don't know the math and I'M too stupid.
So instead I worked with a hack: I placed a plane flat on the grid, made sure its dimensions matched the render resolution (queried from renderGlobals), used the viewHeadOn command to position the camera so that the plane filled the view, parented the plane to the camera and return the camera to its original position.
IIRC some custom scaling was necessary to perfectly align the edges, but all in all it did the job.
I'm sure someone out there can give you a more precise and elegant solution though. Maybe Zoharl or Nathan?
06-02-2012, 05:39 PM
Nyro is right, there is a mathy way to figure out the distance using the field of view (more specifically the camera aperture), the focal length, and the resolution. It's a little tricky to explain...but I'll give it a shot...
You first need to start with a base aperture. A default Maya camera is 1.417 x 0.945 in. Equivalent to 36 x 24 mm. No let's say we take the default resolution of 640x480, this gives us (32x24) x 20 ... 20 times the base aperture. (I'm only looking at the vertical). Given a focal length of 35, this is leads to place a 640x480 scaled plane in Maya 700 units away by simply multiplying the focal length by the multiplication factor (35x20).
But I know what you're thinking, I'm working in HD, that example is so 2004. Well I feel you man, I feel you. So let's say instead, we're working in 720p. We change the scale of our plane to 1280x720. Now we change the aperture. We can either change the vertical or the horizontal. Let's change the horizontal giving us 2.51911x0.945 inches...equivalent to 42.666667x24 mm. This is our new base. 1280x720 is 30 times the base. To determine the distance, multiply your focal length by the base.
And just cause I'm having such a good time doing this, I'll throw in a real world example. The Canon 7D has a sensor size of 22.3 x 14.9 mm for images. When you're shooting video, it windows to 22.3 x 12.54375 mm (16:9). Equivalent to 0.87775 x 0.4937 inches. This is our base. You'd use the inch measurements in you horizontal and vertical measurements respectively to match a Maya cam with 7D. 1280 x 720 is 57.3991 times our base. So at 720p and a focal length of 100, the distance we'd set a plane scaled to 1280 x 720 is 100 x 57.39991 = 5739.991 units.
Hope this helps!
Sounds nifty, but somehow the math doesn't pan out as expected for me.
Using the values for 640x480, the plane does not fill the entire view when placed 700 units away from the camera.
Interestingly though, those 700 units work perfectly for the 1280x720 example...
06-02-2012, 09:03 PM
Hmm...not sure...I just tried it again...
Horizontal film aperture: 1.417 in. (36mm)
Vertical film aperture: 0.945 in. (24mm)
Resolution: 640 x 480
Plane scale: 640 x 480
Focal length: 35
fits snug as a bug.
Maybe I'm missing something?
Does overscan change anything for you?
06-02-2012, 10:12 PM
Ah...As a matter it does. Turning overscan on causes my method to fail. I simply turned on the resolution gate and set that bottom section to "Fill". I'd have to investigate why the math is altered with overscan on.
But according to the docs:
"If the resolution gate and the film gate have the same aspect ratio, these settings have no effect. The default setting is Fill. "
Just a guess...but the default settings have mismatched aspect ratios. The aperture settings have a 1.5 aspect ratio while the resolution gate has a ratio of 1.3333. This might account for the discrepancy?
Ah. I had it set to horizontal instead of fill (its default for me). I don't claim to fully understand all the options... will ahve to play around. But still good to have the math to do it without hacks.
06-04-2012, 03:42 PM
i just uploaded a script (MEL) that might do what you are looking for ...
some additional info on my blog. hope this helps.
EDIT: link works now ...
in maya 2013 the free image planes are now a shape node...
maybe thats interesting for you...
Very cool. May I ask why you chose to use clusters and constraints for this setup?
06-04-2012, 04:45 PM
the maya 2013 info is good news indeed! :) - sadly i dont have 2013 yet :(
guess i found it easier back then to simply pin the corners to the calculated positions, than calculating the size from the positions and translating them into a scale value for the plane (which definitely could've been an option as well). maybe there was even another reason for it - honestly, i don't really remember :D since it's quite some time ago that i wrote the script. i just dug it out & repacked it into a tool when i read this post. ;)
if you're having any trouble with the setup just let me know and i'll see what i can do ...
06-04-2012, 05:45 PM
A most interesting approach. Good stuff!
In your posted script, I noticed you are mixing and default maya python and pymel...usually, this isn't a good thing to do. Also, just out of curiosity, why use a mesh and not the image plane background on the camera. Just wondering what spawned this little conversation. :)
06-04-2012, 08:36 PM
im doing some image matching , and originally the cam matches were going into unity, so they needed a mesh to display the image.
06-05-2012, 06:05 PM
i just updated the script on creative crash (http://www.creativecrash.com/maya/downloads/scripts-plugins/camera/c/image-plane-and-aspect-ratio) to work without clusters.
thanks Nyro for pointing that out! it really is much cleaner that way (only scale for size and translate for distance and offset).
also added a new bool attribute on the camera, so you can decide whether the image plane should take the film offset into account.
hope it'll be of use to someone! - cheers! :)
06-05-2012, 06:05 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.