Hi there! Could someone help me on a python command?
I have a function to get the point on the surface of the object, but I would like to return the locator that is created on each click… how can I do that?
def hit():
vpX, vpY, _ = cmds.draggerContext(ctx, query=True, anchorPoint=True)
position = om.MPoint()
direction = om.MVector()
omui.M3dView().active3dView().viewToWorld(int(vpX), int(vpY), position, direction)
selectionList = om.MSelectionList()
selectionList.add(mesh)
dagPath = selectionList.getDagPath(0)
fnMesh = om.MFnMesh(dagPath)
intersection = fnMesh.closestIntersection(
om.MFloatPoint(position),
om.MFloatVector(direction),
om.MSpace.kWorld,
99999,
False)
hitPoint, hitRayParam, hitFace, hitTriangle, \
hitBary1, hitBary2 = intersection
x, y, z, _ = hitPoint
if (x, y, z) != (0.0, 0.0, 0.0):
# I want to return this point
point = cmds.spaceLocator()
cmds.move(x, y, z)
ctx = "Click2dTo3dCtx"
if cmds.draggerContext(ctx, exists=True):
cmds.deleteUI(ctx)
cmds.draggerContext(ctx, pressCommand=hit, name=ctx, cursor="crossHair")
cmds.setToolTo(ctx)
thanks a lot!!!