Preview Geometries how to avoid useless computation by caching results?


I have a question regarding preview geometries, i.e. those that can be drawn with DrawViewportWires() and DrawViewportMeshes() methods.
Just as an example let’s consider that I have a curve and I want to display in the viewport some values and/or some symbols on this curve at certain positions. The computation of positions and the retrieve of values it is computationally expensive and I would like to cache the result to avoid to recompute every time that I pan, rotate or zoom in the viewport and let the computation run again just if the curve has changed.

The question are:

  • If I have a Grasshopper document, whenever I move in the viewport , e.g. zooming out, every component’s parameters that inherit from IGH_PreviewObject drawn again them self with
void DrawViewportWires(IGH_PreviewArgs args);
void DrawViewportMeshes(IGH_PreviewArgs args);

or there is some caching mechanism to avoid to compute everything if nothing has changed?

  • Which could be the best place where to cache results?


@DavidRutten maybe you are the right person to ask for it?

Place the cache information in your GH_Component derived class.

  • When SolveInstance is called, delete your cache.
  • In your draw functions, check to see if the cache is null and if so create and drwa it. If your cache already exists, then just use it.