meshmash / Plankton

A C# half-edge mesh data structure, and components for using this in Grasshopper/Rhino
http://meshmash.github.io/Plankton
GNU Lesser General Public License v3.0
216 stars 66 forks source link

HalfEdge Line #39

Closed petrasvestartas closed 7 years ago

petrasvestartas commented 7 years ago

Hi,

I would like to ask several questions regarding plankton:

  1. How to get HalfEdge as rhino Line? First I was thinking that I can get start and end vertices, but in the drop-down menu I only see StartVertex field.

  2. What is the method to change mesh vertex position (similarly as in Rhino Mesh setVertex function)?

  3. Is it possible to know how many connected vertices / edges each vertex/halfedge has?

  4. How to duplicate PlanktonMesh? In rhinomesh I used mesh.DuplicateMesh()

  5. How can I check if halfed is naked?

Sorry for so many question but I am translating one script from rhino to plankton meshes. It is so nice that there is no difference between vertex and topology vertex, rhino mesh is such a workaround in some cases.

Thank you, Petras

pearswj commented 7 years ago
  1. There isn't currently a method which constructs a Rhino.Geometry.Line from a PlanktonHalfedge. There are a bunch of extension methods in PlanktonGh.RhinoSupport so – if you also reference Plankton.gha in the C# script component – you could do the following...

    // "i" is the index of a halfedge
    var from = pmesh.Vertices[pmesh.Halfedges[i].StartVertex].ToPoint3d();
    var to = pmesh.Vertices[pmesh.Halfedges.EndVertex(i)].ToPoint3d(); // uses EndVertex helper
    var line = new Rhino.Geometry.Line(from, to);
  2. You can use PlanktonVertexList.SetVertex to change the position of a vertex. There are also extension methods for Point3f and Point3d.

    pmesh.Vertices.SetVertex(i, x, y, z);
    pmesh.Vertices.SetVertex(j, new Point3d(x, y, z));
  3. See PlanktonVertexList.GetVertexNeighbours and PlanktonVertexList.GetHalfedges.

    // "i" is the index of a vertex
    int[] vertexNeighbours = pmesh.Vertices.GetVertexNeighbours(i);
    int[] outgoingHalfedges = pmesh.Vertices.GetHalfedges(i);

    Under the hood Plankton uses "circulators" to handle adjacency queries; there are vertex circulators for when you want to iterate through all the halfedges around a vertex and face circulators for when you want to iterate through all the halfedges around a face.

  4. To duplicate a PlanktonMesh simply construct a new one.

    var dup = new PlanktonMesh(orig);
  5. Check out the PlanktonHalfedgeList.IsBoundary method.

    bool naked = pmesh.Halfedges.IsBoundary(i);
  6. I've linked back to the source code a lot, but we also have some rough and ready docs at http://pearswj.co.uk/plankton. Have a look around :)
petrasvestartas commented 7 years ago

Thank you very much for such a detail overview:)