i have a piece of code here in python which gives me the 2d viewpoint coords of the cursor whenever i click the mouse:
########################################
import maya.cmds as cmds
ctx = 'myCtx'
def onPress():
print cmds.draggerContext(ctx, query=True, anchorPoint=True)
if cmds.draggerContext(ctx, exists=True):
cmds.deleteUI(ctx)
cmds.draggerContext(ctx, pressCommand=onPress, name=ctx, cursor='crossHair')
cmds.setToolTo(ctx)
#########################################
What i need is to cast a ray whenever i click, coming from the viewpoint of the camera and using the 2d coordinates generated by this script to check for the intersection point on a poly mesh.
Then i just want it to return the 3d xyz coords of that intersection point
im pretty stuck with this. But im sure it can't be to extensive. I anyone can help i would be super happpyyyyyy!!!
thanks,
Sam
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/758864e0-0946-4126-939a-c1ba3bc21a48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sam
Hi Sam,
I’m confident there is a method within the Python API you could use to do this, but a poor man’s version might be to:
Best,
Marcus
ha, yep of course. Been trying to find a clear response to this problem for a while. Hopefully someone on here will know !;)
Sam
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ace6fce3-80a0-4dc0-9def-683be07483dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import maya.api.OpenMaya as omimport maya.api.OpenMayaUI as omuiimport maya.cmds as cmds
ctx = 'myCtx'def onPress(): vpX, vpY, _ = cmds.draggerContext(ctx, query=True, anchorPoint=True) pos = om.MPoint() dir = om.MVector() omui.M3dView().active3dView().viewToWorld(int(vpX), int(vpY), pos, dir) for mesh in cmds.ls(type='mesh'): selectionList = om.MSelectionList() selectionList.add(mesh) dagPath = selectionList.getDagPath(0) fnMesh = om.MFnMesh(dagPath) intersection = fnMesh.closestIntersection( om.MFloatPoint(pos), om.MFloatVector(dir), om.MSpace.kWorld, 99999, False) if intersection: print "we're hit!!" hitPoint, hitRayParam, hitFace, hitTriangle, hitBary1, hitBary2 = intersection x,y,z,_ = hitPoint cmds.spaceLocator(p=(x,y,z)) if cmds.draggerContext(ctx, exists=True): cmds.deleteUI(ctx)cmds.draggerContext(ctx, pressCommand=onPress, name=ctx, cursor='crossHair')cmds.setToolTo(ctx)