0
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のカメラをなんとかしたい3 ~反転カメラをつくりたい~

0
Last updated at Posted at 2025-12-07

mayaで位置ではなく、画面の左右を反転させたカメラが欲しいなぁ・・・・ というリクエストをもらいました。

つまり、

こういう見た目が
image.png

こうなってほしい
image.png

検証

さてどうやったら反転できるのか・・・
viewPort周りのプラグインを作ったらできそうですが、そんなスキルは生憎持ち合わせておらず。

とりあえず、なにも考えずにカメラのスケール値を反転させてみます。

image.png

特になにも様子は変わりません。
image.png

よし、無理。
と 一旦諦めましたが、もう1個だけ試してみます。
inverseScaleコネクトのような処理が入ってるかもしれないので、親グループを作成しそこでスケールを掛けてみます。

まさかの成功。

image.png

他の軸でも反転してくれますね。

他の機能も念のため確認しておきます。

例えば filmOffset

image.png

image.png

んー これはどうやら 反転の後にfilmOffsetの影響が掛かってますね。

イメージ的にはこうなってほしいですね。
なので、反対の数値を入れる必要があります。
image.png

そのままで良いアトリビュートと反転させる必要があるアトリビュートがあるということがわかりました。

実装

単一のカメラ内でやっても良いのですが、元の数値が迷子になると怖いので

  • ターゲットのカメラを複製
  • 親ノードを同一の位置に作って親子化
  • 親ノードのスケールを -1
  • 親ノードをターゲットのカメラでparentConstraint
  • 反転不要アトリビュートはそのままコネクト
  • 反転必要アトリビュートはノードを挟んでコネクト

こんな感じで処理しようと思います。

import maya.cmds as cmds
def createMirrorCam(target,replace = True):
    if cmds.listRelatives(target,type = "camera") == None:
        return
        
    cameraName = target.split(":")[-1]
    mirrorCam = cameraName + "_rev"
    parent = cmds.createNode("transform", name = mirrorCam + "_parent")    
    
    if cmds.objExists(mirrorCam):
        if replace:
            cmds.delete(mirrorCam)
            cmds.delete(parent)
        else:
            return
    
    if cmds.objExists(mirrorCam) == False:
        nodes = cmds.duplicate(target)
        cmds.refresh()
        cmds.rename(nodes[0], mirrorCam)
        
        cmds.parentConstraint(target,parent,mo =False)
        cmds.parent(mirrorCam,parent,a=True)
        cmds.setAttr(parent + ".sx",-1.0)
        
        revAttrs = ["horizontalFilmOffset","verticalFilmOffset","filmRollValue"]
        
        for attr in revAttrs:
            revMath = cmds.createNode("floatMath")
            cmds.setAttr(revMath + ".operation",2)
            cmds.connectAttr(target + "." + attr,revMath + ".floatA")
            cmds.setAttr(revMath + ".floatB",-1)
            cmds.connectAttr(revMath + ".outFloat" , mirrorCam + "." + attr,f=True)
            
select = cmds.ls(sl =True)
target = select[0]
createMirrorCam(target)

上手いこと反転してくれました。

image.png

ちなみにこのカメラ
一応レンダリング結果にも反映されます。
ただし細かい素材の出力結果までは確認できていません。

0
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
0
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?