Skip to content

Swift triangular and hexagonal grid utility framework

License

Notifications You must be signed in to change notification settings

zilmarinen/Deltille

Repository files navigation

Platforms Swift 5.1 License

Deltille

Deltille is a utility framework designed to encapsulate the mathmatical principles and concepts of a coordinate system defined within a regular tiling of a triangular grid.

Installation

To install using Swift Package Manager, add this to the dependencies: section in your Package.swift file:

.package(url: "https://github.com/zilmarinen/Deltille.git", .upToNextMinor(from: "0.1.0")),

Dependencies

Euclid is a Swift library for creating and manipulating 3D geometry and is used extensively within this project for mesh generation and vector operations.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Implementation

Deltille is a lightweight wrapper for the base utility data structures required to get started working with triangular grids. By constraining triangles to a fixed Grid, it is possible to generate triangle vertices for any given Scale by leveraging the natural geometric properties of triangle subdivision.

Triangles

The basic building blocks of Deltille are both the Coordinate and Triangle types which are used together to model equilateral triangle vertex positions along a plane.

//create a triangle at the world origin
let triangle = Grid.Triangle(.zero)
    
//generate triangle vertices for the desired scale
let vertices = triangle.corners(for: .chunk)

Stencils

A Stencil can be used to subdivide a triangle into individual sub-triangles mapped to a specific grid scale.

//subdivide into stencil components
let stencil = triangle.stencil(for: .tile)
    
//grab the stencil center
let vertex = stencil.vertex(for: .center)

Footprints

A Footprint defines a collection of triangles centered around a given origin.

//define a collection of triangle coordinates
let septomino = Grid.Septomino.asterope
    
//create a footprint    
let footprint = Footprint(origin: .zero,
                          coordinates: septomino.coordinates)
    
//rotate footprint around its origin
let rotated = footprint.rotate(rotation: .clockwise)

Examples

Regolith makes usage of the concepts introduced by Deltille to generate meshes for predefined tessellations of a triangle interior using Ortho-Tiling.

Verdure implements additional mesh generation on top of Deltille to create stylised foliage canopies constrained to a triangular grid.

Credits

The Deltille framework is primarily the work of Zack Brown

Special thanks go to;

  • Boris the Brave for his extensive articles on grid systems, dual contouring, marching cubes, ortho-tiling and so much more.
  • Oskar Stalberg for inspiring posts on procedural generation and wave function collapse.
  • Amit Patel for stimulating deep dives into hexagonal grids, coordinate systems and grid edge classifications.