I'm having trouble with setting the color of a Brep in my C# component. The command FromArgb() takes four arguments which represents alpha, red, green, and blue. As I understand the first argument alpha, which can vary between 1 and 255, corresponds to the opacity of the previewed Brep (255 being solid and 1 being transparant). With my code below I manage to change the color but not the opacity. Changing int a below doesn't give any effect. The previewed Brep is always displayed as solid (255) no matter of the value of int a. Changing int r, g and b however gives effect on the previewed color. It is like the first argument doesn't have any effect.
Any Ideas??
int a = 180; // Opacity??
int r = 10; // red
int g = 10; // green
int b = 10; // blue
brep = nb;
alpha = a;
red = r;
green = g;
blue = b;
}
// <Custom additional code>
Brep brep;
int alpha;
int red;
int green;
int blue;
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
args.Display.DrawBrepShaded(brep, new Rhino.Display.DisplayMaterial(System.Drawing.Color.FromArgb(alpha, red, green, blue)));
}
// </Custom additional code>
}
David Rutten
Hi Benjamin,
alpha values can vary between 0 and 255, where 0 is indeed fully transparent.
A Rhino Display material however doesn't support colours with transparency. The .NET color type (which does support an alpha channel) is converted into a Rhino colour type and the alpha information is discarded. Instead, you have to modify the Transparency property of the DisplayMaterial. This property is completely separate from the Diffuse colour.
--
David Rutten
david@mcneel.com
Tirol, Austria
Oct 10, 2013