algorithmic modeling for Rhino
Hi,
Has anyone by chance made custom previews from within script components? Based on an example posted by David, I have reached here so far:
Private Geo As New List(Of GeometryBase)
Private Mats As New List(Of Rhino.Display.DisplayMaterial)
Public Overrides Sub DrawViewportWires(ByVal args As IGH_PreviewArgs)
If (Geo.Count = 0) Then Return
For i As Int32 = 0 To Geo.Count - 1
Dim C As Rhino.Display.DisplayMaterial = Mats(i)
Dim P As GeometryBase = m_Geo(i)
args.Display.DrawBrepShaded(P, C)
Next
End Sub
My problem is, other preview components start acting weirdly when this runs. Once I got the preview and then it disappeared. I guess I should somehow dispose this preview somewhere. But I have not understood when and why and how.
My ultimate goal is to make a Sub(routine)/Void with a functionality similar to the custom preview component, to use it in a bunch of components already made.
Any help is very much appreciated.
Tags:
Hi Pirouz,
the VB/C# components now indeed have those overridable methods. You can insert them by clicking on the Preview Overrides button:
Incidentally, DrawViewportWires is where you should draw curves, points and edges. DrawViewportMeshes is where shaded meshes go. So DrawBrepShaded should probably be called from within DrawViewportMeshes.
Also your Geo list contains GeometryBase objects, whereas you are calling a method which requires Breps. What happens if there's something other than a Brep stored in Geo? It'll crash, that's what. And it may well cause the rest of the preview to be skipped at that point, not sure. Also, are you making sure there are no nulls in the Geo and Mat lists?
The code uses Geo in some places and m_Geo in others, that can't be right...
--
David Rutten
david@mcneel.com
Tirol, Austria
Hi David, This is great feature. Thanks a lot! Works perfectly!
Hi David,
I managed to put all previews in my components; and everything was working fine. After a few tests, just once suddenly my laptop screen turned black and I got an error message from my machine's NVIDIA graphics card saying something went wrong with Rhino. Rhino crashed afterwards and asked me to close it. I was wondering if this might have anything to do with my custom preview methods. Should I "dispose" displays at some point? (like this for instance?
args.Display.DisplayPipelineAttributes.Dispose)
If you create those instances and nobody else has any copies, then you should always Dispose when you get the chance. I don't think it should cause graphics card crashes though if you don't.
The only things that really wreck havoc when not disposed properly are GDI objects (controls, forms, bitmaps, pens, fills). Windows only allows any application to use a small amount of GDI handles and if you run out, the whole thing comes crashing down.
If you can repeat this crashing behaviour we'd love to see the files.
--
David Rutten
david@mcneel.com
Tirol, Austria
Thank you very much for your response. I am about to release all components in a plugin. In case this happens to any of users, I will let you know. Just one question: what does this method actually do?
args.Display.DisplayPipelineAttributes.Dispose()
I have added this to my code and it is functioning as it used to (But of course that crash just happened once before adding this).
Eh, I assume that call disposes an instance of DisplayPipelineAttributes. If you didn't create this instance (i.e. by calling NewDisplayPipelineAttributes() or something) then you probably shouldn't be disposing of it.
The problem with disposing is much like the problem of trash on the street. If you eat a sandwich you're supposed to dispose of the wrapper yourself, otherwise you can get arrested for littering. However walking into a Subway and starting to throw out sandwich wrappers of people who are still eating their sandwiches is a bit overzealous and probably gets you kicked out of Subway. If you see a piece of wrapper lying on the street, you can typically leave it there because there is a Garbage Collector in .NET which will come along shortly and throw it out*.
--
David Rutten
david@mcneel.com
Tirol, Austria
* Not technically true in the context of this analogy, the GC will not call Dispose() on a class, but if the class has been properly designed it will Dispose itself whenever it gets garbage collected.
:)) Got an idea finally. Thanks for your interesting explanation.
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