Questions about using the GetPoint.Constrain(mesh,bool)

Why is the response rate slow when I get points on the mesh compared to brep using GetPoint.Constrain ()?
Are there any ways to improve speed?

Hi @tr1004sm,

I don’t know why it is slower and I’m not sure how we can speed it up. Can you provide a model and some sample code that seems to work slow for you?

Thanks,

– Dale

Hi @dale, i can confirm this problem, not only with GetPoint.Constrain(mesh, False) but also with Rhino’s OneShot OSnaps. Please review the 2 below example scripts, it is not mesh specific but the mesh size matters. I have tested with a mesh with 750K faces:

The first script shows a timeout of 3 seconds on every scriptrun before you are able to pick the first point on the mesh. All following points can be picked without timeout while the script still runs:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    mesh_id = rs.GetObject("Mesh", 32, True, False)
    if not mesh_id: return
    
    mesh = rs.coercemesh(mesh_id, True)
    
    gp = Rhino.Input.Custom.GetPoint()
    gp.Constrain(mesh, False)
    
    while True:
        gp.Get()
        if gp.CommandResult() != Rhino.Commands.Result.Success: 
            break
        else:
            scriptcontext.doc.Objects.AddPoint(gp.Point())
    
DoSomething()

The problem with this first script is, whenever the GetPoint is disposed and the script restarted there is this timeout before you’re able to pick the first point.

Please review this second example.

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    mesh_id = rs.GetObject("Mesh", 32, True, False)
    if not mesh_id: return
    
    while True:
        rc, pt = Rhino.Input.RhinoGet.GetPointOnMesh(mesh_id, "Pick point", False)
        if rc != Rhino.Commands.Result.Success: break
        scriptcontext.doc.Objects.AddPoint(pt)
    
DoSomething()

It behaves the same on the first run, before you’re able to pick the first point, there is a timeout. All following points picked while the script is active can be picked fast. But there is a remarkable difference, if you rerun the script and pick the same mesh, there is no timeout when picking the first point.

You can reproduce the same behaviour as the first script if you eg. use a Rhino command with a OneShot snap to constrain point picking to a mesh. Eg. this macro:

! _Points _PersistentOnMesh

Causes the timeout on every run. The length of the timeout is of course system specific. I have an older system and tested it in V6. My problem is i need to use Rhino.Input.Custom.GetPoint because i have additional command options and dynamic drawing.

Q: How can i prevent that long timeout ?

thank you,
c.

@mikko - when you have time, can you look at this?

That “timeout” is mesh tree creation taking some time. Constraining input to a mesh uses line-mesh intersector, and that needs a mesh tree. The mesh is also duplicated and duplication does not copy the tree, so it needs to be created from scratch. Right now there’s only two possible solutions to avoid the tree creation when calling GetPoint. The easiest one is using SnapToMeshObject command to constrain all point input to a mesh. It duplicates the mesh and builds the tree when the command is run, and all subsequent calls to GetPoint use that mesh and the tree, avoiding duplication and building. It also has an option to set an offset.

The harder option is to write your own line-mesh intersector that has less precomputation overhead, and in your GetPoint::OnMouseMove call ON_Viewport::GetFrustumLine to get a world line from the screen point, and intersect it with the mesh using your own intersector.

1 Like

Thank you @mikko, since this is for Rhino 6 i’ve tried to use MeshRay intersection instead. It has this first “timeout” like the second script above too but on following script runs it stays fast if the mesh has not been moved. I’ll see if i can implement that to avoid GetPoint.Constrain(mesh, False).

_
c.

@mikko this is a rather “internal” explanation for this. Can you log a bug?
Maybe we can do something for a next release.