I have a nice triangulation of a square mesh. The way I do this currently is
- generate square mesh (two triangles), from (0.,0.) to (1.,1.) (axis-aligned and normalized for simplicity)
- add point somewhere within square (poisson disk sampling)
- detect which triangle point falls within
- subdivide into 3 triangles
- iterate over all tris, perform "delaunay flips" where necessary
- GOTO 2
This works great (a bit simplified, as there's also edge-case detection code to account for colinear points, fp precision errors, etc...).
Anyways, what I want to do now is have the edges of this square "wrap".
EDIT: Upon request, here are some illustrations to help convey my problem:
So, we have an initial set of pts:
A normal delaunay triangulation would generate something like this:
What I want is a tessalated delaunay triangulation. That is, what edges would have to exist to allow this to be infinitely tile-able:
An example set of edges might be like this:
Now, imagine if you left those connections, but didn't tile them. I've drawn just the "wrapping" connections for the red dot and the purple dot in green, assuming there is only one instance of each dot in view (centered around the initially displayed set of dots):
Already, it's a topological mess. But in theory, I'd expect it would work, assuming I stick to some implementation constraints.
So, the plan would be to create a mesh containing all these pts and their respective connections. I would have some offset, and move the points in the vertex shader as a modulus of that offset. That way, every point will exist as "the closest instance of that point in the infinitely tiling plane" to the offset (for example, the camera). Since all the connections are in place, I wouldn't have to mess with them, and would get infinitely-scrolling (repeating) "terrain". All the topologically-messy-wrapping connections would be "backfacing" triangles, and would be culled... right?
Edit: Ok no they would not necessarily be backfacing... shoot. (if the wrap of the triangle was both vertically and horizontally wrapped, it would be back to frontfacing. My best guess at a solution is to, in the vert shader, artificially lower all the pts "close" to being wrapped, so any wonky giant tri's show up way below any legitimate tris. #hack.
Ok. off to try this. Will report back with any updates...