Maya Python API图像平面数学

时间:2013-08-09 14:20:34

标签: python api math maya plane

任何人都知道根据相机光圈,焦距,过扫描和分辨率计算图像平面的数学运算?

我基本上只是试图制作一个基于代表图像平面的当前视口的平面。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

你几乎肯定会遇到一个令人恼火的事实,即Maya以英寸存储相机后孔,但焦距为毫米。因此:

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

答案 1 :(得分:0)

This should be all the math you'll need to do this. 经过大量的研究才找到它!