【发布时间】:2018-05-03 01:15:26
【问题描述】:
我正在尝试创建一个定位器网格,这些定位器用作从 Maya 中的相机在指定深度处投影到平行有限平面上的点。网格应与指定的分辨率对齐,以匹配渲染输出。
目前我的计算已关闭,我正在寻找一些帮助来确定我用于确定投影点的公式是如何不正确的。
我有一个自包含的 python 脚本和图像,显示了作为示例生成的定位器的当前位置。
image showing current spawned locators are off on y and z axis
import maya.cmds as mc
import maya.OpenMaya as om
res = [mc.getAttr('defaultResolution.width'),
mc.getAttr('defaultResolution.height')]
print res
grid = [5, 5]
def projectedGridPoint(camera, coord, depth, res):
selList = om.MSelectionList()
selList.add(camera)
dagPath = om.MDagPath()
selList.getDagPath(0,dagPath)
dagPath.extendToShape()
camMtx = dagPath.inclusiveMatrix()
fnCam = om.MFnCamera(dagPath)
mFloatMtx = fnCam.projectionMatrix()
projMtx = om.MMatrix(mFloatMtx.matrix)
#center of camera
eyePt = fnCam.eyePoint()
#offset position
z = eyePt.z - depth
#calculated xy positions
x = (2 * z * coord[0] / res[0]) - z
y = (2 * z * coord[1] / res[1]) - z
return om.MPoint(x,y,depth) * camMtx * projMtx.inverse()
for y in range(grid[1] + 1):
for x in range(grid[0] + 1):
coord = ( x / float(grid[0]) * res[0], y / float(grid[1]) * res[1] )
pt = projectedGridPoint('camera1', coord, 10, res)
mc.spaceLocator(a=1, p=[pt.x, pt.y, pt.z])
【问题讨论】:
-
那么这些点应该投影在相机截锥体中吗?即,深度为 0 是否应该位于剪辑平面上?
-
是的,网格点应该在指定深度细分/对齐渲染图像的查看区域(在本例中为 10 个单位,作为 arg 传递给 projectionGridPoint 函数)
标签: python math coordinates maya maya-api