玛雅胶卷矩阵

Maya Film Roll Matrix

有谁知道如何用pivot(post投影矩阵)计算maya的滚动矩阵?

目前我能得到的最好的是:

import math
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
import maya.OpenMayaUI as OpenMayaUI

# Get active view.
view = OpenMayaUI.M3dView.active3dView()

# Get camera MFnDagPath.
dagCam = OpenMaya.MDagPath()
view.getCamera(dagCam)

# Build MFnCamera.
fnCam = OpenMaya.MFnCamera(dagCam)

# Get post matrix.
postMatrix = fnCam.postProjectionMatrix()

# Get current film roll value to calculate roll.
filmRollValue = cmds.getAttr("%s.filmRollValue" % dagCam.fullPathName())
deviceAspect = cmds.getAttr("defaultResolution.deviceAspectRatio")

# This is how rotation is calculate (Where does pivot come in?)
cz = math.cos(math.radians(filmRollValue))
sz = math.sin(math.radians(filmRollValue))

# Build matrix.
matList = [0.0] * 16
matList[0] = cz
matList[1] = -sz * deviceAspect 
matList[2] = 0.0
matList[3] = 0.0

matList[4] = sz / deviceAspect
matList[5] = cz
matList[6] = 0.0
matList[7] = 0.0

matList[8] = 0.0
matList[9] = 0.0
matList[10] = 1.0
matList[11] = 0.0

matList[12] = 0.0
matList[13] = 0.0
matList[14] = 0.0
matList[15] = 1.0

# Create MMatrix.
rollMMatrix = OpenMaya.MMatrix()
OpenMaya.MScriptUtil().createMatrixFromList(matList, rollMMatrix)

# Print values.
print("\nMy Film Roll:")
for x in xrange(0, 4):
    print(round(rollMMatrix(x, 0), 3),
          round(rollMMatrix(x, 1), 3),
          round(rollMMatrix(x, 2), 3),
          round(rollMMatrix(x, 3), 3))

print("\nPost Matrix from Maya:")
for x in xrange(0, 4):
    print(round(postMatrix(x, 0), 3),
          round(postMatrix(x, 1), 3),
          round(postMatrix(x, 2), 3),
          round(postMatrix(x, 3), 3))

这不考虑胶卷轴。任何矩阵专业人士都知道这是如何计算的?

经过大量的试验和错误后,我得到了一个可以分享的答案。这目前不考虑电影翻译:

import math
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
import maya.OpenMayaUI as OpenMayaUI

# Get active view.
view = OpenMayaUI.M3dView.active3dView()

# Get camera MFnDagPath.
dagCam = OpenMaya.MDagPath()
view.getCamera(dagCam)

# Build MFnCamera.
fnCam = OpenMaya.MFnCamera(dagCam)

# Get post matrix.
postMatrix = fnCam.postProjectionMatrix()

# Get current film roll value to calculate roll.
filmRollValue = cmds.getAttr("%s.filmRollValue" % dagCam.fullPathName())
filmRollX = cmds.getAttr("%s.horizontalRollPivot" % dagCam.fullPathName())
filmRollY = cmds.getAttr("%s.verticalRollPivot" % dagCam.fullPathName())

dAspect = cmds.getAttr("defaultResolution.deviceAspectRatio")

# This is how rotation is calculated.
cz = math.cos(math.radians(filmRollValue))
sz = math.sin(math.radians(filmRollValue))

# Build the matrix.
# Row 1.
# Ensure to multiply mat[0][1] and mat[1][0] by device aspect.
matList = [0.0] * 16
matList[0] = cz
matList[1] = -sz * dAspect
matList[2] = 0.0
matList[3] = 0.0

# Row 2.
matList[4] = sz / dAspect
matList[5] = cz
matList[6] = 0.0
matList[7] = 0.0

# Row 3.
matList[8] = 0.0
matList[9] = 0.0
matList[10] = 1.0
matList[11] = 0.0

# Row 4.
# Here we're simply moving based along the rotation.
# We move it based on the offset from origin to film pivot.
# We multiply the y by the device aspect.
matList[12] = ((cz * -filmRollX) + (sz * (-filmRollY)) + filmRollX)
matList[13] = ((-sz * -filmRollX) + (cz * -filmRollY) + filmRollY) * dAspect
matList[14] = 0.0
matList[15] = 1.0

# Create MMatrix.
rollMMatrix = OpenMaya.MMatrix()
OpenMaya.MScriptUtil().createMatrixFromList(matList, rollMMatrix)

# Print values.
print("\nFilm Roll Value: %s" % filmRollValue)
print("Film Roll Pivot X: %s" % filmRollX)
print("Film Roll Pivot Y: %s" % filmRollY)

# I round because I don't want to see scientific notation.
print("\nMy Post Projection Matrix:")
for x in xrange(0, 4):
    print(round(rollMMatrix(x, 0), 5),
          round(rollMMatrix(x, 1), 5),
          round(rollMMatrix(x, 2), 5),
          round(rollMMatrix(x, 3), 5))

print("\nPost Projection Matrix from Maya:")
for x in xrange(0, 4):
    print(round(postMatrix(x, 0), 5),
          round(postMatrix(x, 1), 5),
          round(postMatrix(x, 2), 5),
          round(postMatrix(x, 3), 5))


Film Roll Value: 45.0
Film Roll Pivot X: 1.0
Film Roll Pivot Y: 1.0

My Post Projection Matrix:
(0.70711, -1.25708, 0.0, 0.0)
(0.39775, 0.70711, 0.0, 0.0)
(0.0, 0.0, 1.0, 0.0)
(-0.41421, 1.77778, 0.0, 1.0)

Post Projection Matrix from Maya:
(0.70711, -1.25708, 0.0, 0.0)
(0.39775, 0.70711, 0.0, 0.0)
(0.0, 0.0, 1.0, 0.0)
(-0.41421, 1.77778, 0.0, 1.0)