This should be all the math you'll need to do this. Took lots of research to find it!
Maya Python API Image Plane Math
题
Anyone know the math for calculating an image plane based off camera aperture, focal length, overscan, and resolution?
I basically just trying to make a plane that's based off the current viewport that represents an image plane.
Thanks for any help.
解决方案 2
其他提示
You'll almost certainly run into an issue with the irritating fact that Maya stores the camera back apertures in inches but the focal length in millimeters. Hence:
import math
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
# maya uses INCHES for camera backs
# but MILLIMETERS for focal lenghts. Hence the magic number 25.4
def get_vfov (camera):
'''
returns the vertical fov the supplied camera, in degrees.
'''
fl = cmds.getAttr(camera + ".focalLength")
vfa = cmds.getAttr(camera + ".vfa") * 25.4 # in mm
return math.degrees ( 2 * math.atan(vfa / (2 * fl)))
def get_hfov (camera):
'''
returns the horizontal fov the supplied camera, in degrees.
'''
fl = cmds.getAttr(camera + ".focalLength")
vfa = cmds.getAttr(camera + ".hfa") * 25.4 # in mm
return math.degrees ( 2 * math.atan(vfa / (2 * fl)))
def get_persp_matrix (FOV, aspect = 1, near = 1, far = 30):
'''
give a FOV amd aspect ratio, generate a perspective matrix
'''
matrix = [0.0] * 16
fov = math.radians(FOV)
yScale = 1.0 / math.tan(fov / 2)
xScale = yScale / aspect
matrix[0] = xScale
matrix[5] = yScale
matrix[10] = far / (near - far)
matrix[11] = -1.0
matrix[14] = (near * far) / (near - far)
mmatrix = OpenMaya.MMatrix()
OpenMaya.MScriptUtil.createMatrixFromList( matrix, mmatrix )
return mmatrix
不隶属于 StackOverflow