Skip to content

action-script/ofxWFC3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wave Function Collapse

A C++ implementation of the Wave Function Collapse Tile-Model algorithm by @mxgmn ready for OpenFrameworks.

wfc_git_01

wfc_git_02

About

ofxWFC3D works in 3 dimensions, uses XML configuration files and outputs multiple formats such indices, ofNodes and key-value transformation tables.

It supports the original symmetry, rotations and subsets. It also implements new functionalities. The addon does not require any specific hardware or external libraries. It should work in every OF supported platform.

symmetry

symmetry

cardinality

The tiles placement and their neighbor relations are based its symmetry. Tiles rotates anticlockwise 90° on the Y axis.

symmetry 0 | 0° 1 | 90° 2 | 180° 3 | 270°
X x_0 x x x
T T_0 T_1 T_2 T_3
L L_0 L_1 L_2 L_3
I I_0 I_1 x x
\ d_0 d_1 x x
+ plus_0 plus_0 plus_0 plus_0

Usage

// instance the WFC3D
ofxWFC3D wfc;

// config_name, subset, x, y, z, periodic=false, ground_name="", surround_name=""
wfc.SetUp("data.xml", "default", width, height, length);

// run the WFC3D
// (the algorithm may runs into contradictions)
wfc.Run(seed);

// get a list of all the tiles transformations
ofNode world_node; // parent node
std::vector<ofNode> = wfc.getNodes(world_node, glm::vec3(size_x,size_y,size_z));

// get the indices of each tile based on the configuration
std::vector<size_t> modelIndices = wfc.getIndices();

Specific tiles instantiation

It reduces entropy and limits randomness creating predictable results.

// instanciate an specific tile on the WFC
wfc.SetTile("tile", x, y, z); 

Special features

+ symmetry

This version of the WFC, includes tiles without symmetry. The "+" symmetry actually does not perform any symmetry, instead uses only rotations and has 4 unique anchor points.

For complex structures that require a very concrete tile union, use the symmetry type "+".

<tile name="corner" symmetry="+"/>

Height range

The "min-height" and "max-height" attributes defined the height range where a tile can be placed.

<tile name="roof" symmetry="I" min-height="2" max-height="4"/>

Axis and coordinate origin

ofxWFC3D has a different axis coordinate, being Y-up and Z-forward. That is what OF uses as well. This changes does not only changes the output, it does also affects the configuration and the way the wave propagates and its observed.

Performance

Example basic

// OF 0.10.1 - Arch-Linux | i7-6500U

| Process	| Microsecond   | Attempts  |
| ------------- | ------------- | --------- |
| SetUp		| 3204          | 1         |
| SetUp		| 1452          | 1         |
| SetUp		| 1438          | 1         |
| SetUp		| 451           | 1         |
| Run		| 140883        | 1         |
| Run		| 142980        | 1         |
| Run		| 134868        | 1         |
| Run		| 117848        | 1         |

Example advance

// OF 0.10.1 - Arch-Linux | i7-6500U

| Process	| Microsecond   | Attempts  |
| ------------- | ------------- | --------- |
| SetUp		| 2520          | 1         |
| SetUp		| 2025          | 1         |
| SetUp		| 1463          | 1         |
| SetUp		| 526           | 1         |
| Run		| 59608         | 3         | 2 contradictions
| Run		| 60894         | 4         | 3 contradictions
| Run		| 75666         | 3         | 2 contradictions
| Run		| 64881         | 1         |
| Run		| 69637         | 2         | 1 contradiction

License

ofxWFC3D is distributed under the MIT License.

About

Wave Function Collapse 3D | openFrameworks Addon

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published