How to Input Surface to C# component

I can’t figure out how to input an existing surface into a custom C# compiled component.

I try making a new Surface(), but the constructor is protected for internal use.

I can get the surface input as a GH_Surface, but I can’t figure out how to use GH_Convert.ToSurface because I can’t ref a new Surface for the same above reason.

I am trying to get the edges from a surface and evaluate the surface at some uv points. This doesn’t seem like it should be difficult, but I can’t get my geometry into the Surface object.

        protected override void RegisterInputParams(
            GH_InputParamManager pManager)
            pManager.AddSurfaceParameter("Surface", "S", "Surface", GH_ParamAccess.item);

        protected override void SolveInstance(IGH_DataAccess DA)
            var ghSurface = new GH_Surface();

            DA.GetData(0, ref ghSurface);

I found a way to get a brep out of the GH_Surface, so I can now get edges and evaluate the faces of the brep to get uv points.

var edges = ghSurface.Face.Brep.DuplicateNakedEdgeCurves(true, false);

I’m not sure if this is the best way, but it is a way to move forward.

Is it? (139.5 KB)

Thank you for the example. It looks like I needed to declare a Brep instead of a Surface and handle the single surface from within the Brep object. This helps a lot!

The Iso-Curve extraction works great too. I am now struggling to figure out how to make offset curves on the surface. I am going to play around with your example. Thank you for the help!

Not quite: a Brep is (in general) a collection of BrepFaces (exactly like a Mesh that is a collection of MeshFaces). So in fact you need to play ball with a BrepFace (and/or the underlying Surface that serves as some sort of “template” [+ Trims] - so to speak).

That said a triangle (like the demo one used in the C#) can be (a) a “portion” of a Surface OR (b) a Surface with a singularity (there’s RC Methods to inform you about that).

BTW: For the Curve Offset part (Slower than any Harley Davidson - for a reason) use these RC Methods (shown: using a Point2d)

Anyway see this (either faulty or useless : good luck): (136.4 KB)

Thank you for breaking down BrepFace vs Surface. This is pretty interesting and something I will keep in mind as I develop these kinds of tools.

OffsetOnSurface is CRAZY slow and it doesn’t seem to work very often. I am trying to think through how to do this in more of a discrete instead of continuous way. I also hadn’t seen the Surface.ShortPath, so I will add that to my toolbox.

I am trying to make a series of paths on a surface that each have the same offset from the previous. My approach now is to take the initial path, divide into points, get vectors between points in the path, use some cross-products to get each point’s offset vector, move the point along offset vector, get closest point on surface, measure the actual offset distance and move again until it is within my process tolerance. This makes some nice offset path on certain types of surfaces, but the paths wrinkle when my surface has varying curvature (convex and concave). I am working on a way to remove the wrinkles and distribute points better on the new offset before making the next offset.

This seems like something that probably has been done before… and I don’t want to reinvent the wheel (or something far less useful). The parts that seem silly right now is how I am getting the offset point on the surface at the correct distance. Seems like there would be a direct way to compute where the point should be. I can think of a geometric way to do with with a circle in the plane of the offset vector and surface normal, but intersecting curves and surfaces seems slow and buggy as well.

Here are some offset paths on radially symmetrical surface which works pretty well.

Here is the output when the surface has convex and concave curvature.
I am working on ideas of how to resolve these areas.

If you attempt to cut the mustard the “analytic” way (points, vectors, cross/dot products, ccx events, cats and dogs) you’ll find yourself into a big rabbit hole … unless you use various filters [curvature related] upon what points are the right ones [+ other things] for defining the next offset [Note: Curve self Ccx events are not the only way to walk the walk]. The problem is “like/kinda” attempting to offset a planar PolyCurve - where self Ccx events are paramount … blah, blah.

1303.3578.pdf (1.3 MB)
Xu-ZhengLiu2007a.pdf (1002.6 KB)

What is the purpose of these Curves? Why is important the “same” offset? (this means possibly weird/ugly offsets depending on the Topology]. Why a Ccx Method (Brep/Plane) is out of question? Are you in the AEC market sector or you do just Objects or you are an Artist ?

1 to 10 what is your C# experience?

Screen Shot 069

Oh, I have been down these rabbit holes before, but for different reasons.

I used to generate Structured Grids and other types of volumetric meshes.
I am interested in adding some of these tools to my gh toolkit.
I am still playing with different ideas of how these grids should be generated and what their topology should look like. is a great place to find inspiration.
There are many ways to make different kinds of grids, but I haven’t found one that has my specific criteria - Conform to the geometry while offsetting same the same distance from the previous layer at each point. These two goals contradict each other if you are trying to capture all of the geometry without breaking the offset rule when working with arbitrary shapes. I play many games to get what I need.

Right now, I am focusing on manifold quad-meshes that can be marched in or out to make structured volumetric grids.
I am playing with the idea of breaking the structured topology and collapsing quads into triangles if needed.
This opens up all kinds of problems and possibilities.

The type of grid I am interested in producing right now has some baseline requirements for the type of simulation I need to produce.
The main requirements are that the points conform to some input geometry (surface, brep, mesh…) within some tolerance and that each layer of points maintains an offset distance from the previous layer.
You could think of these layers like paths for a milling tool that is removing the same amount of material on each pass. This is mostly for simulation, but some might call it art.

1 to 10… I would say 6. I played long enough to know that I don’t know much, but I am more than willing to keep trying.

I do genuinely agree that mustard cannot be cut, but sometimes you get lucky.
I know the types of offset paths I want to produce are not compatible with arbitrary geometry, but it does work well for things I am interested in producing.

It’s not luck: it’s just a matter of cutting some other thing (if the mustard is a tough call).

Suggestion1: FIRST fully master the art of offseting a PolyCurve THEN cut … er … hmm … something.

Suggestion2: The difference between an amateur and a pro is that the formar knows when NOT to attempt/do something (time flies, life’s short, why bother? blah, blah). Imagine someone asking from a top pro to solve a Hamiltonian Path on a Graph with 666 nodes in 0.666 milliseconds (using an ordinary I9). That’s simply a hallucination. So don’t waste toooooo much time IF signs are bad/odd/weird/freaky/ominous: just provide some “scientific” fake/real excuse … and walk some other walk.

GH’s surface can be a brep.