以前のこれですが、なんかうまくいかない
getRenderingFrustum が取れたり取れなかったりなので、
なんだか安定しないんですよねぇ
整理して考える
filmApertureの横基準か、縦基準かを考慮して
設定された解像度からresolutionGateサイズの比率を求めます。
それをV,Hそれぞれ求め、postScale値を求める
import maya.cmds as cmds
import maya.api.OpenMaya as om2
def convertFilmFitToPostScale(source,resolutionW,resolutionH):
postScale = 1.0
sourceCamDAG = om2.MGlobal.getSelectionListByName(source).getDagPath(0)
sourceCamFn = om2.MFnCamera(sourceCamDAG)
if cmds.getAttr(source + ".filmFit") == 1:#H to V
deviceAspectRatio = resolutionH / resolutionW
sourceResH = sourceCamFn.horizontalFilmAperture * deviceAspectRatio
sourceResW = sourceCamFn.horizontalFilmAperture
deviceAspectRatio = resolutionW / resolutionH
targetResH = sourceCamFn.verticalFilmAperture
targetResW = sourceCamFn.verticalFilmAperture * deviceAspectRatio
postScale = targetResH / sourceResH
elif cmds.getAttr(source + ".filmFit") == 2:#V to H
deviceAspectRatio = resolutionW / resolutionH
sourceResH = sourceCamFn.verticalFilmAperture
sourceResW = sourceCamFn.verticalFilmAperture * deviceAspectRatio
deviceAspectRatio = resolutionH / resolutionW
targetResH = sourceCamFn.horizontalFilmAperture * deviceAspectRatio
targetResW = sourceCamFn.horizontalFilmAperture
postScale = targetResW / sourceResW
return postScale
def switchCameraFit(cameraName):
resolutionW = cmds.getAttr("defaultResolution.width")
resolutionH = cmds.getAttr("defaultResolution.height")
postScale = convertFilmFitToPostScale(cameraName,resolutionW,resolutionH)
if cmds.getAttr(cameraName + ".filmFit") == 1:
cmds.setAttr(cameraName + ".filmFit",2)
elif cmds.getAttr(cameraName + ".filmFit") == 2:
cmds.setAttr(cameraName + ".filmFit",1)
cmds.setAttr(cameraName + ".postScale",cmds.getAttr(cameraName + ".postScale")*postScale)
これをー
switchCameraFit("persp1")
こう
もう一回かけてー
switchCameraFit("persp1")
こんどは大丈夫ですかねぇー
ただ1つ心配なのは、
postScale値の初期値を記憶させてるわけではないので
何度も繰り返し処理していくと数値が徐々にずれていくんじゃぁないかなぁということですね。
なので、ちゃんとツール化するのであれば
vertical / horizontal それぞれの時のpostScale値を取得しておいて、それを呼び出して切り替える
という風にしたいですね。


