Construct mesh (faces and vertices )


(Amir Habibi) #1

Hi all , Since I found no method same as ( Grasshopper: Construct mesh ) in Rhinocommon , What is the proper way to make mesh from faces and vertices ?


(Dale Fugier) #2

Hi @Amir_Habibi,

Something like this should do:

var mesh = new Mesh();
// Add vertices
mesh.Vertices.Add(new Point3d(0.5, 0.5, 0.5));
mesh.Vertices.Add(new Point3d(0.5, 0.5, -0.5));
mesh.Vertices.Add(new Point3d(0.5, -0.5, 0.5));
mesh.Vertices.Add(new Point3d(0.5, -0.5, -0.5));
mesh.Vertices.Add(new Point3d(-0.5, 0.5, 0.5));
mesh.Vertices.Add(new Point3d(-0.5, 0.5, -0.5));
mesh.Vertices.Add(new Point3d(-0.5, -0.5, 0.5));
mesh.Vertices.Add(new Point3d(-0.5, -0.5, -0.5));
// Add faces
mesh.Faces.AddFace(0, 1, 5, 4);
mesh.Faces.AddFace(0, 4, 6, 2);
mesh.Faces.AddFace(0, 2, 3, 1);
mesh.Faces.AddFace(7, 3, 2, 6);
mesh.Faces.AddFace(7, 6, 4, 5);
mesh.Faces.AddFace(7, 5, 1, 3);
// Compute normals
mesh.FaceNormals.ComputeFaceNormals();
mesh.Normals.ComputeNormals();
// Cleanup
mesh.Compact();

// TODO...

– Dale


(AdrianG) #3

Nice Dale! Having some fun with your script :sunny:

test2

The File : proceduralMesh.gh (15.9 KB)