1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mayaのカメラをなんとかしたい2 ~vartical を horizontal へ~ おかわり

1
Last updated at Posted at 2025-12-02

以前のこれですが、なんかうまくいかない

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)
	

これをー

image.png

switchCameraFit("persp1")

こう

image.png

もう一回かけてー

switchCameraFit("persp1")

image.png

こんどは大丈夫ですかねぇー

ただ1つ心配なのは、
postScale値の初期値を記憶させてるわけではないので
何度も繰り返し処理していくと数値が徐々にずれていくんじゃぁないかなぁということですね。

なので、ちゃんとツール化するのであれば
vertical / horizontal それぞれの時のpostScale値を取得しておいて、それを呼び出して切り替える
という風にしたいですね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?