Hi,
I am running separate Task in SolveInstance of grasshopper component, I collect some pointclouds and then I display pointcloud through (I also override boundingbox):
public override void DrawViewportWires(IGH_PreviewArgs args) {
args.Display.DrawPointCloud(cloud, 1);
}
The geometry is only displayed when I rotate or do smth in rhino viewport.
I tried to refresh rhino canvas
base.ExpirePreview(true);
base.OnPreviewExpired(true);
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw();
But it does not help.
Full code is here:
protected override void SolveInstance(IGH_DataAccess DA) {
bool run = false;
DA.GetData(0, ref run);
Plane plane = Plane.Unset;
int time = 60;
double dist = 1;
DA.GetData(1, ref time);
DA.GetData(2, ref dist);
DA.GetData(3, ref plane);
cloud = new PointCloud();
bbox = new BoundingBox();
double[] frame = new double[12] {
plane.Origin.X,
plane.Origin.Y,
plane.Origin.Z,
plane.XAxis.X,
plane.XAxis.Y,
plane.XAxis.Z,
plane.ZAxis.X,
plane.ZAxis.Y,
plane.ZAxis.Z,
plane.YAxis.X,
plane.YAxis.Y,
plane.YAxis.Z,
};
if (run) {
//run in other thread
System.Threading.Tasks.Task.Run(() =>
{
g3.DMesh3 dMesh3 = FastScan_Get_Read(time,frame,dist);
var g3box = dMesh3.GetBounds();
bbox = new BoundingBox(g3box.Min.x, g3box.Min.z, g3box.Min.y, g3box.Max.x, g3box.Max.z, g3box.Max.y);
for (int i = 0; i < dMesh3.VertexCount; i++) {
var v = dMesh3.GetVertex(i);
var c = dMesh3.GetVertexColor(i);
int color = (int)(c.x * 255.0);
cloud.Add(new Point3d(v.x, v.z, v.y), System.Drawing.Color.FromArgb(color, color, color));
}
});
GC.Collect();
GC.WaitForPendingFinalizers();
DA.SetData(0, cloud);
base.ExpirePreview(true);
base.OnPreviewExpired(true);
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw();
} else {
GC.Collect();
GC.WaitForPendingFinalizers();
}
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw();
}