Need help with vertex-based tile terrain editing

Started by
0 comments, last by swiftcoder 8 years, 9 months ago

Hello folks. I'm creating a level editor within Unity3d for my project. The editor is inspired by Blizzard's World Editor used for Warcraft III. I understand that it's tile based and fairly certain that the individual tiles of the mesh are sharing vertices with neighbors. Correct me if I'm wrong.

I'm generating a grid mesh with x rows and y columns, see wireframe here: http://puu.sh/jaHYY/4385a6ae9a.png

I also have an alternate grid mesh that I thought make life easier though I no longer thing it's necessary, see here: http://puu.sh/jaI2G/442f0eb66b.png

First problem I'm having is applying UV's accordingly to get my base-layer default tiles to display nicely. I'm using a solution that just seems super wrong to me at the moment:

(x = row, y = column, this code is within an x/y iteration)


// Top of tile
if(y % 2 == 0)
{
	// Second vertex of top of tile
	if(x % 2 == 0)
	{
		uvs[i] = new Vector2(1, 1);
	}
	// First vertex of top of tile
	else
	{
		uvs[i] = new Vector2(0.51f, 1);
	}
}
// Bottom of tile
else
{
	// Second vertex of bottom of tile
	if (x % 2 == 0)
	{
		uvs[i] = new Vector2(1, 0.51f);
	}
	// First vertex of bottom of tile
	else
	{
		uvs[i] = new Vector2(0.51f, 0.51f);
	}
}

Doing this maps the uv coordinates to the top right portion of the texture for every tile in the mesh. I don't feel like this is the proper way to do it and the textures don't repeat nicely. Here's how it looks:

http://puu.sh/jaIqL/fb6222f22d.jpg

Applied texture:

http://puu.sh/jaIrj/938c079b00.jpg

Is there a better way to uv map my base layer? Ideally I would like to create an atlas containing multiple tile-textures that can be picked out and used for random individual tiles on the mesh.

My second problem is applying different textures atop the base layer positioned at vertices. I'm assuming this is going to involve multiple atlases and these optional atlases are going to have a at least one tile that is transparent for when the texture is not in use. Will these textures be applied on a separate UV layer of the mesh, and will I be able to set the uv coordinates of a single vertex on the mesh or will I need to alter the surrounding vertices as well?

Here's my shader: http://pastebin.com/Jh6vwDVZ

This is my first time working with shaders, and procedural meshes, so this is a little bit overwhelming. For an idea of what I'm trying to achieve please see here: https://vid.me/nVlf

If somebody could clear things up I'd appreciate it a lot, been hackin' at this for a while and I just can't wrap my head around it angry.png

Advertisement


fairly certain that the individual tiles of the mesh are sharing vertices with neighbors

I don't think they share vertices (at least in the general case). You need more flexibility during tile placement, so you are better off with separate vertices.

After all tiles placed, and you are ready to bake/export the map, you can always run an optimisation pass to get rid of any vertices that are actually duplicates.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement