using System; using System.Collections.Generic; using System.Text; using Grasshopper.Kernel; using Rhino.Geometry; namespace Reinforcement_Toolbox { public class MeshTopologyComponent : GH_Component { //Add constructor public MeshTopologyComponent() //Call the base constructor : base("MeshTopology", "MeshTop","Creates the mesh topology of a triangle mesh.","Reinforcement Toolbox","Geometry") { } protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { pManager.Register_BRepParam("Triangles", "Tr", "Collection of triangular Breps.",GH_ParamAccess.list); //pManager.Register_IntegerParam("Vertice Index", "VI", "Index of vertice."); //Optional input pManager[0].Optional = true; //pManager[1].Optional = true; } protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { //output parameter 0 pManager.Register_PointParam("Centroids", "C", "Centroids of the faces."); //output parameter 1 IGH_Param meshTopology = new Param_MeshTopology(); pManager.RegisterParam(meshTopology, "MeshTopology", "MP", "Holds the topological information of a mesh."); } protected override void SolveInstance(IGH_DataAccess DA) { //create a list with Breps List brepList = new List(); //create a MeshTopology RTMeshTopology meshTopology = new RTMeshTopology(); //fill the list with the assigned Breps if (!DA.GetDataList(0, brepList)) { return; } //if (!DA.GetData(1, ref index)) { return; } //create a Face for each Brep in the list and add the Face to the MeshTopology foreach (Brep brep in brepList) { Face face = new Face(brep); meshTopology.AddFace(face); } //unify the orientation of all Faces contained in the MeshTopology meshTopology.UnifyOrientation(); //create the Face normals meshTopology.SetFaceNormals(); //create the Vertice vectors meshTopology.SetVerticeVectors(); //DEBUG //create a list with offset vertices List verticePointList = new List(); foreach (Vertice vertice in meshTopology.Vertices) { Point3d verticePoint = new Point3d((vertice.X + (10 * vertice.VerticeVector.X)), (vertice.Y + (10 * vertice.VerticeVector.Y)), (vertice.Z + (10 * vertice.VerticeVector.Z))); verticePointList.Add(verticePoint); } DA.SetDataList(0, verticePointList); //DEBUG //REVISE: set the output to the MeshTopology //int verticeCount = meshTopology.Vertices.Count; } public override Guid ComponentGuid { get { return new Guid("{CF25B715-C72B-4010-8441-4882AA805E1E}"); } } } }