A 3D procedural generation tool using the Wave Function Collapse algorithm, built with React Three Fiber and TypeScript.
This project implements the Wave Function Collapse (WFC) algorithm for procedural 3D world generation using modular 3D tiles with defined adjacency rules to generate coherent structures in a 3D world.
- 3D Wave Function Collapse algorithm β Generate 3D worlds using constraint-based tile placement
- Real-time Visualization β Watch the algorithm collapse cells step-by-step or run instantly
- Editor Mode β Browse, inspect and edit the result
- Custom Modules β Support for custom 3D models with adjacency rules defined in JSON
- Interactive Controls β Orbit, zoom, and explore generated worlds
- React Three Fiber β React renderer for Three.js
- Three.js β 3D graphics library
- TypeScript β Type-safe JavaScript
- Vite β Fast build tool
- Zustand β State management
- Node.js (v18+)
- npm or yarn
# Clone the repository
git clone <repository-url>
cd wave-function-collapse
# Install dependencies
npm install# Start the development server
npm run devOpen http://localhost:5173 to view the app in your browser.
# Build for production
npm run build- Click "Start WFC (instant)" to generate a world immediately
- Click "Start WFC (auto animated)" to watch the generation process
- Click "Start WFC (step by step)" to advance one step at a time
- Use "Reset WFC" to clear and start over
Toggle between WFC Mode and Editor Mode using the button in the top-left corner. Editor Mode allows you to browse all available prototype tiles.
src/
βββ WaveFunctionCollapseV2/ # Core WFC algorithm
β βββ Cell.ts # Cell state management
β βββ Map3D.ts # 3D grid structure
β βββ WaveFunctionCollapse.ts # Main WFC logic
β βββ Prototype/ # Tile prototype definitions
βββ World/ # 3D world rendering
βββ Editor/ # Editor mode components
βββ Resources/ # Providers and utilities
Custom 3D modules are stored in public/models/wfc_modules/:
wfc_modules.glbβ 3D model file containing all tile meshesprototype_data.jsonβ Adjacency rules and prototype definitions
MIT
