Hi,
I would like to display meshes with ngons with black edges as ngon outlines.
I have already done this in the following simple code as component (Code of component and screenshot below).
My question: I have a bunch of components that are working with ngons in meshes.
Is there any way to apply this procedure to all of them, without copying this type of code in all the components? I.E. inhereit from some main class, a preview of ngons meshes? If yes how to do this?
Once I did this my creating custom parameter for another grasshopper add-on. But this requires a bit of work to do. I am wondering if there is other way than creating a custom parameter just to solve this tiny display preference of mine.
using System;
using System.Collections.Generic;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;
using NGonsCore;
using Rhino.Geometry;
namespace SubD.NGons {
public class NGon : GH_Component {
Mesh mesh = new Mesh();
Line[] lines = new Line[0];
BoundingBox bbox = BoundingBox.Empty;
public override BoundingBox ClippingBox => bbox;
public override void DrawViewportMeshes(IGH_PreviewArgs args) {
args.Display.DrawMeshShaded(mesh, new Rhino.Display.DisplayMaterial(System.Drawing.Color.White));
}
public override void DrawViewportWires(IGH_PreviewArgs args) {
args.Display.DrawLines(lines, System.Drawing.Color.Black);
}
public NGon()
: base("NGon", "NGon", "NGon", "SubD", "NGons") {
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) {
pManager.AddMeshParameter("Mesh", "M", "Mesh", GH_ParamAccess.tree);
pManager.HideParameter(0);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) {
pManager.AddMeshParameter("Mesh", "M", "Mesh", GH_ParamAccess.tree);
pManager.HideParameter(0);
}
protected override void SolveInstance(IGH_DataAccess DA) {
mesh = new Mesh();
lines = new Line[0];
Grasshopper.Kernel.Data.GH_Structure<GH_Mesh> tree = new Grasshopper.Kernel.Data.GH_Structure<GH_Mesh>();
DA.GetDataTree(0, out tree);
foreach (GH_Mesh m in tree) {
mesh.Append(m.Value);
}
bbox = mesh.GetBoundingBox(false);
lines = mesh.GetAllNGonEdgesLines(mesh.GetAllNGonEdges(mesh.GetNGonsTopoBoundaries()));
DA.SetDataTree(0, tree);
}
protected override System.Drawing.Bitmap Icon {
get {
return Properties.Resources.preview;
}
}
public override Guid ComponentGuid {
get { return new Guid("47c23c43-efa7-4d73-ac4b-2e729e76ecb7"); }
}
}
}