Mesh Ray intersection failing?

We want to create an image from the height of a mesh object, but Mesh | Ray intersections seems to fail with a lot of points it shouldn’t.

The script is based on David Rutten’s original post here: Generate Image from Mesh - Grasshopper

Here is the script:

the result:

As you can see it should be an even grid of intersection points, but there are many gaps. Any ideas?

generateimage_from_height.gh (1.1 MB)

Didn’t look at your code, but I had something very similar lately. Hope someone knows
https://discourse.mcneel.com/t/bug-meshray-gives-false-result-with-closed-mesh/

1 Like

Apparently your C# writes an image to the desktop? So the path must be changed.

I can’t speak to why MeshRay fails to intersect at times and don’t have Pufferfish (but I innovated around that). I converted the mesh to a brep (took 1.3 minutes!) and tried to use IsoVist Ray instead of MeshRay but it is painfully slow. I’ll let you know if it ever finishes.

Maybe you can interpolate the missing points?

1 Like

I believe the problem lies in a limitation of the MeshRayIntersection method called by the component, as it is prone to fail in some situations (i.e. ray hitting an edge). The picture shows the mesh edges and the failed ray intersections (failed in gray, yellow are successful):

One workaround would be to scale the Mesh just enough to avoid hitting edges but still have a reliable enough mapping (“reliable enough”- and if the workaround is viable at all to start with - depends on your desired accuracy of course).

I took the liberty to replace the Pufferfish component with a chain that extracts the same data (I do not have the plugin installed). Basically you can tweak the scale factor close enough to 1 until the sum of missed hits is zero (I set it to 1.001 to have 0 missed hits).
generateimage_from_height_AE.gh (1.1 MB)

1 Like

Took 1.7 hours for IsoVist Ray to complete :bangbang: Unfortunately, I connected it to your downstream components before flattening its output so must start again. :frowning: Will report again in two hours.

Well, I must say this was a lot of trouble for a very disappointing result. 250 X 250 pixels, 62,500 points that took 1.7 hours to process (twice!). For this:

test

The second time, I forgot to set the file path for my machine but managed to internalize the points. This R8 file has my work-arounds (disabled) and the points from IsoVist Ray:

generateimage_from_height_2024_Jul22b.gh (2.0 MB)

P.S. A simple rendered view of the mesh that took no time at all:

Top View:

Here is another thing you can do with these points. Honestly, I don’t see the purpose of this?


generateSrf_from_mesh_2024_Jul22a.gh (919.1 KB)

A Top view render for a heightmap is actually a good idea! Even better if you turn on ShowZBuffer. Make a new floating viewport in Top projection and with the same proportions as the mesh (1:1 in this case), turn ShowZBuffer on, Zoom to fit and ViewCaptureToFile with the scale you want (see attached picture)

2 Likes

Thanks for taking the time to try it with IsoVist Ray. Crazy how long it takes!

That’s a great idea as well, which doesn’t rely on pixels or even Grasshopper for that matter.