I’m writing a c# plugin for rhino 8.
I get the wrong shading of the preview (the box on the left). I expext to get a preview like vanilla components (box on the right).
What am I missing?
Thanks
My code
I’m overwriting the preview with this code.
In Component.cs:
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
base.DrawViewportMeshes(args);
DisplayMaterial material = Attributes.Selected ? args.ShadeMaterial_Selected : args.ShadeMaterial;
System.Drawing.Color color = Attributes.Selected ? args.WireColour_Selected : args.WireColour;
int thickness = Attributes.Selected ? 2 : args.DefaultCurveThickness;
Preview.drawViewportBreps(args, material, color, thickness, previewBreps);
}
In Preview.cs there is a Preview class with drawViewportBreps method:
public static void drawViewportBreps(IGH_PreviewArgs args, DisplayMaterial material, Color color, int thickness, List<Brep> breps = null)
{
// Ensure the list is not null AND contains items
if (breps != null && breps.Count > 0)
{
foreach (Brep brep in breps)
{
if (brep == null || !brep.IsValid) continue;
MeshingParameters meshingParameters = new MeshingParameters();
Rhino.Geometry.Mesh[] meshes = Rhino.Geometry.Mesh.CreateFromBrep(brep, meshingParameters);
foreach (Rhino.Geometry.Mesh mesh in meshes)
{
args.Display.DrawMeshShaded(mesh, material);
}
Curve[] wires = brep.GetWireframe(0);
if (wires != null)
{
foreach (Curve wire in wires)
{
args.Display.DrawCurve(wire, color, thickness);
}
}
}
}



