Alexey Vanzhula Posted June 17, 2014 Share Posted June 17, 2014 I can find primitive under the mouse with MouseCHOP. Now i wat to find closest point at this primitive. The problem is that nearpoint expression function return near point to viewport plane. As the result I can find valid point number in flat grid and via one of ortho views. How to properly find closest point ? I have to consider direction (in my code) returned by mapToWorld. But How ? import hou, toolutils cur_viewport = toolutils.sceneViewer().curViewport() # CURRENT VIEWPORT mx, my = hou.evalParmTuple("/obj/geo1/dm1/core/mouse") # THIS IS PATH TO MOUSE-CHOP vx, vy = v.mapFromMouseChop(mx,my) # GET VIEWPORT COORDINATES direction, position =v.mapToWorld(vx,vy) # CONVERT VIEWPORT TO WORLD COORDINATES node = cur_viewport.queryNodeAtPixel(vx, vy) # NODE AT WORLD COORDINATES if node is not None: prim = v.queryPrimAtPixel( node, vx, vy ) # PRIM AT WORLD COORDINATES hou.hscriptExpression( 'nearpoint("{}",{},{},{})'.format(node.path(), position[0], position[1], position[2]) ) # POINT NUMBER Quote Link to comment Share on other sites More sharing options...
Storm Keeper Posted June 17, 2014 Share Posted June 17, 2014 (edited) Alexey, my solution is to use origin and ray vectors and then iterate over the primitive's vertices to find minimal distance to the ray. Here is my code: def getN(point, orig, dir): pos = point.position() OP = pos - orig proj = OP.dot(dir) n = OP - proj * dir return n def nearestPrimPoint(prim, orig, dir): minD = float('inf') nearestPoint = prim.vertices()[0].point() for v in prim.vertices(): P = v.point() N = getN(P, orig, dir) D = N.length() if D < minD: minD = D nearestPoint = P return nearestPoint So you can pass the direction and position vectors to this function. Edited June 17, 2014 by Dmitry Shurov Quote Link to comment Share on other sites More sharing options...
Alexey Vanzhula Posted June 17, 2014 Author Share Posted June 17, 2014 Thanx, i`ll try it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.