From debug lines to a mesh - QuadTree > Mesh

Hello forums…

I’ve gotten myself in a bit over my head as usual with a task. The TLDR version is the title, which means I’m trying to use this guys code here:

To generate a QuadTree out of data points… which that part I can pretty much handle, but as you see in his code, it generates the data then represents it with a set of Debug.DrawLine() lines… and that is great and all, but I need to make a mesh (perhaps several meshes) out of those debug lines instead.

I have already started experimenting but so far - its mind boggling to me how to go from his output, to instead outputting a series of mesh objects.

Why do I want to do that you ask? Well I’ve got a 2D image that I use in a world generator, that looks like this:

(except my final map is actually much larger, this is a smaller version for testing)

Now, with this image I convert pixels into 10 x 10 tiles like so:

  • black lines are road tiles
  • green areas are grass tiles
  • white areas are paved tiles with buildings
  • red areas are paved tiles with no buildings
  • blue areas have nothing but a gray color (the generator makes nothing there, and a pre-existing large plane with gray color occupies the area slightly lower on Y position than all the other tiles so it shows under everything else)

And my generator works great as is - but the problem being that on a large world, it has just so many wasteful tiles side by side and burns precious mobile performance, which could easily be a single tile occupying a larger area. And sure, I could go in by hand after the generator is done and replace the many tiles in a QuadTree style, but that takes frikkin ages, and would require me doing it every single little change I make that requires me to regenerate the world. Hence, the need for a QuadTree mesh generating implementation here…

I seriously doubt anybody will have much useful information to share, because this is so highly specific to my games design, and my generators design… but I figured hey why not, lets ask if anybody has any idea how to move forward. Perhaps one of you has had to take on a similar problem, and has some useful tips to make doing this easier!

So if you have some advice, or even better, some code that might shed light upon how to proceed, please share! Even some ideas for using that QuadTree’s output to get to a set of mesh objects would help me out a lot right now.

Well, after several hours trying to wrap my head around Quadtrees, I decided to reapproach the problem with a more simple solution, and what I went with was deceptively simple - to just use a large quad with a texture of the world’s ground spread across it.

Thanks to this game having a fairly simple look, I was able to get away with a single sharp texture for the entire worlds ground rather than many smaller gameobjects. Of course this has its drawbacks, such as having to recreate the ground texture whenever changes are made to the world, but it helped a whole lot with performance on mobile versus the generated ground meshes for tiles. A nice benefit of doing this was that I can use as many unique colors and areas as I want to for the ground, at no additional performance cost!