Expand description
Autotiling allows you to fill the content of a grid according to pre-defined rules. Tiles are assigned frequencies and adjacency rules, and then an algorithm is used to attempt to fill a given area with tiles in accordance with the rules and frequencies.
This library supports both deterministic autotiling and wave function collapse. Deterministic autotiling tries to find the particular tile that the user wants based upon giving specification for the purpose of streamlining creating tile-based art. Wave function collapse is a process of automatically generating random content where the algorithm is giving freedom to choose whatever tiles it likes within the limits of the adjacency rules.
The autotiling algorithm is based upon Terrain Autotiler.
The wave function collapse algorith is based upon fast-wfc.
Structs§
- Auto
Pattern Constraint - A pair of an
HashConstraintMapand anAutoTerrainPatternMap. - Auto
Tile Context - This contains the background information required for autotiling
independent of the particular cells to be filled, so it can be used
for multiple autotiling tasks. It contains a hash map from terrain
values to lists of patterns, representing both the patterns contained
within each terrain and the order in which the patterns should be examined.
It also contains and a hash map from patterns to a
ProbabilitySetof tiles, representing how a tile should be randomly selected once a pattern is chosen. - Auto
Tiler - The object responsible for autotiling and owning a hash map were the result is stored.
- Constraint
Fill Rules - When a cell is autotiled it may be desired that adjacent cells should be modified to fit with the new terrain of this cell. This object specifies whether that should be done. Cells that are added this way keep their current terrain, but their pattern may change.
- Hash
Constraint Map - A pattern source that is stored in a hash map.
- Hash
WfcConstraint - An implementation for
WfcConstrainthat stores the information for each pattern in a hash table and also keeps track of a which values each pattern may represent, so that patterns may be translated into tiles after wave function collapse is complete. - List
Terrain - An implementation of
TileTerrainbased upon a slice of patterns. - Needed
Terrain - This represents a cell that needs to be autotiled, including its position, its terrain, and the rules for what to do with the surrounding tiles.
- Pattern
Bits PatternBitsrepresents a tile’s pattern as a 3x3 grid ofi8values for doing autotiling in 2D withVector2<i32>positions. The center of the 3x3 grid is called the pattern’s terrain. The 8 values around the outside of the grid are called the pattern’s peering bits.- Probability
Set - A set of values of type
Vwhere each value is associated with a frequency so that a value can be chosen from the set at random with the probability of each value weighted by its frequency. - Vector2
Diagonal - An offset to move from a
Vector2<i32>position to an diagonalVector2<i32>. - Vector2
Offset - An offset to move from a
Vector2<i32>position to an adjacentVector2<i32>in one of the four cardinal directions. - Vector2
Offset Counter - A
WaveOffsetCounterforVector3offsets, containing 4usizevalues, one for each adjacent cell of a pattern in 2D. - Vector3
Diagonal - An offset to move from a
Vector2<i32>position to an diagonalVector2<i32>. - Vector3
Offset - An offset to move from a
Vector3<i32>position to an adjacentVector3<i32>in one of the six cardinal directions. - Vector3
Offset Counter - A
WaveOffsetCounterforVector3offsets, containing 6usizevalues, one for each adjacent cell of a pattern in 3D. - WfcFailure
- Wave function collapse failed to find a solution. Due to the randomization of the algorithm, a failed attempt does not necessarily indicate a problem, but may instead be due to chance. Another attempt my succeed where a previous one failed.
- WfcPropagator
- The propagator is responsible for the wave function collapse algorithm and
it contains all the necessary data except for the
WfcConstrainobject that contains the rules for which patterns may be chosen.
Enums§
- Tile
Constraint - The ways in which a cell’s choice of tile can be constrained.
- WfcControl
Flow - Wave function collapse is a multi-step that may require a significant amount of time,
depending on how may cells need to be filled.
WfcControlFlowallows wave propagation methods to specify in their return value whether they have completed their task or whether further work is required. This allows the user to spread the wave function collapse across multiple method calls so it can be mixed with other work or even aborted.
Traits§
- Auto
Constrain - The contraints that control how the autotiler searches for tiles at each position.
- Offset
Position - Position types for tiles that provides abstract access to all of the position’s adjacent positions.
- Pattern
Source - Trait for objects that represent a constraining environment for the autotiler.
Given any position, a
PatternSourceobject can supply aTileConstraintfor that position. While aTerrainSourceobject alone may be enough to tell the autotiler what positions it needs to fill with tiles, aPatternSourcecan provide information about the neighboring tiles, and thus give the autotiler a complete picture of the environment it is tiling. - Terrain
Source - Trait for objects that represent a particular autotiling problem to be solved, with a set of positions that need tiles and a terrain for each position to control which tiles are valid.
- Tile
Pattern - For the purposes of autotiling, tiles are represented by patterns that hold the data which determines whether two tiles are permitted to appear adjacent to each other. Therefore autotile algorithms place patterns rather than tiles, and translating those patterns into actual tiles is a later step.
- Tile
Terrain - For autotiling, tiles are grouped into patterns, and patterns are grouped into terrains. Each cell that is to be autotiled is given a terrain, and the autotiler must choose a pattern from within that terrain.
- Wave
Offset Counter - A trait for counting types that store a
usizefor each of the offsets from someOffsetPositiontype. During the wave function collapse process, these counts can be reduced as adjacent patterns possibilities are removed so that the algorithm can keep track of how many ways a pattern is possible. For a pattern to be possible, it must match some possible pattern in all offsets, so if any of these counts become 0 the algorithm will know to remove the corresponding pattern. - Wave
Position - A
WavePositionis like anOffsetPositionbut it also has a counter type that the wave propagator can use to keep count of how many possible matching patterns are available from eachOffset. - WfcConstrain
- Trait for an object that specifies the rules by which wave function collapse tiles are chosen.
Type Aliases§
- Auto
Pattern Value Map - A hash map from patterns to tiles. It is possible for multiple tiles to share
the same pattern, and in that case there is no way for the autotiler to deterministically
choose a tile. This map gives each pattern a
ProbabilitySetthat can be used to randomly select a tile based upon the relative frequency of each tile. - Auto
Terrain Pattern Map - A hash map from terrain values to lists of patterns. Each pattern has a terrain, and this map is used to list all of the patterns for a given terrain id value in the order of priority. If multiple patterns in the list may be chosen for some cell, the pattern nearest the front of the list should be chosen.