views:

215

answers:

3

I've got a bunch of overlapping triangles from a 3D model projected into a 2D plane. I need to merge each island of touching triangles into a closed, non-convex polygon.

The resultant polygons shouldn't have any holes in them (since the source data doesn't).

Many of the source triangles share (floating point identical) edges with other triangles in the source data.

What's the easiest way to do this? Performance isn't particularly important, since this will be done at design time.

+1  A: 

Try gpc.

lhf
unfortunately this will be used in a commercial game; not sure how UManchester would feel about that.
nornagon
gpc has a commercial license as well. Moreover, gpc lists other similar libraries at http://www.cs.man.ac.uk/~toby/alan/software/#Links . Perhaps one of those has a more suitable license.
lhf
+1  A: 

Imagine the projection onto a plane as a "view" of the model (i.e. the direction of projection is the line of sight, and the projection is what you see). In that case, the borders of the polygons you want to compute correspond to the silhouette of the model.

The silhouette, in turn, is a set of edges in the model. For each edge in the silhouette, the adjacent faces will have normals that either point away from the plane or toward the plane. You can check this be taking the dot product of the face normal with the plane normal -- look for edges whose adjacent face normals have dot products of opposite signs with the projection direction.

Once you have found all the silhouette edges you can join them together into the boundaries of the desired polygons.

Generally, you can find more about silhouette detection and extraction by googling terms like mesh silouette finding detection. Maybe a good place to start is here.

brainjam
This isn't quite adequate -- for one, I have several model parts whose projections overlap.
nornagon
@nomagon, good point. Also, are your models closed? I.e. do they have an inside and an outside like a sphere or a torus? Or are they just a general polygon soup?
brainjam
+1  A: 

I've also found this[1] approach, which I will be trying next.

[1] http://stackoverflow.com/questions/1014293/2d-outline-algorithm-for-projected-3d-mesh

nornagon