Batching brep/meshes in pipeline draw

We have to draw a lot of point/lines/breps as part of a custom display conduit. When the amount get large there is a noticeable lag. Is there a better way to make these draw calls to improve performance? I’m wondering if there is a way to make some brep collection to Draw rather than a for loop in C#?

    private static void DrawSurfaces(IEnumerable<Brep> surfaces, Color color, DrawEventArgs e)
        using var displayMaterial = new DisplayMaterial(color, 0.5);
        foreach (var surface in surfaces)
            e.Display.DrawBrepWires(surface, color, 1);
            e.Display.DrawBrepShaded(surface, displayMaterial);

I’ve also heard that potentially caching the mesh or drawing the mesh can help improve performance. However, computing the mesh and instead storing this didn’t seem to have any drastic improvement.

Not all geometry is compute ahead of time and cached for the conduit to consume. Only when the user makes a change in our plugin is the geometry recompute (which doesn’t happen all that often).

If you are caching the meshes, you can join all meshes into one big mesh object, even if the parts of the mesh are disjoint. This can speed up drawing performance; drawing 1 big mesh is faster than drawing hundreds or more small meshes.

It does mean that when on part is changed, you need to re-create the big cached mesh, so that may slow things down. But if that does not happen all that often, you may get better performance overall.

Mesh cache = new Mesh();
foreach(var surface in surfaces) {
  Mesh part = Mesh.CreateFromBrep(surface, MeshingParameters.DocumentCurrentSetting);
1 Like

Great thanks! I figured something like this is possible. The user has a few controls for filtering things, but the user clicks a button far less than they trigger a redraw, so this suits my needs.

1 Like

Oh actually this won’t work with the grasshopper components I have. Each of my types is wrapped in a GH_Goo type which overrides DrawViewportMeshes and DrawViewportWires. I haven’t yet done my perfomance testing of the grasshopper library, but given the code is pretty much identical I guess I am going to have the same issue.