Skip to content

Sighr/WFCHexGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WFC Hex Grid Generator

A pet project aimed to explore the Wave Function Collapse (WFC) algorithm applied to a hexagonal grid, dynamic linking application and low-level rendering.

Overview

This is a project developed to experiment with several concepts:

  • Procedural Generation: Implementation of the Wave Function Collapse algorithm for generating consistent hexagonal maps based on adjacency rules.
  • Dynamic Linking: The core generation logic is compiled into a dynamic library (.dll), which is loaded at runtime by the main application using Windows API (LoadLibrary, GetProcAddress).
  • Low-Level Rendering: A dedicated debug visualizer built with bgfx to render the generated hex grids.

Tech Stack & Libraries

  • Language: C++20
  • Build System: CMake
  • Libraries:
    • bgfx: A cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
    • GLFW: A multi-platform library for OpenGL, OpenGL ES, Vulkan development on the desktop.
    • tinyxml2: A tiny, simple, C++ XML parser.

Visualization

Generated Grid

Project Structure

  • library/: The core WFC logic, compiled as a dll.
  • mainApp/: A simple host application to dynamically load the generator library with sample arguments.
  • debugVisualiser/: A bgfx-based tool for visualizing the generation results.
  • tinyxml2/: XML parsing for configuration and tile data.

Building

The project uses CMake and expects bgfx, glfw and opengl to be available on the system. The definitions for the libraries should be passed as CMake arguments.

  1. Configure the project: cmake . -DBGFX_DIR=path/to/bgfx/root -DBGFX_LIB_DIR=path/to/bgfx/libs -DGLFW_DIR=path/to/glfw/root -DGLFW_LIB_DIR=path/to/glfw/libs Make sure that bgfx has shaderc support enabled.
  2. Build the project. There are several targets available:
  • WFCHexGeneratorLib: The WFC library.
  • WFCHexGenerator: The library accessor. The default files are config.xml and output.xml.
  • bgfxdebugvisualiser: A bgfx-based tool for visualizing the generation results. Accepts the xml filename argument to visualize a specific map.
  • cleanShaders and compileShaders: Utility targets for the shader files.

Limitations

  • The algorithm currently supports only adjacency rules. A sample configuration can be found in config.xml.
  • While the types of the tiles are configurable, the visualiser supports only the types listed in the sample config. See debugVisualiser/hexConfigLoader.cpp for color mapping.
  • For the large maps, the visualiser may not show all the tiles due to the camera being static and no controls or position/angle adjustments. See debugVisualiser/Simple2DHexGridDrawer.cpp, specifically bx::mtxLookAt for camera position.

About

A pet project to learn dynamic linking and rendering

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages