Procedurally Connected Mesh/3d Model Tiles?

On a grid-based game, how would I procedurally determine adjacent objects (North, South,East, West) in an efficient manner?

I already have everything implemented from grid, to grid object placement, to actual object placement. Id like to implement this automatic system rather than having the player ie. select a corner for the building or sidewalk model

Below is a picture to better describe what Im trying to explain:

alt text

I have several 3d model variations of multiple objects from cliffs to paths/fences to buildings. Im aiming to allow players to place an object in runtime where if another of the same object is placed next to it, then depending on the direction a different mesh piece would replace the other.

Think of it as the Cliff system while making a map in starcraft 2 or warcraft 3.

alt text

(Place an object, in this case a cliff, then place another next to it and both will change where the left cliff would have no face on its right side and the right cliff would have nothing on its left face.)

Im trying to do this because allowing objects to simply overlap with one model rather than having multiple variations of the model with different faces not rendered is more ideal. Another example with exactly what I want:
alt text

(Web browser Version)

You have to implement your own tile identification logic. Each tile needs something that identifies it’s basic type, such as “hill”, “river”, “road” and so on. This can be done in several ways, for example a simple int where 0 is clear, 1 is ground, 2 is road, 3 is hill and so on. Or a string that directly describes the type. Or a enum value. Something like that.

Then, when building the mesh, you have to go through each tile, and for each tile, check it’s neighboring tiles for their type as well. Based on that information, your code can decide which mesh part to use for the current tile. For example, if the tile at x,y is a hill, and the tile at x+1,y (left neighbor) is ground/clear, then you need a cliff for the tile at x,y. It gets more complicated the more neighbors you have to take into account, of course.