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:
This is what I tried, but keep getting:
"{0;0} 0. Error (CS0115): 'Script_Instance.RegisterOutputParams(Grasshopper.Kernel.IGH_PreviewObject)': no suitable method found to override (line 153)"
ah! I thought you were writing a component in Visual Studio! My bad.
In the case of a C# script component you have to use something like this:
IGH_PreviewObject prv = Component.Params.Output[1] as IGH_PreviewObject;
prv.Hidden = true;
You can put that in the RunScript method.
--
David Rutten
david@mcneel.com
Seattle, WA
As I understand, setting the preview color in a C# component overrides color properties for the component when it's selected. Is it a possibility to prescribe a different color for selected C# component?
You can draw your own geometry in whatever colour you want, but you cannot override the colour of geometry someone else is drawing.
--
David Rutten
david@mcneel.com
Seattle, WA
Are there any more details about how DisplayMaterials work? They seem bizarrely irregular.
For example, I've not been able to properly assign .SetTransparencyTexture without also assigning .SetBitmapTexture. Also anytime I've added .SetEnvironmentalTexture, I can't seem to remove it later (as in, anytime I make a DisplayMaterial using the same source file for the Bitmap Texture, the EnvironmentTexture returns, even if not assigned in the script).
Also is there anyway to scale the BitmapTexture? Currently they are all sized relative to the object, but I'd like to scale it to a global size (like a planar texture mapping set to a constant interval).
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