Code Monkey home page Code Monkey logo

wfcproceduralgenerationtool's Introduction

WfcProceduralGenerationTool

Description

This is my final project for university. I chose to develop it when I found out Maxim Gumin's Wave Function Collapse, I thought it was such a cool algorithm and couldn't take it out of my head :D.

The project consist of my own implementation of a tile-based WFC generator, with a strong focus of making it as generalist as possible, and a custom editor in order to handle tilemap manipulation and to facilitate the interaction with the algorithm. The idea is that anyone can model a tileset on any 3D mesh modeling software and use this to generate tile-based levels/maps with WFC.

generation example

The WFC Overlapping model was chosen because of its flexibility and minimal user input, since the tile adjacencies can be extracted from an sample map, instead of having to manually declare each one by hand.

Another great functionality that WFC supports and has been implemented is being able to autocomplete maps:

autocomplete

Table of contents

  1. Description
  2. Table of contents
  3. How to use
  4. Implementation Details
    1. Tileset
    2. WfcGenerator

How to use

The generator and the tool itself are two separate monobehaviours (WfcGenerator and WfcInterface), in case of needing just the generator but not the functionality of editing the input/output tilemaps.

To experiment with the tool you can just attach the WfcInterface script to an emtpy GameObject. In order to use the generator you must create your TileSet first, where you define the tile meshes and materials that you're goint to use. Then you can create your own Tilemap with your tiles from the scene window on editor mode. On the WfcInterface Inspector window the option to serialize and load already serialized input tilemaps is available.

Having an input map created (either making it by hand or loading a serialized one) you can then start generating output maps with the button on the editor, you can tweak parameters to change the behaviour of the WFC generation from the WfcGenerator and WfcInterface inspector window.

Example with two generations with the same input tilemap and parameters except for patternSize:

patternSize == 2 patternSize == 3
PatternSize2 PatternSize3

Implementation Details

Tileset and TileAttributes

A TileSet is a scriptable object with essentially just a list of TileAttributes. You should be able to create one right-clicking on the project window and navigating to Create>ScriptableObjects>TileSet.

TileAttributes is a struct that contains the Mesh, Material and SymmetryType of every Tile. The SymmetryType is an important attribute to get right for your tiles if you want to use the pattern rotation or reflection parameters to generate maps, undesired generation results are expected if your tiles are not correctly classified with their respective symmetry type, check Wave Function Collapse original repo for an explanation of tile symmetries.

Here's the two simple tilesets I've made:

testTileSet islandTileSet
TestTileset IslandTileset

Tilemap

A Tilemap basically contains a flattened array of encoded tiles as integers. It must not be confused with SerializableTilemap which is just a ScriptableObject wrapper for serializing input tilemaps from the WfcInterface inspector window.

In the following pic there are two tilemaps, the input map made by hand (small one) and the generated output map (the bigger one):

IslandMap

WfcGenerator

WfcGenerator was separated from the interface just in case it needs to be used to generate using already serialized input tilemaps, for example to use as a level generator.

There's a code functionality not reflected on the editor tool that allows you to save generated maps as meshes but its not that well written and the meshes are unoptimized.

wfcproceduralgenerationtool's People

Contributors

envialon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.