WaveFunctionCollapse icon indicating copy to clipboard operation
WaveFunctionCollapse copied to clipboard

Generate from a pre-defined output image

Open SKFrozenCloud opened this issue 1 year ago • 4 comments

Hi,

I'm trying to implement a way to give the algorithm a pre-defined output image containing fixed (already put in place) tiles (in overlap mode).

I do not understand the code very well but I have some ideas.

So on this line the output image is created: https://github.com/mxgmn/WaveFunctionCollapse/blob/a6f79f0f1a4220406220782b71d3fcc73a24a4c2/OverlappingModel.cs#L116 Is it possible to fill the observed array with our pre-defined image (before running the algorithm)? What does the array observed do? Another option would be to put it in inside the init or observer function.

EDIT:

My use-case is specifying an output image where the border is filled with "water" so that you can guarantee that the algorithm always generates "islands". Same goes with "rooms".

SKFrozenCloud avatar Jun 20 '23 07:06 SKFrozenCloud

Hi! To constrain the output, you need to:

  1. Ban all unwanted options.
  2. Call Propagate() to propagate the bans.

For an example, see how I constrain ground pixels here.

mxgmn avatar Jun 22 '23 13:06 mxgmn

Could you just explain the snippet of code you linked so that I can write my own?

SKFrozenCloud avatar Jun 23 '23 06:06 SKFrozenCloud

Sure!

if (ground)
{
    for (int x = 0; x < MX; x++)
    {
        for (int t = 0; t < T - 1; t++) Ban(x + (MY - 1) * MX, t);
        for (int y = 0; y < MY - 1; y++) Ban(x + y * MX, T - 1);
    }
    Propagate();
}

This code executes in examples where we need to fix the ground level. That is, in examples like Skyline, Flowers and Platformer, where we see the picture from the side and not from the top. If we omit this code, the ground level could appear anywhere in the output (like in the middle of an image), or there could even be multiple ground levels. Try changing to ground="False" in samples.xml and see what happens.

Ground pattern is the last pattern in the input, so its index equals T-1.

  1. In the first interior for in the code, we ban all non-ground (that is, t != T-1) patterns from the ground level.
  2. In the second for, we ban the ground pattern from non-ground (that is, y != MY-1) levels.

And then we propagate the bans.

In your example, to generate islands, you need to ban all non-water patterns from the border of the image, and then propagate.

I guess I'll reopen the issue because this is a common question.

mxgmn avatar Jun 23 '23 12:06 mxgmn

Thanks, now I understand.

SKFrozenCloud avatar Jun 23 '23 16:06 SKFrozenCloud