0

i have created a dragger context in maya using the following code, pos holds my 2D coordinates of mouse cursor, i want to convert it into 3D coordinate to be the source of the ray i want to launch,, i want it either through python scripting or through the 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--------
    ????????

thanks in advance

Ahmad Dwaik
  • 963
  • 1
  • 9
  • 13

2 Answers2

1

Actually, you might wanna look into the space(sp) flag in the draggerContext command help.

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

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

...should print you the worldspace XYZ values of the click.

Nikhil
  • 16,194
  • 20
  • 64
  • 81
Riggerman
  • 11
  • 1
0

Have you reviewed the projection (-pr) options for the draggerContext?

Mouse co-ordinates is data across 2 dimensions, and the projection options are methods to resolve how the 3rd dimension is mapped. For rays, maybe one of the following options is relevant to your question:

xAxis project to closest point on X axis yAxis project to closest point on Y axis zAxis project to closest point on Z axis

Here's hoping that helps and best of luck.

Mike Ton
  • 83
  • 1
  • 6