I have the following code in one of my components to preview some structural geometry, these are Breps that represent a structural beam or member for visualization:
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
// Extrude elements
if (extrude)
{
// let's create some BREPS for the beams
List<Brep> extrudedBeams = Visualise.ViewElements.ViewBeams(this.unsolvedModel);
foreach (Brep beamBrep in extrudedBeams)
{
args.Display.DrawBrepWires(beamBrep, Visualise.Colours.colour_black);
args.Display.DrawBrepShaded(beamBrep, Visualise.Colours.colorMaterial);
}
}
base.DrawViewportMeshes(args);
}
As I move the viewport around in 3D or 2D, the above is called each time (as expected), but the viewing is very very choppy with slow redraw performance.
The Visual Studio profiler claims ~800ms on this line:
base.DrawViewportMeshes(args);
Other lines are <= 1ms. This includes this outside function call:
List<Brep> extrudedBeams = Visualise.ViewElements.ViewBeams(this.unsolvedModel);
For reference, that list has 51 items in it, each consisting of 3 Breps or so. However, this is a problem with any number of extrudedBeams
above about 5.
I donât know the inner workings of the base
call so not sure on how to efficiently use it.
Am a bit surprised that the performance is this slow for previewed geometry. Iâve seen much more complicated models and Rhino handles those just fine.
Iâve tried:
- Moving
List<Brep> extrudedBeams = Visualise.ViewElements.ViewBeams(this.unsolvedModel);
toSolveInstance
, no difference to performance. - Merging the
extrudedBeams
list into a singleBrep
(inSolveInstance
) and drawing that instead of theforeach
loop. The merge operation was horrendously slow, and unfortunately once merged, the performance was just as choppy.
I could try:
- Some kind of RxC treatment where it redraws once the
DrawViewportMeshes
call is not called for last 800ms or something. Wonât look good on the end userâs screen, but at least theyâll be able to rotate and navigate without slowdowns. Not 100% sure how to implement this though. - Temporarily bake the geometry to some temporary layer then delete layer and rebake when geometry updates.
What can be done here? Am expecting the performance to be close to baked geometry for this preview geometry.
Any ideas appreciated.