Can get Point-Index under the mouse pointer? (Py)
-
Can get Point-Index under the mouse pointer? (Py)
I found a useful post.
But I'm a beginner so I'm asking for help. Thank you. -
Hello @ymoon,
Thank you for reaching out to us. I am a bit confused regarding what you are asking for here. The method
ViewportSelect.GetNearestPoint
you have linked to is indeed the recommended way to retrieve the closest vertex to a mouse cursor. Its return value also contains the index of the closest element under the key i.Alternatively, you could also convert the points of a point object first to world and then to screen space using BaseView.WS. You could then manually poll the mouse using c4d.gui.GetInputEvent or use mouse coordinates provided by another method to determine which is the closest point. But since this is extra labor and the kind of computation one wants to avoid doing in Python for performance reasons, you should only do that if you must customize the closest point computation for some reason.
Cheers,
Ferdinand -
The mouse position is obtained as follows.
msg[c4d.BFM_INPUT_X] --> GetEditorWindow() --> editor_x = win.Global2Local() --> mouse_x-abs(Editor_x)
The problem of overlapping selection in GetNearestPoint() was solved by making a list of selected object.
Thank you.