@DavidRutten
Hi David, this is an old post but still very useful indeed.
How can the transparency be adjusted? In other words, have various components that output various color breps, but with the same transparency setting as the default grasshopper breps(Transparent red)
I have several components I developed as VS C# components and overwrote the “BeforeSolveInstance”, “AfterSolveInstance”, “DrawViewportMeshes” and “DrawViewportWires” methods. In the DrawViewportMeshes I set the DisplayMaterial(Color.Gold, 0.75), but this transparency does not seem to render properly.
More concerning is that it’s duplicating the breps for some reason. If I remove the override methods I am back to single breps again.
public class ColumnComponent : GH_Component
{
/// <summary>
/// Initializes a new instance of the ColumnComponent class.
/// </summary>
public ColumnComponent() : base("Column", "C", "Import column elements", "Link", "Link")
{
}
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("Content", "C", "Content of the file.", GH_ParamAccess.list);
pManager.AddTextParameter("Tag", "Tag", "tag.", GH_ParamAccess.item);
pManager.AddNumberParameter("Relative Height", "RL", "Height (Z) of level.", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddBrepParameter("Brep", "Brep", "Brep of Beam Element", GH_ParamAccess.list);
pManager.AddCurveParameter("Curve", "C", "Line from start point to end point", GH_ParamAccess.list);
pManager.AddTextParameter("Profile", "P", "Beam size (profile)", GH_ParamAccess.list);
pManager.AddNumberParameter("Rotation", "R", "Column rotation", GH_ParamAccess.list);
}
private readonly List<Brep> Breps = new List<Brep>();
private BoundingBox _clippingBox;
/// <summary>
/// BeforeSolveInstance method
/// </summary>
protected override void BeforeSolveInstance()
{
foreach (var brep in Breps)
{
brep.Dispose();
}
Breps.Clear();
_clippingBox = BoundingBox.Empty;
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
//Column collection
List<Column> Columns = new List<Column>();
//Declare input variables.
List<string> contents = new List<string>();
string tag = string.Empty;
double relativelevel = double.NaN;
//Check if input parameters are not null
if (!DA.GetDataList("Content", contents)) return;
if (!DA.GetData("Level Tag", ref tag)) return;
if (!DA.GetData("Relative Level", ref relativelevel)) return;
Columns = GetData.GetColumns(contents, tag, relativelevel);
//Declare output variables
List<Line> Curves = new List<Line>();
List<string> ProfileStrings = new List<string>();
List<double> Rotations = new List<double>();
if (Columns != null)
{
foreach (var column in Columns)
{
Brep brep = column.CreateBrep();
Breps.Add(brep);
Line line = column.CreateColumnAxis();
Curves.Add(line);
string profilestring = column.CreateProfileString();
ProfileStrings.Add(profilestring);
double rotate = column.Theta;
Rotations.Add(rotate);
}
}
else
{
return;
}
//Assign output variables to output parameters
DA.SetDataList("Brep", Breps);
DA.SetDataList("Curve", Curves);
DA.SetDataList("Profile", ProfileStrings);
DA.SetDataList("Rotation", Rotations);
}
/// <summary>
/// AfterSolveInstance method
/// </summary>
protected override void AfterSolveInstance()
{
_clippingBox = BoundingBox.Empty;
foreach (var brep in Breps)
{
_clippingBox.Union(brep.GetBoundingBox(false));
}
}
/// <summary>
/// Return the unified bouding box
/// </summary>
public override BoundingBox ClippingBox
{
get { return _clippingBox; }
}
/// <summary>
/// DrawViewportMeshes to override the color of the brep and brepwires
/// </summary>
/// <param name="args"></param>
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
DisplayMaterial brepShadeMaterial = new DisplayMaterial(Color.DarkBlue, 0.5);
foreach (var brep in Breps)
{
args.Display.DrawBrepShaded(brep, brepShadeMaterial);
args.Display.DrawBrepWires(brep, Color.DarkBlue);
}
brepShadeMaterial.Dispose();
}
/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return Properties.Resources.Ghc_Column_Icon;
}
}
/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("ef596c29-1d26-4b2d-ab76-ea11cc842792"); }
}
}