algorithmic modeling for Rhino
Can someone point me to a discussion or reference giving a general overview on why I would want to, or need to, use GH geometry inside a C# or Python component instead of Rhino geometry. Basically, is there an introduction to how Grasshopper handles geometry and why there is a need for a separate set of GH_Geometry classes? For example, when and why would I need to cast between the two?
I've been picking up bits and pieces from threads but its very frustrating to not have a clear explanation of what's happening. If one exists already, I would love to read it. If one does not, it should really be written sooner than later.
Thanks so much, David
Tags:
Grasshopper doesn't really have its own geometry, what it has are wrapper classes for all the data types it uses. So GH_Brep is not a different implementation of the notion of a boundary-representation, it just provides a bunch of additional methods and carries a regular Rhino Brep inside of it.
As a component developer there are a few cases in which you would deal with these IGH_Goo wrapper types directly:
Very few native components actually deal with these GH_XXXX types themselves, they are mostly just the way Grasshopper talks to itself.
Thanks so much for the prompt reply. Knowing these are wrapper classes is very helpful, and cuts short a ton of secondary questions. Is it right to assume Rhino DocObjects are wrapper classes as well, seeing they have a geometry and a set of attributes attached to that geometry? These are more intuitive to me.
The last issue I have then is knowing how to pull geometries from Rhino so that either:
(a) The reference is maintained and thus if the geometry in Rhino is changed, it will be changed in GH as well. It seems using the DocObject's GUID is the proper (only) way to do this? How do I maintain this if I'm passing geometry between components?
(b) The reference is severed immediately (either upon calling the geometry from RH into GH, or through a conversion) and thus the geometry becomes "naked" so to speak within GH? I would like to do this without having to manipulate the geometry, make a copy, etc., or pass it in and out of a component, which it seems sometimes does this for you. Instinctively I would imagine this is where i convert to a GH_Brep, or wrapper class, or, pull the geometry out of the DocObject wrapper class?
If it saves you time, David, feel free to point to other discussions. I searched, and didn't find anything with super clear answers however.
Lastly, I will try and write up a short explanation of all of this and add it to the common questions section. There doesn't appear to be anything there in this topic.
Is it right to assume Rhino DocObjects are wrapper classes as well, seeing they have a geometry and a set of attributes attached to that geometry? These are more intuitive to me.
Yeah pretty much. The DocObjects add attributes and a bunch of drawing/picking caches to regular geometry without re-implementing said geometry.
You can use the GH_Convert class to perform almost all conversions between types known to Grasshopper. For example you can convert Rhino object ids to IGH_GeometricGoo instances using:
ObjRef objRef = new ObjRef(id);
A = GH_Convert.ObjRefToGeometry(objRef);IGH_GeometricGoo goo = GH_Convert.ObjRefToGeometry(objRef);
if (!goo.IsGeometryLoaded)
goo.LoadGeometry(RhinoDocument);
goo.ReferenceID = Guid.Empty;
B = goo;
where A is a referenced GH_Brep and B has been dereferenced.
Thanks so much.. these work great.
One last, last, last question (i hope)...
When I use DocObject.ObjRef.Geometry(objRef) , and then print the results I get something like:
<Rhino.Geometry.Brep object at 0x0000000000000031 [Rhino.Geometry.Brep]>
Is this now a reference to a Brep in memory? Or is it still referencing the RhinoDoc object? When I pass this geometry out of the Python component, it now says Closed Brep, so I assume the the former. Is there any reason not to use the DocOBject.ObjRef.Geometry function above, instead of the slightly longer code you wrote:
IGH_GeometricGoo goo = GH_Convert.ObjRefToGeometry(objRef);
if (!goo.IsGeometryLoaded)
goo.LoadGeometry(RhinoDocument);
goo.ReferenceID = Guid.Empty;
B = goo;
Thanks...
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