Display large amount of meshes that are totally the same in shape through grasshopper component

Hi,

I would like to ask what is the proper way of displaying large amount of elements via grasshopper component?

I have a collection of objects that are totally the same (not necessary boxes) but an example I did is this:

In the Solve instance each iteration I declare mesh that is global to the component:

previewMesh = new Mesh();

then I loop through a for loop and append mesh boxes to previewMesh

foreach(Rigid body in solver.Bodies){


previewMesh.Append(Mesh.CreateFromBox(b, 1, 1, 1));

}

And then display it through custom previews:

    public override void DrawViewportWires(IGH_PreviewArgs args) {
        args.Display.DrawMeshWires(previewMesh, System.Drawing.Color.Black);
    }

    public override void DrawViewportMeshes(IGH_PreviewArgs args) {
        args.Display.DrawMeshShaded(previewMesh, m);
    }

Since this is the same geometry I do not think this is the best way to create one large mesh out of many small meshes. What would be the most efficient way regarding display?

You must store the transform per mesh, then push the transform to the display pipeline prior to drawing each individual mesh, then pop the transform again afterwards. I can go into more detail after dinner.

The basic idea is this:

args.Display.PushModelTransform(transform);
args.Display.DrawMeshShaded(_mesh, mat);
args.Display.PopModelTransform();

pushpop.gh (7.5 KB)

Thank you, I did not know about this push and pop tranformations:)