WTG (Wade Terrain Generator) v 0.1
This post continues an exploration of voronoi diagrams, terrain generation and Wade. If you want some background, you can see the first voronoi post here.
A Few Notes Before I Get Started
- This demo uses Wade 4.0.1
- D3 is freely available here and is released under the BSD license.
- Azgaar’s blog is here. I have used many of his ideas and some of his code in this endeavor.
Wade Terrain Generator v 0.1
To better organize the terrain generator, I have broken it up into a couple of roughly based modules:
- WTGGeometry – interface to the underlying voronoi mapping library. Currently using D3, but may be able to swap out for a faster library in the future. Include the canvas draw routines for drawing the underlying geometry (should drawing be a separate module ?).
- WTGGui – implement an interface so it is easier to customize terrain and maps
- WTGMap – isolate all the map making functionality. Ex: elevation, water, rivers, biomes, currently empty except for map neighbor function.
- WTGExporter – what should a terrain generator export ? An image, tiles ?
Final Results Preview
When you load the page, you see a blank grey screen with three tabs, (Geometry, Map, Export). The map and export tabs are currently not implemented, so don’t bother with those. Click the geometry tab and you should see a menu to create a voronoi diagram (the map’s underlying geometry). You can drag the sliders to change the size of map you want to create.
Polygon center placement is now calculated based on, “Poisson Disc Sampling”. This seems to be faster than using random points and then voronoi relaxation. This is relevant for the third slider on the menu, “radius”. Making this number larger will create fewer polygons while making this number smaller will create more polygons. The approximate polygon count should be shown in the middle of the menu between the build and update buttons.
After you have selected your parameters, click the build button to generate a voronoi diagram. After the diagram has been generated, you can go back to the geometry menu and toggle polygons, triangles and centers to show or hide them. If you change the map parameters (width, height, radius) they won’t be reflected in the diagram unless you click build again.
Building a map with a large number of polygons (> 2000) may take a little bit of time. So, if you click build and nothing appears to be happening, wait.
You can use the scroll wheel to zoom the diagram in or out.
This post is a step backwards from my last post which had some rudimentary elevation mapping. However, after deciding to try to make this into a full-blown terrain generator, I realized that going back and rearranging some stuff would be easier now than in the future. Going forward, I will try to post incremental changes to the terrain generator as they are implemented.
Download and extract the zip file, load wtgDemo.html in your browser to see it in action.
The code contains a lot of comments, so I hope it is easy to follow. Feel free to play around and use the code however you want.
cheers – Shri