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:
Thanks for anybody looking at it!