This is a simple C++17 implementation of the Wave Function Collapse algorithm including a rudementary test UI.
It does not contain any extensions such as overlapped WFC.
The WFC code is not tied to the UI code and can be easily recycled in other projects.
// set up your tiles and how they are compatible to each other first
std::vector<Tile> tiles;
// configure a grid
Grid grid(64, 64, tiles);
// set up a callback if you want to see in realtime which slots in your grid are collapsed
grid._tile_collapsed_callback = [](const Vector2D& pos, int32_t index)
{
// ...
};
// start the execution, ideally do this in another thread
grid.run();
// read the grid data and pass it to your UI
ui->_tile_grid->setGrid(grid._size, grid.readGrid());
- Load a texture
- Select a tile on the left tileset
- Select a direction (N, E, S, W) where you want to configure compatible tiles
- Select compatible tiles on the right tileset
- Repeat steps 2-4 until you've configured all your tile dependencies
- Select a grid size
- Hit 'Generate'