Dear all,
First off, sorry about this huge text, but it was important for me to explain the problem properly. :)
I have a pretty hairy geometry question I've been pondering for a while. I'm developing an application that involves the generation of some pipes. The pipes consist of meshes created at runtime, two meshes per pipe (one with triangles facing out, the other with triangles facing in, so that it doesn't become invisible from neither the inside or outside). The meshes are drawn around a line in space defined by a series of points that are read into the program from an XML file. Think of them as subway tunnels, basically.
Occasionally, the tunnel might have sidetracks that split apart from the main pipe. Sticking to the subway analogy, this is just a connecting tunnel. The sidetrack is defined by a series of points just like the mainpipe, and then a certain position that indicates where it connects to the main pipe.
At the moment, I'm simply drawing the sidetrack with the exact same algorithm as the mainpipe, with no regard to intersecting geometry. From the outside, this looks fine:
The sidetrack seems to just blend into the mainpipe seamlessly.
But when you move the camera closer so that the near clipping plane cuts open the geometry, the fact that they are simply drawn on top of one another without any kind of attention to intersection becomes painfully obvious:
This is a problem, since I need the user to be able to traverse the inside of the pipes and see where they split apart properly from the inside as well. This is a Constructive Solid Geometry problem, i.e. it involves the merging of two parametric surfaces. These problems aren't usually trivial, and I've sweated over how to solve it for a while, and I have a few ideas, but I'd like your input on how to best do it, which is why I'm posting the problem here. :)
My idea is to try and generate a voxel grid surrounding each pipe, and then perform set operations on them to remove the voxels that overlap in space, that is, the voxels from a sidetrack that end up inside the mainpipe's geometry. After that, I would reconstruct the triangle mesh using some implementation of the Marching Cubes algorithm.
So I guess the question is two-fold. First, can you think of a better way to accomplish the merger of this geometry where the pipes intersect? Second, if not, do you know of a library for Unity that specializes in constructive solid geometry, or am I on my own? Thanks in advance!
- Christian