Best Way to Extrude Polyline Curve

Hello!

Apologies if this has been asked/answered already, but I did try to look at similar posts and didn’t see any that matched my question.

I have a polyline curve that I’m trying to vertically extrude by a known distance into a Mesh prism (needs to be a mesh), and I was wondering how best to do that (in C# code). So far, I’ve tried a few different options:

  1. Brep.CreateFromSweep() + Mesh.CreateFromBrep()
  2. Surface.CreateExtrusion() + Mesh.CreateFromSurface()
  3. Extrusion.Create() + GetMesh() (called on the created instance)

I only toyed around with the third one a little bit, but it returned a null mesh (even for a non-null extrusion). Moreover, I would ideally like the implementation to allow for non-planar curves, and Extrusion.Create() requires a planar curve, so I’ve pretty much ruled it out. I wanted to document my attempt at using it, though, in case it ended up being the recommended approach.

The first two approaches get close, but aren’t quite white I need. The Surfaces/Breps that are created are accurate, but the Mesh.CreateFromX() functions don’t accurately recreate the top and bottom faces. The base polyline is repeatedly sampled instead of being directly used to construct the bottom/top faces of the mesh, and this results an approximate mesh that doesn’t capture the proper geometry (see figure below).

I could always set the Meshing Parameters to be more fine-grained, but it seems like an unnecessary waste of computation for an undesirably complex mesh. Extruding a polygon into a mesh prism seems like such a fundamental thing, so I feel like I have to be missing something here. Any and all advice is appreciated!

Note: Technically I’m working on a Grasshopper Plugin, but given that the relevant code is all Rhino functions, I felt the Rhino Developer tag was more appropriate as the primary tag.

If you want to work with mesh, no need to use Brep. A polyline curve with N points will become a mesh with 2 * N points, if polyline closed, it will be 2 *( N-1) after CombineIdentical(true, true); You can also Unweld mesh if you want faces looking flat.

  public static Mesh ExtrudePolylineOneSide(Polyline polyline, Vector3d normal, double extrusionHeight)
        {
            Mesh meshExtruded = new Mesh();

            normal.Unitize();
            foreach (Point3d pt in polyline)
            {
                meshExtruded.Vertices.Add(pt);
                meshExtruded.Vertices.Add(pt + normal * extrusionHeight);
            }

            for (int i = 0; i < (polyline.Count - 1); i++)
            {
                meshExtruded.Faces.AddFace(i * 2, i * 2 + 1, (i + 1) * 2 + 1, (i + 1) * 2);
            }

            meshExtruded.Vertices.CullUnused();
            meshExtruded.Vertices.CombineIdentical(true, true);
            meshExtruded.RebuildNormals();

            return meshExtruded;
        }
2 Likes

I thought about creating the Mesh myself from the vertices and faces, but I figured there had to be some one line function in the API that did what I was asking. That being said, the custom method you provided is much simpler than I thought it would be, so I’ll probably go with that approach for now. Thanks a bundle!

That but could be something like Mesh.createMesh …

https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.mesh/createfromcurveextrusion

I think I tried that one first actually (forgot to include it above), but it also takes a MeshingParameters object, meaning it’s still going to do the sampling that was messing things up in the other approaches.

I tried once and also has problem with the BoundingBox … It was not so easy.

OHH right! Now that you mention it, I remember having this very problem, looking it up on the forums, and seeing this post (see hyperlink) where they recommended the Surface based approach:

(Mesh Extrusion Bug? - #21 by dale)