Grasshopper

algorithmic modeling for Rhino

Hi all, 

       I am a python user(beginner) trying to understand meshes and meshing algorithms like Marching cubes, Ball Pivot and Marching tetrahedra. I saw basic example provided with rhinoscriptsyntax, It was hard to imagine how hard it was to make mesh faces assigned from points. One way i could think of not Reinventing the wheel was to call mesh from points commands in python . I needs some direction to head towards creating meshes in rhino

      I was suggested Libraries but i not smart enough to figure out how to or where to use them exactly. 

Views: 8167

Replies to This Discussion

I baked the points and also got an average of all points and baked a sphere.so selected points when "mesh patch" command asked. and for surface  i took the sphere as refference.

I would recommend using rhinocommon rather than rhinoscript when you can...it will give you a lot more control over the objects you're working with, and direct access to their methods.

Check the Python example here for the syntax: http://wiki.mcneel.com/developer/rhinocommonsamples/addmesh

I wasn't even aware of the distinction (!), and there's more Python examples in the rhinocommon.chm than in RhinoScript.chm help files I have on my iPhone. The RhinoIronPython.chm file also relies on rhinoscript content. Rhinocommon it is then, as my main toolbox.

You can browse all of the classes and methods in the SDK here: http://4.rhino3d.com/5/rhinocommon/ :)

The Python example finally adds geometry to the Rhino document using:

scriptcontext.doc.Objects.AddMesh(mesh)

...but I have no idea how to even approach figuring out how to export the mesh via a Python output. There's no damn manual for this stuff for Python in Grasshopper. Do I assign that final AddMesh line to an output variable, or else assign "mesh" itself to it? I mean I'm at pure trial and error stage still, after a year of delving into Python in Grasshopper. I can't even tell if "mesh" is a variable I'm loading up or a shortcut for the function Rhino.Geometry.Mesh(). There is an arbitrary human element to these rules and without a clear manual it takes hours to figure out little things like this. All the error checking these examples add only confuses those of us trying to learn, too.

I think python is not into rhino development that is why it is less documented ???

It definitely is like walking around in the dark. Such is the life of live beta!

I really don't Python myself...more of a C# guy these days...but no...don't bother with the doc.Objects stuff. These examples on the Rhinocommon WIKI are definitely NOT written directly for Grasshopper components, but for the general Python editor for Rhino, so they all also deal with interfacing directly with the Rhino document. In GH you have the luxury of just worrying about creating the data or geometry objects, and then letting it manage the interface with Rhino. What you probably want to focus on (at this point) are only those classes and methods in the Rhino.Geometry namespace. So don't worry about the AddMesh stuff, or redrawing, or commands...etc.

If "a" is the output variable on your component and "mesh" is your mesh, you can just set "a = mesh".

What is this line doing?

mesh = Rhino.Geometry.Mesh()

(A) one time filling the variable "mesh" with an empty container of a mesh object?

(B) creating a convenient shortcut for "Rhino.Geometry.Mesh()" in the rest of the script that I could just as well replace each "mesh" in my script with "Rhino.Geometry.Mesh()"? Similar to how "import Rhino as rh" is used and then "rh." bastardly replaces "Rhino."

If so, then where is my mesh located, conceptually, then, if not in the variable "mesh"?

(C) something else?

Creating a new Mesh object called "mesh". You could call it anything. So say you have three points (P0, P1, and P2) when you want to add them as vertices to it, you do:

mesh.Vertices.Add(P0)

mesh.Vertices.Add(P1)

mesh.Vertices.Add(P2)

Then you want to organise these as a face:

mesh.Faces.AddFace(0,1,2)

What I do with my marching cube/tetrahedra implementations is make a main mesh:

OutputMesh = Rhino.Geometry.Mesh()

then, I cycle through each unique triangle:

for(whatever the for syntax is for python)

TriMesh = Rhino.Geometry.Mesh()

TriMesh.Vertices.Add(P0)

TriMesh.Vertices.Add(P1)

TriMesh.Vertices.Add(P2)

TriMesh.AddFace(0,1,2)

OutputMesh.Append(TriMesh)

OutputMesh.Vertices.CombineIdentical(true, true)

End for

a = OutputMesh

"import Rhino as rh" threw me off. Ah, it does not just assign a shortcut using an equals sign, but uses the word "as" to do that within the import command, some special case. I hate that though, so I use long hand and just write Rhino in my code since I'm not lazy and want to see what's there.

The distinctions you have revealed today are treasure that should soon triple my income as one of the few to land on his feet.

But how do you reset/clear the "TriMesh" container for each unique isolated single triangular mesh face that you then append to OutputMesh? Do you reissue the TriMesh = Rhino.Geometry.Mesh() each loop cycle? Or is there step where you formally clear it by assigning it to ""?

Better question, how do you think about such things? Your example contains no loops, just one purely conceptual cycle.

I'm answering my own question here, since you do specify a loop ("for"/"End for") and indeed you do re-issue the TriMesh blank container line (TriMesh = Rhino.Geometry.Mesh()) inside the loop.

There is a cartoon version of these distinctions that means a simple crystalline world of the gods exists.

Is the only way to "clear" the TriMesh container by re-initializing it? Do variables have types in Python in Grasshopper in Rhino?

Yes, you declare your TriMesh each time you get a triangular result from the algorithm, where you execute "PolygoniseTri". Whenever one of these returns a list of three valid points, you want to create a face from them, and then append that face to your main mesh. At the very end, by culling duplicate vertices (which Rhinocommon does super fast), you kill all of the duplicates.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service