Hi,
I am trying to display brep through grasshopper component, I checked there are no duplicates , but when I add transparency value I get these artifacts (either with double sided option on or off). Is it possible to avoid them using Rhino.Display.DisplayMaterial ?
The code is attached below
public class Brep2Edges : GH_Component {
BoundingBox bbox = new BoundingBox();
List<Brep> breps = new List<Brep>();
Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(System.Drawing.Color.FromArgb(200, 200, 200));
List<Curve> curves = new List<Curve>();
int weight = 2;
System.Drawing.Color color = System.Drawing.Color.FromArgb(200,200,200);
List<double> materialParameters = new List<double>() { 0.904, 0.49, 0.0 };
public override BoundingBox ClippingBox => bbox;
public override void DrawViewportWires(IGH_PreviewArgs args) {
if (!base.Hidden && !base.Locked) {
foreach (Curve c in curves)
args.Display.DrawCurve(c, System.Drawing.Color.Black, weight);
}
}
public override void DrawViewportMeshes(IGH_PreviewArgs args) {
if (!base.Hidden && !base.Locked) {
foreach (Brep b in breps)
args.Display.DrawBrepShaded(b, mat);
}
}
public Brep2Edges()
: base("Brep2Edges", "Brep2Edges",
"Gets brep edges that does not belong to the same surface",
"RhinoJoint", "Display") {
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) {
pManager.AddBrepParameter("Brep", "B", "Brep", GH_ParamAccess.tree);
pManager.AddIntegerParameter("Weight", "W", "Curve weight", GH_ParamAccess.item, 2);
pManager.AddColourParameter("Color", "C", "Color", GH_ParamAccess.item, System.Drawing.Color.FromArgb(200,200,200));
pManager.AddNumberParameter("RefShTra","P","Parameters of material as a list, reflection - shiness - transparency",GH_ParamAccess.list, new List<double>() { 0.904, 0.49, 0.0 });
pManager[1].Optional = true;
pManager[2].Optional = true;
pManager[3].Optional = true;
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) {
//pManager.AddCurveParameter("Curves", "C", "Curves", GH_ParamAccess.tree);
}
protected override void SolveInstance(IGH_DataAccess DA) {
this.bbox = new BoundingBox();
this.breps.Clear();
this.curves.Clear();
this.materialParameters.Clear();
GH_Structure<GH_Brep> GH_Breps;
DA.GetDataTree(0, out GH_Breps);
DA.GetData(1, ref this.weight);
DA.GetData(2, ref this.color);
DA.GetDataList(3, this.materialParameters);
//Get Brep properties
foreach(GH_Brep gh_brep in GH_Breps.AllData(true)) {
Brep brep = gh_brep.Value;
this.bbox.Union(brep.GetBoundingBox(true));
this.breps.Add(brep);
var crvs = RhinoGeometry.BrepUtil.Get2ValenceCurves(brep);
this.curves.AddRange(crvs);
}
//Create Material
var c = (this.color == System.Drawing.Color.Empty) ? System.Drawing.Color.FromArgb(200, 200, 200) : this.color;
double r = (this.materialParameters.Count != 3) ? 0.904 : this.materialParameters[0];
double s = (this.materialParameters.Count != 3) ? 0.49 : this.materialParameters[1];
double t = (this.materialParameters.Count != 3) ? 0.0 : this.materialParameters[2];
//base.Message = r.ToString() + " " + s.ToString() + " " + t.ToString() + this.materialParameters.Count.ToString();
base.Message = this.breps.Count.ToString();
r = Math.Min(Math.Max(r, 0), 1);
s = Math.Min(Math.Max(s, 0), 1);
Rhino.DocObjects.Material material = new Rhino.DocObjects.Material();
material.ReflectionColor = c;
material.DiffuseColor = System.Drawing.Color.White;
material.AmbientColor = System.Drawing.Color.Black;
material.EmissionColor = System.Drawing.Color.Black;
material.Reflectivity = r;
material.ReflectionGlossiness = s;
material.Transparency = t;
mat = new Rhino.Display.DisplayMaterial(material);
//mat.IsTwoSided = true;
//mat.BackDiffuse = System.Drawing.Color.Red;
}
protected override System.Drawing.Bitmap Icon {
get {
return null;
}
}
public override Guid ComponentGuid {
get { return new Guid("792744d9-278b-4916-aa11-5695336897ca"); }
}
}
Without transparency no artifacts: