How can I retrieve polygons with respective vertices from a PShape?

I would like to be able to retrieve all individual polygons from a PShape object (preferably an imported .obj) in order to know which vertices are linked to each other.

for example if I was to import a simple tetrahedron i would like to retrieve the indices of the vertices linked to a vertex with a given index.

since a tetrahedron has 4 vertices this should give me something like this:

vertex 0 is linked to the vertices 1, 2, 3
vertex 1 is linked to the vertices 0, 2, 3
vertex 2 is linked to the vertices 1, 0, 3
vertex 3 is linked to the vertices 0, 1, 2

This could theoretically be achieved by checking which vertices are contained in which polygon, but I have no idea what methods to use for that or if an appropriate method even exists. Anybody got any suggestions?

EDIT: So I figured out that


returns a PShape that consists of the polygon at the index.


on that PShape returns the 3 vertices of that Polygon so that’s a step forward.
Stil, what I would like to do is to know which Vertex is attached to which Polygon globally in order to see which Vertices are neighbors. Hope somebody can help me out :slight_smile:

It sounds like you want to be to do the kinds of operations typical of a mesh library. Will you be working with triangles specifically, or any arbitrary polygon?

Here is an interesting related past discussion

These might be worth checking out to see if they already have tools to solve your problem:

  • Mesh by Lee Byron
  • Toxiclibs by Karsten Schmidt
  • iGeo by Satoru Sugihara
  • Hemesh (WBlut)
1 Like

Hey @jeremydouglass,

Thanks for your reply. The toxi.geom package seems very promising! I’ll check it out.

1 Like