【问题标题】:how (in maya) can i get the 3D position of the mouse?我如何(在 Maya 中)获得鼠标的 3D 位置?
【发布时间】:2010-12-25 07:02:07
【问题描述】:

我使用以下代码在 Maya 中创建了一个拖动上下文,pos 保存我的鼠标光标的 2D 坐标,我想将其转换为 3D 坐标作为我想要发射的射线的源,我想要它要么通过python脚本或通过python api,,,

import maya.cmds as mc

mc.draggerContext( 'testContext', pressCommand='getCursorPos()',
                    dragCommand='getCursorPos()', cursor='default')

def getCursorPos():

    #--get the 2D position of cursor (on the view port)----

    pos = mc.draggerContext( 'testContext', query=1, dragPoint=1) 

    #----convert to 3D coordinates in the scene--------
    ????????

提前致谢

【问题讨论】:

  • # 错误:RuntimeError:文件 第 4 行:#

标签: python scripting 3d maya autodesk


【解决方案1】:

实际上,您可能想查看 draggerContext 命令帮助中的 space(sp) 标志。

mc.draggerContext('sampleContext', dragCommand='getCursorPos()', space='world')

def getCursorPos():
    print mc.draggerContext( 'testContext', query=1, dragPoint=1) 

...应该为您打印点击的世界空间 XYZ 值。

【讨论】:

    【解决方案2】:

    您是否查看过 draggerContext 的投影 (-pr) 选项?

    鼠标坐标是二维数据,投影选项是解决如何映射第三维的方法。对于光线,也许以下选项之一与您的问题相关:

    xAxis 投影到 X 轴上最近的点 yAxis 投影到 Y 轴上的最近点 zAxis 投影到 Z 轴上的最近点

    希望对您有所帮助,祝您好运。

    【讨论】:

      猜你喜欢
      • 2015-10-22
      • 2019-02-25
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多