Focal lengthで画角を指定したV-Ray Physical Cameraからfovを取得するテストスクリプト。
Mayaのカメラなら以下のようにfilmWidthとfocalLengthから計算できますが、MaxのV-Ray Cameraでは被写体までの距離が必要です。
def angleOfView(filmWidth,focalLength):
angle = 2 * math.atan(float(filmWidth) / (2*float(focalLength)))
angle = math.degrees(angle)
return angle
Angle of viewの「Derivation of the angle-of-view formula」が参考になります。
import MaxPlus
import math
def angleOfView(filmWidth,focalLength):
angle = 2 * math.atan(float(filmWidth) / (2*float(focalLength)))
angle = math.degrees(angle)
return angle
def angleOfViewVrayCamera(filmWidth,focalLength,distance):
focalLengthWithMagFactor = distance * focalLength / (distance - focalLength)
angle = angleOfView(filmWidth,focalLengthWithMagFactor)
return angle
def getVRayCameraFocusDistance(node):
objPBlock = node.Object.ParameterBlock
distance = 0.0
if objPBlock.targeted.Value and (not objPBlock.specify_focus.Value):
targetNode = node.GetTarget()
vec = targetNode.GetWorldPosition() - node.GetWorldPosition()
distance = vec.GetLength()
elif (not objPBlock.targeted.Value) and (not objPBlock.specify_focus.Value):
distance = objPBlock.target_distance.Value
elif (not objPBlock.targeted.Value) and objPBlock.specify_focus.Value:
distance = objPBlock.focus_distance.Value
return distance
def getVRayCameraFOV(node):
objPBlock = node.Object.ParameterBlock
fov = 0.0
if objPBlock.specify_fov.Value == True:
fov = objPBlock.fov.Value
else:
fov = angleOfViewVrayCamera(
objPBlock.film_width.Value,
objPBlock.focal_length.Value,
getVRayCameraFocusDistance(node))
return fov
if __name__ == '__main__':
if MaxPlus.SelectionManager.GetCount() != 0:
selNode = MaxPlus.SelectionManager.GetNode(0)
if selNode.Object.GetClassName() == 'VRayPhysicalCamera':
print getVRayCameraFOV(selNode)
else:
print "Selection is not V-Ray Camera."
else:
print "Select V-Ray Camera."
はじめてPythonAPIを使ってみました、Maxの中にPythonエディタが搭載されてるわけでは無いんですね。APIリファレンスの情報量も少ないなー。