カメラの口径、焦点距離、オーバースキャン、および解像度に基づいてイメージ プレーンを計算するための数学を知っている人はいますか?
私は基本的に、イメージ プレーンを表す現在のビューポートに基づいたプレーンを作成しようとしています。
助けてくれてありがとう。
ほとんどの場合、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
これは、これを行うために必要なすべての計算である必要があります。 それを見つけるためにたくさんの研究が必要でした!