Knowing how to group connected faces when exporting?


So I’m writing a 3D exporter, and have it working, but not optimally.

Say I have a rectangle, and I draw another rectangle in it, and then pull that face up. I now have a connected mesh that has at least 6 faces, one of which I will have to triangulate (the outer rectangle that has the piece pulled out of it).

Theoretically, I could join those triangles and the 5 quads that make up the pulled box into a single mesh.

But now if I draw another rectangle, disjoint from the rest, I obviously would want to export that as a different mesh, since it doesn’t share any vertices with the others.

Without doing some sort of connectivity analysis, is there something in the API that I could use to discover this myself so that I would naturally export two meshes, one with 5 quads & some triangles and the other mesh as a single quad?

Thanks for any insight. I was going to put a picture in-line to show what I was talking about, but don’t see how to do that…