Custom data parameter preview performance very slow


I have a custom data type as a class in Visual Studio, lets say “CustomMesh”. It is essentially a mesh, but with more data behind (more points). Inside CustomMesh class I have implemented a DrawViewportMeshes as follows:

public void DrawViewportMeshes(GH_PreviewMeshArgs args)
if (this == null) { return; }
Mesh dispMesh = DisplaySimpleMesh();
args.Pipeline.DrawMeshShaded(dispMesh, args.Material);

where dispMesh is a very simple light version of the real full mesh laying behind. Only for rendering and drawing purposes.

Now, I have created a custom Parameter, where I have IGH_PreviewObject implemented as:

public void DrawViewportWires(IGH_PreviewArgs args)


Although dispMesh is a very very simple mesh, and I can view it in the viewport, when handling Rhino things are veeeery slow and general performance decreaces.

Any idea why is this happening? if I convert my “CustomMesh” to a normal GH Mesh, things speed up again. So I feel Im doing something wrong either in my parameter drawing, or in my CustomMesh class drawing.

Any Ideas?

Try to store dispMesh as a cache/ internal variable inside the class and only build it (calling DisplaySimpleMesh()) when your input data changes. Perhaps creating that lightweight mesh every time rhino renders the viewport is the cause of the delay.

Hi Dani, thanks for the answer, I think you are right.

Do you know how I can call my fuction DisplaySimpleMesh inside the parameter? Is it inside DrawViewportWires section from the parameter? Im struggling to access the object inside the parameter in order to call my function DisplaySimpleMesh()…help is most welcome!

@DavidRutten any help is very much appreciated :slight_smile:

this can never be null, or the code wouldn’t be running.

And yes, cache your display mesh. Recreating it from scratch for every update of every viewport is a waste of processing cycles.

I can change this to this.m_value == null, but I think it wont solve the performance problem… any other idea?

Yes, cache your display meshes. How many of these meshes are contained in a single parameter. A few? A couple hundred? Millions?

Its basically a high order tetrahedral mesh. In the data type there is a list of Nodes (id, x, y, z), list of tetra elements (each tetra is a mesh of 4 faces). So yea they can be in the order of thousands of meshes inside the data type. DisplaySimpleMesh is a function inside the class just returning a mesh around the volume, only for rendering the shape. I dont want to render each tetra element. Do you have any example for doing this caching?