Creating points between all territories

I’ve converted our world map to reflect that which Europa Universales 4 uses (shown above) as a back end and was able to implement using GetPixel to detect the clicked pixel of the Texture2D at runtime.

Next is we somehow need to generate points between all the territories to create borders like these:
http://www.strategygamer.com/assets/BlogPosts/Europa-Universalis-IV-Common-Sense-Review-PC-483884-8.jpg

I’ve created some mock tests with LineRenderer and textures and it looks exactly as it should, but I’m looking for a way to automatically generate the points somehow and make them belong to a territory.

Any ideas how to traverse the texture and generate points to use for shared borders and know what territories they belong to?

As an end result I was thinking it would be a Dictionary<Territory, List> or something to traverse to draw line renderers for each territory. This also needs to know what points are shared with other territories so that if owned by the enemy it draws a different style of border than a single black one.

You have an image with different colors for each territory so you could just do some pixel lookups to create your data.

For example a simple algorithm I can think of right now would be:

  1. Start with any country and get the color of it by taking the color of any pixel in it.

  2. From this starting pixel check every neighbouring pixel recursively (and remember which you have checked so you never check the same twice) until you encounter a pixel of a different color (or have no more pixels to check).

  3. When you encounter a pixel of a different color (you reached a neighbouring country’s pixel) then don’t check that pixel recursively but instead go back to the pixel you came from and mark it as a border pixel to that country color .

  4. In the end of the recursion (when there are no more pixels to you will have saved all pixels that borders to other countries and you will have marked which country (color) each of these border pixels are bordering to (for example by putting the border pixels positions in a list, one list for each neighbouring country)

  5. To make ordered point lists from the pixel lists you could just start with any pixel in the border list and check which of the other pixels in the list are neighbouring to this pixel (so only the neighbours that are marked as border pixels are valid neighbours), then choose any of those pixels and recuirsively check it the same way for neighbouring pixels (without checking the same pixel twice) and saving it as the next point in the list. In the end you should have an ordered list of points that you can draw lines between.

  6. Repeat steps 1-5 for all other countries.

Thanks eXonius this helped break it down a bit better. I was trying to step through how to iterate all the pixels… top down, left right etc and nothing made sense. Iterating the entire texture to find a starting pixel per RGB to find a starting point for every territory isn’t something that crossed my mind and sounds good.

This does seem suitable to end up with a list of edge pixels per territory and tracking pixel neighbors, but how do you then convert them to world space points?

To convert a pixel coordinate to a world coordinate you could just put it in a vector like this:

Vector3 worldPoint = new Vector3((float)pixel.x, 0.0f, (float)pixel.y);

Alternatively add a scale value:

float scale = 1.0f;
Vector3 worldPoint = new Vector3(scalepixel.x, 0.0f, scalepixel.y);

Also since there’s quite a bit of noise in the image with for example blue spots in the middle of some countries you need to find a way to tell your algorithm to ignore these pixels.

Yea understood, mine doesn’t have water territories so will be easier. Thanks man.