Jump to content

Procedural Towns


SpiderPig
 Share

Recommended Posts

Spent today refining an old class.

TownGeneration_003.thumb.png.f4fd95b94479ef9f802c638cb6883149.png

The above shot was generated procedurally from this JSON file.  Basically, towns can be created all over a terrain.  Each town is made up of districts which can be defined by vertices so can be any closed 2D shape.  Each district can hold properties which can also be any 2D shape.  Each property can have access points (the blue wireframe at some of the edges) and neighbouring properties are aligned to an edge and allow room for roads if that edge is an access point.  Then each property can be filled with a list of models.  Right now there's only one and it's placed at the centre of the property.  But once each model has a footprint calculated (probably from it's AABB) it can be placed randomly within a property.  Hopefully, creating some nice randomized towns.  With more defined shapes and models to place I think it'll look quite random.  I'm going to try and work on roads next, probably use some sort of mesh spline that weaves between the properties that have access points.  :)

{
	"towns":
	[
		{
			"name":"TownA",
			"min_radius":100,
			"max_radius":250,
			"min_height":0,
			"max_height":1000,
			"min_slope":0,
			"max_slope":90,
			"scatter":false,
			"districts":
			[
				{
					"name":"DistrictA",
					"enabled":true,
					"primary":true,
					"vertices":[[0,0,4],[29,0,4],[29,0,-6],[20,0,-14],[-7,0,-14],[-10,0,-10],[-6,0,0]],
					"edge_access":[false,false,false,false,false,false,false],
					"normal":[0.0,1.0,0.0],
					"scale":5.0,
					"path_width":4.0,
					"zone_buffer":0.25,
					"properties":	
					[
						{
							"name":"Zone1",
							"vertices":[[-1,0,-1],[-1,0,1],[0,0,1.5],[1,0,1],[1,0,-1]],
							"edge_access":[true,true,false,false, false],
							"scale":5.0
						},
						{
							"name":"Zone2",
							"vertices":[[-1,0,-1],[-1,0,1],[1,0,1],[1,0,-1]],
							"edge_access":[true,false,true,true,false],
							"scale":6.0
						}
					]
				}
			]
		}
	]
}

 

  • Like 1
Link to comment
Share on other sites

I think I've nearly got paths & roads working.  The answer was using A* pathfinding but stopping whenever it hit an existing path.  This way each access point will link up to an existing path.  The only problem I can see thus far is some paths are created parallel to each other when in reality they should merge to one or the other.  I'll have to experiment with some sort of neighbour check that will weight a path towards an existing one if it's close enough.  For now though I think it's time to get a spline mesh going.

TownGeneration_005.thumb.png.c72a624b6b2d42f430d1295ea2dbf4c7.png

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...