I’m creating some components that preview voxel data as a point cloud with colours. I’ve got my custom data type set up with the corresponding DrawViewportWires override to draw the bounding box:
public class VoxelGoo : GH_GeometricGoo<VoxelStructure>, IGH_PreviewData
{
...
/// <summary>
/// Clipping box for drawing.
/// </summary>
public BoundingBox ClippingBox => Boundingbox;
public void DrawViewportWires(GH_PreviewWireArgs args)
{
args.Pipeline.DrawBox(Boundingbox, Color.DarkOliveGreen);
}
...
}
Which works fine as seen in the below screenshot when the relevant preview is activated on the canvas:
I’ve also got a custom preview component that renders the voxels as a point cloud, with associated colours for their values:
protected override void SolveInstance(IGH_DataAccess DA)
{
GH_Structure<IGH_Goo> voxelGoos = new GH_Structure<IGH_Goo>();
Interval displayRange = new Interval();
int weight = 2;
string colourBarTitle = "";
if (!DA.GetDataTree("Voxel Data", out voxelGoos)) return;
if (!DA.GetData("Scalar Range", ref displayRange)) return;
if (!DA.GetData("Point Weight", ref weight)) return;
if (!DA.GetData("Colourbar Title", ref colourBarTitle)) return;
_colourBarTitle = colourBarTitle;
_weight = weight < 1 ? 1 : weight;
_displayClouds = new List<PointCloud>();
foreach (var branch in voxelGoos.Branches)
{
if (branch != null)
{
foreach (var voxelGoo in branch)
{
if (voxelGoo == null) continue;
var display = new VoxelGoo((VoxelGoo)voxelGoo);
_displayClouds.Add(GeneratePointCloud(display, displayRange.T0, displayRange.T1));
}
}
}
_interval = displayRange;
_voxelGoos = voxelGoos;
}
/// <summary>
/// We need this to be able to draw the preview.
/// </summary>
/// <param name="args"></param>
public override void DrawViewportWires(IGH_PreviewArgs args)
{
base.DrawViewportWires(args);
if (!Locked)
{
... Colourbar code ...
if (_displayClouds.Count > 0)
{
foreach (var cloud in _displayClouds)
{
args.Display.DrawPointCloud(cloud, _weight);
}
}
}
}
If both of these components have their preview enabled, the custom preview component displays the point cloud with a colourbar:
However, if I deactivate the preview on the “SpatialCorrelation” component, stopping the draw call on my custom class, my preview component also deactivates the preview, despite it still being “activated” on the canvas (notice how the colourbar isn’t drawn):
I have tried debugging this in Visual Studio, and when the previously connected component has preview deactivated, the corresponding DrawViewportWires method in the Preview component is not even called, hence not even the colourbar is drawn. Visual studio doesn’t give any information as to why the draw calls are not happening in the custom preview component.
Can anyone suggest why simply deactivating the preview of a previous component affects my upstream preview?
Please let me know if there’s some detail I haven’t included!
Thanks!