WaveFunctionCollapse
WaveFunctionCollapse copied to clipboard
Generate from a pre-defined output image
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".
Hi! To constrain the output, you need to:
- Ban all unwanted options.
- Call
Propagate()
to propagate the bans.
For an example, see how I constrain ground pixels here.
Could you just explain the snippet of code you linked so that I can write my own?
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
.
- In the first interior
for
in the code, we ban all non-ground (that is,t != T-1
) patterns from the ground level. - 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.
Thanks, now I understand.