algorithmic modeling for Rhino
I've written C# component that takes in a list of meshes, applies transforms to them, and then previews them. I was hoping to get relatively fast drawing speeds so that I can animate them.
I perform the transform computations from within solve instance, and then signal the component to redraw the meshes.
I'm drawing meshes in DrawViewportMeshes and DrawViewportWires by calling args.Display.DrawMeshShaded, and I'm not doing any computation inside those routines.
The bottleneck occurs at the end of SolveInstance, when I call this.PreviewExpire(true)' to tell the component to redraw the preview geometry. This one call takes a significant chunk of time, but all I want to do is redraw the component meshes.
Is there a better method call to make to signal the component to redo the preview? Or is there a better way to preview the meshes? I can work out some demonstration code if the above description is not clear enough.
Thanks everyone for the help!
Tags:
If I just export the meshes as parameters (and don't force my component to draw the meshes), which will cause Grasshopper to preview the geometry, the compute time goes from 100ms to 5ms. The main reason why I wish to do the previewing internal to the component is so that I can change the display material for different situations.
There must be a 'correct way' to preview meshes from a component with custom display materials.
You shouldn't have to call PreviewExpire from within SolveInstance. Whenever SolveInstance runs the preview is automatically expected to expire.
If you're displaying meshes by overriding DrawViewportMeshes and those meshes are cached (i.e. don't need to be computed prior to every drawing operation) then all you need to do is trigger a redraw of the Rhino viewports. You do not need to recompute or expire previews in this case.
Some background information: expiring previews accomplishes two things:
Invalidating viewports means that at some point in the future (probably quite soon, but no guarantees are given as to when) the viewports will redraw themselves. When this happens Grasshopper will notice and draw its preview geometry into those viewports. For this it iterates over all components (and parameters) which could potentially draw previews. This list exists so that GH doesn't have to perform a lot of casts and tests on every viewport redraw.
If you have your geometry standing by and do not need to perform any computations that would involve SolveInstance, then you can just call
Rhino.RhinoDoc.ActiveDoc.Views.Redraw()
and be done with it.
If I have misunderstood your problem, then please post the offending code.
--
David Rutten
david@mcneel.com
Tirol, Austria
I suppose I misunderstood how to preview geometry. Removing ExpireSolution still allows geometry to be previewed now, and it's fast too. Thanks for your help.
Bump. Surely, someone has solved this problem before...
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by