MeshMeshIntersection rhinoscript problem

Thanks, I am (trying to) make a mesh stamp tool, so I need to split meshes, but I run into a lot of trouble trying to work around these issues.
I see that if I run the command MeshIntersect in Rhino I get good curves, but if I run rs.meshmeshintersection() then I get bits of the curves, so maybe this is where the issue lies.

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

def splitMesh(obj_idA,obj_idB):
    objA = rs.coercemesh(obj_idA)
    objB = rs.coercemesh(obj_idB)
    crvs = rs.MeshMeshIntersection(objA,objB)
    for crv in crvs:
        rs.AddCurve(crv)

def runScript():
    obj_idA = rs.GetObject("Select Terrain")
    if not obj_idA: return
    obj_idB = rs.GetObject("B")
    if not obj_idB: return
    splitMesh(obj_idA,obj_idB)
    rs.HideObject(obj_idA)
    rs.HideObject(obj_idB)

runScript()

AND I also get different results depending on the order I pick the two meshes…
Strange isn’t it?

Edit: I also tried Intersection.MeshMesh Method
but that became too difficult for me to understand, it was too many strange parameters :slight_smile:

Putting the file here since the tread was split:
MeshSplit bug.3dm (810.7 KB)

I have a feeling that I know why this happens. I’ll investigate this one, but I think they are unrelated (hence, the split of the two topic, sorry about that one).

It’s not sooo bad! I’ll post a sample tomorrow if you’d like.

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

1 Like

Thanks, a sample would be great! But do you think making the intersections and splitting with those are a better route? Or should pure mesh mesh splitting do the job better?

IMHO if Holo needs a sample and better directions then we all do.

2 Likes

:laughing: the problem with me is that my skills at coding are not as high as my persistence… (And I wished my memory was a few notches better too… so I didn’t have to relearn what I once figured out :wink: )

@AIW @Holo You guys are champs. I’m 100% culpable of exposing a very powerful and yet very elaborate tool.

In fact it’s the same function that the MeshIntersect commands in V7 uses (+ V8 will use). So it supports showing and updating the progress bar, hitting the ESC key and cleanly stopping, piping the text info to the toolbar or a Grasshopper balloon, and other amenities. I’m sorry it’s a little rough around the edges for simpler use cases. I didn’t want to dumb it down, and not everyone was happy about adding default parameters.

Certainly, if you don’t want to use the MeshMesh class because you don’t need those other items, you can use the Rhino.Geometry.Intersect.Intersection.MeshMeshAccurate(mesh1, mesh2, tolerance) function. I’m showing both ways here below:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import System

def splitMesh(obj_idA,obj_idB,tolerance=None):
    objA = rs.coercemesh(obj_idA, True)
    objB = rs.coercemesh(obj_idB, True)
    if tolerance is None:
        tolerance = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance * \
            Rhino.Geometry.Intersect.Intersection.MeshIntersectionsTolerancesCoefficient
    #pls = Rhino.Geometry.Intersect.Intersection.MeshMeshAccurate(objA, objB, tolerance)
    ok,perf,overl,_ = Rhino.Geometry.Intersect.Intersection.MeshMesh(
        [objA,objB],tolerance,True,False,None,System.Threading.CancellationToken.None,None)
    for pl in ((list(perf) if perf else [])+(list(overl) if overl else [])):
        sc.doc.Objects.AddCurve(pl.ToPolylineCurve())

def runScript():
    obj_idA = rs.GetObject("Select Terrain")
    if not obj_idA: return
    obj_idB = rs.GetObject("B")
    if not obj_idB: return
    splitMesh(obj_idA,obj_idB)
    rs.HideObject(obj_idA)
    rs.HideObject(obj_idB)

runScript()

Thanks! But I don’t get good results though…
If I try with the file I included above and use MeshMeshAccurate I get this:

And if I use Try Except on adding polylines from the perf only list (have to use Try since some polylines are too short to add) I get 16 visible curves (here moved in Z to show curves, if you count them you’ll only see some as the others are too short to see)

Can you please try on the file and see what’s happening?

Also obviously there are stuff I don’t understand like why Rhino.Geometry.Intersect.Intersection.MeshMesh() returns two sets of polylines, and also why it returns a mesh. Can you elaborate on that please?

Here’s the link again so you don’t have to scroll :wink:
MeshSplit bug.3dm (810.7 KB)

I’m on Rhino 7 SR16 and get this from both:

There is a bug, though, in some duplications. I think that’s the origin of the split problem. I’ll debug it with the split problem above but hopefully, it might be easier to fix knowing this.

You can get better results by moving to this call:
sc.doc.Objects.AddCurve(pl.ToPolylineCurve())
The one I was using really expects points.

I updated the script above.

You found the documentation page and the answer to these question is in the Parameters heading. IronPython (and Python for .Net) returns out parameters as parts of tuples.

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

RH-67504 is fixed in Rhino 7 Service Release 17 Release Candidate

1 Like