Is it possible to have ngons in a mesh that are defined by array of vertices and zero mesh faces.
I have specific situation such as extruded hexagon pattern, when I need ngons defined as vertices of hexagons.
Probably this by definition it produces invalid mesh.
But it seems that even if mesh is invalid, I can extract ngons vertices array. Which works for me.
Why do you need this? Perhaps I need a picture of what you are trying to do…
I solved it in a different way. As I wanted to planarize ngon mesh, but only polygons with 4 vertices.
I added this function to my planarize function.
The original problem was that I removed faces n valence mesh from all ngons.
The mesh looked like extruded hex extruded grid and caps at top and bottom were hexes.
After deleting them I wanted again to fill ngons with faces. But this was a bit reverse engineering and took too much time to calculate.
Maybe it is still possible to do this? I have different situation.
When I want to create ngon with no faces, just to keep track of vertices, ngon is not added to mesh.
MeshNgon ngon = MeshNgon.Create(someVertexIdList, new List () );
The situation I have is this:
To resurrect this, often Ngons are defined just with a vertex loop, and the triangulation is done on-the-fly. Libraries such as Carve only give you a vertex loop and no faces to work with.
Are there any helper functions to create an Ngon from a vertex loop WITHOUT faces? Or is the best way at the moment to create a Polyline from the vertex loop, triangulate that, then add that as an Ngon? I imagine this to be a bit inefficient, but kind of works for now… ?
void CreateNgon(Mesh m, int verts)
var pts = verts.Select(x => new Point3d(m.Vertices[x])).ToList();
Polyline pl = new Polyline(pts);
MeshFace mfs = pl.TriangulateClosedPolyline();
for (int i = 0; i < mfs.Length; ++i)
mfs[i].A = verts[mfs[i].A];
mfs[i].B = verts[mfs[i].B];
mfs[i].C = verts[mfs[i].C];
mfs[i].D = verts[mfs[i].D];
int fis = m.Faces.AddFaces(mfs);
I also know just this method in rhinocommon.
Wondering if in the code of this method any point coordinate calculation is made.
Did you look at Cpp sdk how this method is made? @Dale should know the answer if we need actual geometry or vertex id would be enough.
This is polyline class with that triangulation method .net.
Now it would be good to find code what is exactly that unsafe method and where is the source in native language.
Same stuff in cpp sdk RhinoTriangulate3dPolygon and I think it is not shared via github what is inside. Also other google quires shows examples that requires x and y coords for triangulation calculation so i think you cannot do triangulation without knowing location of vertices.
I adapted an ear clipping algorithm I found, and it seems to work quite alright. I’m sure there is lots of room for optimization, and it could probably be threaded, etc. for making a large amount of Ngons.
It needs to be changed so that you can input a Mesh and give it a list of vertex indices, but that should be pretty straight-forward.
180715_Triangulation_v1.gh (7.3 KB)
The Polyline.TriangulateClosedPolyline() function seems to use a much better, minimum cost method. The triangles are nicer
Yeah that method is awesome (Polyline strikes again!). I’ve used it quite a lot for membrane meshing a lot of the CITA stuff and for closing meshes.
Would be good to make a benchmark sometime to see if ‘new Polyline -> Polyline.TriangulateClosedPolyline()’ is a big slowdown or not, in comparison to a raw meshing implementation, such as the basic ear clipping. I haven’t run into a situation where it’s a huge bottleneck yet, but I’m sure it will happen
Until we get some more Ngon love in R6 and more optimized helper functions, this might be the easiest way to make Ngons from scratch
In any case, maybe I’ll try to whack this into Carverino, to see if we can make use of the Ngon support in Carve.
Nice references in the code for finding orignal source.
In the end it is similar method just avoiding creating Polyline data structure?
Yes, exactly. Really just an optimisation, though, I haven’t done any serious testing.
I think the requirement of Ngons to have pre-existing mesh faces to use should be looked at closer, as one of the key advantages AFAIK of Ngons is the flexibility of defining polygons without triangulating them, and only triangulating them when required, and in a way that is optimal for that particular occurrence. Otherwise we might as well just have face groups, similar to smoothing groups in other programs…
Yes, in rhinocommon ngon is just an additional property to track collection of mesh faces.
And when it comes doing something with ngons you always need to have some sort of mapping to jump between triangular mesh properties and ngons.
While in half-edge mesh data structure you do not need any triangulation.
But half-edge has its own issues too.