algorithmic modeling for Rhino
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>
}
Tags:
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
Hi David,
I see, I'm kind of a beginner in C#, can you write an example of how to modify the Transparency property of the DisplayMaterial?
// Benjamin
Hi Benjamin,
There should be another constructor available that allows to use a double for the transparency. You should be able to use it like so (this being a very long line):
args.Display.DrawBrepShaded(brep, new Rhino.Display.DisplayMaterial(System.Drawing.Color.FromArgb(red, green, blue), doublePrecisionAlpha));
Transparency goes from 0.0-1.0: github.com...
This is the way you can set it via the property:
Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(System.Drawing.Color.FromArgb(red, green, blue), doublePrecisionAlpha);
material.Transparency = 0.5;
args.Display.DrawBrepShaded(brep, material);
You can get this type of information in a C# book.
I hope this helps,
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Another question on the same topic:
In the same component I have a list of Point3d as output. These points will by default be previewed as red crosses, is there any way to overwrite the preview of them and make them invisible?
You can switch the preview off for an output parameter. This is easiest inside the RegisterOutputParams() function. You can call pManager.HideParameter(1) for example.
You can enable/disable the preview of any input/output parameter at any time, but you'll have to cast the IGH_Param to IGH_PreviewObject before you get access to the Hidden property.
--
David Rutten
david@mcneel.com
München, Germany
Can't get it to work, can anyone take a look?
public override void RegisterOutputParams(IGH_PreviewObject pManager)
{
pManager.HideParameter(1);
}
That method doesn't register any output parameters... Can you please post your entire method?
--
David Rutten
david@mcneel.com
Seattle, WA
TopColumn1 = TP1; // List<Point3d>
TopColumn2 = TP2; // List<Point3d>
SecondaryBeam = TPS; // List<Point3d>
brep = nb;
alpha = a;
red = r;
green = g;
blue = b;
}
// <Custom additional code>
Brep brep;
double alpha;
int red;
int green;
int blue;
public override void RegisterOutputParams(IGH_PreviewObject pManager)
{
pManager.HideParameter(1);
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
args.Display.DrawBrepShaded(brep, new Rhino.Display.DisplayMaterial(System.Drawing.Color.FromArgb(red, green, blue), alpha));
}
// </Custom additional code>
}
It's still empty:
public override void RegisterOutputParams(IGH_PreviewObject pManager)
{
pManager.HideParameter(1);
}
If you're not adding any outputs, then you also cannot hide any outputs.
--
David Rutten
david@mcneel.com
Seattle, WA
I still can't figure out how to write the code. Could you maybe write an example? I'm sorry but I'm not very experienced in writing in C#.
public override void RegisterOutputParams(IGH_PreviewObject pManager)
{pManager.AddBrepParameter("Brep", "B", "Shape");
pManager.AddPointParameter("Pt", "P", "Point");
pManager.HideParameter(1);
}
(For the sake of brevity I didn't include the access argument)
The HideParameter(index) method will switch the preview off for the parameter at the given index. In this case the point parameter.
--
David Rutten
david@mcneel.com
Seattle, WA
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by