Jump to content
  • Advertisement
Sign in to follow this  
Jak3

Unity Need help with vertex-based tile terrain editing

This topic is 1240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!