首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何(在maya中)获取鼠标的3D位置?

如何(在maya中)获取鼠标的3D位置?
EN

Stack Overflow用户
提问于 2009-12-10 23:07:33
回答 2查看 3.3K关注 0票数 0

我已经使用以下代码在maya中创建了一个拖拽上下文,pos保存我的鼠标光标的2D坐标,我想将其转换为3D坐标,以成为我想要启动的光线的源,我想通过python脚本或通过python api,

代码语言:javascript
复制
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--------
    ????????

提前感谢

EN

回答 2

Stack Overflow用户

发布于 2011-11-24 01:43:52

实际上,您可能需要查看draggerContext命令帮助中的空间(Sp)标志。

代码语言:javascript
复制
mc.draggerContext('sampleContext', dragCommand='getCursorPos()', space='world')

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

...should会打印单击的worldspace XYZ值。

票数 1
EN

Stack Overflow用户

发布于 2010-03-04 16:47:50

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

鼠标坐标是跨2个维度的数据,而投影选项是解决如何映射第三个维度的方法。对于光线,可能以下选项之一与您的问题相关:

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

希望这对你有所帮助,并祝你好运。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1881592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档