In a recent post, I found that converting polylines to meshes in Grasshopper can be problematic. Using a patch to create a mesh from a curve is slow, and directly converting from a curve to a mesh resulted in an inefficent mesh with too many faces.
It seemed that in Grasshopper, there was no easy way to create efficient meshes from closed polylines, so I set about creating my own component. It produced meshes like this:
But in cases with more complicated geometry, it didn’t always work – in the details, it would sometimes miss out triangles, or the mesh edge didn’t quite line up with the original boundary.
Revisiting the problem today, my colleague David Greenwood pointed me towards a method he’d found within the Rhino API – and we can access it in both the C# component and through visual studio. This method produces a mesh from a closed polyline – but amazingly, it returns the kind of efficient mesh we were wanting all along. And as a bonus, it’s really fast too!
The command you need is very simple:
A = Rhino.Geometry.Mesh.CreateFromClosedPolyline(pline);
We tried this method to create the roof tops of a whole city centre, with over 11000 building outlines as polylines. This is the result:
Click the image above for full size.
Zooming in on an image, we can see that, bearing in mind that mesh faces like to be in triangles, the meshes seem to be roughly as efficient as we could imagine:
And how long did these 11000 meshes take to generate? About half a second!
And if, instead of using the C# component, we write the code into a compiled component, such as when we create components with Visual Studio, the time is less than 300ms.
And if that is still too slow, we could also parallelise it, potentially bringing that time under 100ms.
So much for ripping out my hair trying to write my own algorithm or dig around for one elsewhere – I needn’t have bothered because it’s already implemented in Rhino!
With these fast built in Rhino commands – is it possible to make a C# script of the extractRenderMesh function? Then we’d be meshing breps much faster than ever!
This script saved my day! Thanks for sharing.