Joining Mesh in c#(Mesh.Append method)

Hello,

I am doing a mesh window component, when I use a mesh as Input it joines well, but with polylines as input it gives me single faces instead of a joined mesh.

  protected override void SolveInstance(IGH_DataAccess DA)
        {
            
            //Get geo an initialize 
                     GeometryBase geometryBase =null;   
                     if ((!DA.GetData(0,ref geometryBase)))
                        return;

                  object someGeometry = geometryBase;                        
                  double factor = double.NaN;
                  DA.GetData(1, ref factor);
                  Mesh outMsh = new Mesh();
                  var curves = new List<Polyline>();



            //get Plines from mesh if mesh is the input
                  if (someGeometry is Mesh)
                  {                    
                      Mesh msh = someGeometry as Mesh;                                           

                        for (int f = 0; f < msh.Faces.Count; f++)
                        {
                          if(msh.Faces[f].IsTriangle)
                          {
                            var pts = new List<Point3d>(3);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);
                            pts.Add(msh.Vertices[msh.Faces[f].B]);
                            pts.Add(msh.Vertices[msh.Faces[f].C]);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);

                            Polyline polyline = new Polyline(pts);
                            curves.Add(polyline);

                          }

                          if(msh.Faces[f].IsQuad)
                          {
                            var pts = new List<Point3d>(3);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);
                            pts.Add(msh.Vertices[msh.Faces[f].B]);
                            pts.Add(msh.Vertices[msh.Faces[f].C]);
                            pts.Add(msh.Vertices[msh.Faces[f].D]);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);

                            Polyline polyline = new Polyline(pts);
                            curves.Add(polyline);
                          }
                        }                      
                     }

                      

                //put Polylines in list

                  else if (someGeometry is Curve)
                  {
                      Polyline polyline;
                      Curve curve = (Curve)someGeometry;
                      if (!curve.TryGetPolyline(out polyline))
                          throw new ArgumentException("Only polylines and meshes are allowed as inputs");
                      curves.Add(polyline);
                      
                  }


            
            //Make mesh window
                  for (int i = 0; i < curves.Count; i++)
                  {                                            
                      var ptsO = curves[i];
                      Polyline polylineCopy = new Polyline(curves[i]);
                      Point3d center = curves[i].CenterPoint();
                      Transform xform = Transform.Scale(center, factor);
                      polylineCopy.Transform(xform);

                      var ptsS = polylineCopy;
                      
                      Mesh m = new Mesh();
                      for (int j = 0; j < ptsO.Count - 1; j++)
                      {                          
                          var pts = new List<Point3d>();
                          pts.Add(ptsO[j]);
                          pts.Add(ptsO[j + 1]);
                          pts.Add(ptsS[j + 1]);
                          pts.Add(ptsS[j]);
                          m.Vertices.AddVertices(pts);
                          m.Faces.AddFace(new MeshFace(j * 4, j * 4 + 1, j * 4 + 2, j * 4 + 3));                                          
                       }
                      
                      outMsh.Append(m);
                     
                  }

            //assign joined mesh
            
                      Message = "Mesh";
                      outMsh.Vertices.CombineIdentical(true, true);
                      outMsh.Vertices.CullUnused();
                      outMsh.UnifyNormals();
                      outMsh.FaceNormals.ComputeFaceNormals();
                      outMsh.Normals.ComputeNormals();

                      DA.SetData(0, outMsh);
        }

I have a list of Polylines, once it is generated from the vertices of a mesh and once I import it from Curves, so the error just can come from the las part of the code I think:

wut

Thanks for anybody looking at it!

See attached

Mesh_from_FacetPolylines_V1.gh (227.8 KB)

Added some stuff more (in the name of science, what else?)

Mesh_from_FacetPolylines_V1A.gh (227.4 KB)

Hi Peter!
thanks for the examples, I cant use the Mesh.CreateFromClosedPolyline Method cause it creates triangulated meshes in case of 4edges:


My intention is doing a mesh scale component which can output single faces or a mesh, which works if I feed a mesh in, but fails with polylines as input.

My dear Watson … that’s the easiest of things to implement: just a simple question more (if poly.Count == 5 > do a quad mesh).

I’ll add that in the trad V1B update

Hi,
it already works for 4+ edges

, its just not joining together.

V1B would do anything (still WIP with regard some minor things [ closed mesh orientation and the likes]).

Good morning Sherlock,

I think you forgot the file :wink:
By the way, a maybe a hint why the mesh out of pLines dont joines?
If I join it afterwards it works:


I do the same in VS and dont get a joined one without success:vslop

Er … hmm … indeed, But the ugly news are that I’m far and away from home right now.

Moral: Porca Miseria.

Check out Mesh+ It has this as well as 23 other aparature component types for meshes or polyines in the subdivision panel. Also, @DavidMans was nice enough to leave all the components open so you can look at the code (is in VB tho).

Well … hope dies last. I have a stupid Laptop with me (we are in some sort of w/e break in the mountains BUT there’s F1 (Valencia) and WSB (Assen) races this w/e) and guess what?

Found that def:

Mesh_WindowsFromPolylines_V1.gh (127.9 KB)

BTW: Use the facet demo and observe that the offset inwards is far more challenging than it appears on first sight (I have some C#'s that do that properly on any polyline imaginable) … but anyway.


:

HI,
thanks Michael,
they are indeed really nice, I opened them once, its a lot of code, but definetly helps to understand the manner and its a nice ressource.

Thanks Peter,

looks nice and as always freaky :slight_smile: will look closer at the weekend!

Enjoy the mountains!