WAVE FUNCTION COLLAPSE 3D

A procedural structure generator in Unity that builds coherent 3D worlds from a set of labelled modules. It reads the geometry of each mesh, works out for itself which pieces can sit next to which, and collapses the possibilities into a structure that is different every run and never illegal.
The problem
Wave Function Collapse is only as good as its adjacency rules, and authoring those by hand is miserable — every new module means revisiting every rule you already wrote. The algorithm was never the hard part. The data entry was.
What I built
- Automatic socket detection. The tool inspects each 1×1×1 module mesh and derives its connection sockets from the geometry itself, so adjacency rules fall out of the models rather than a spreadsheet.
- Rotation handling. Every module is expanded into four rotational variants automatically, with naming conventions that keep flipped and symmetrical sockets matching correctly.
- A labelling tool. A dedicated
ModuleGeneratescene analyses meshes and writes out the module data, so adding a new piece is a one-click operation instead of a code change. - Weighted selection, so common pieces appear more often than rare ones and the output does not read as uniform noise.
- Progressive rendering, which draws the collapse step by step — as much a debugging tool as a visual one, since you can watch exactly where a generation goes wrong.
Tech
Unity 2021.3+, C#, Newtonsoft.Json for module data. Generation is driven by grid dimensions and a calculated initialise choice for edge modules.