Hi all
I’m developing a plug-in component in Visual Studio to ‘voxelize’ a random shape.
(i) First component generates a dataTree (or list) of points.
(ii) Second component makes ‘Center Boxes’.
I would like to add a custom preview to this second component, which will have different colors in a later stage… But I can’t seem to find the best method for this.
I’m testing the performances of different strategies in C# in GH; but I can’t seem to find methods that are as fast a the existing ‘Custom Preview’ component of GH. .
Using the standard display method of GH is very fast. But I don’t like the transparency.
I’ve used ‘Preview Override’ (see code below), but it has a duration of 72 ms compared to 19 ms. How can I speed up this process? Any ideas anyone? I really need it to be as fast as possible. Voxel settings are still very coarse now.
Thanks! -Gieljan
My code
using System.Drawing;
private void RunScript(Box voxels)
{
_boxes.Add(voxels);
_materials.Add(new Rhino.Display.DisplayMaterial(System.Drawing.Color.Black, System.Drawing.Color.White, System.Drawing.Color.White, System.Drawing.Color.Coral, 0.0, 0.0));
}
private readonly List<Box> _boxes = new List<Box>();
private readonly List<Rhino.Display.DisplayMaterial> _materials = new List<Rhino.Display.DisplayMaterial>();
private BoundingBox _box;
public override void BeforeRunScript()
{
_box = BoundingBox.Empty;
_boxes.Clear();
_materials.Clear();
}
public override BoundingBox ClippingBox
{
get { return _box;}
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
if (_boxes.Count == 0)
return;
for (int i = 0; i < _boxes.Count; i++)
args.Display.DrawMeshShaded(Mesh.CreateFromBox(_boxes[i], 1, 1, 1), new Rhino.Display.DisplayMaterial(_materials[i]));
}
public override void DrawViewportWires(IGH_PreviewArgs args)
{
if (_boxes.Count == 0)
return;
for (int i = 0; i < _boxes.Count; i++)
args.Display.DrawBox(_boxes[i], System.Drawing.Color.Black);
}