Skip to main content

Crate autotile

Crate autotile 

Source
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§

AutoPatternConstraint
A pair of an HashConstraintMap and an AutoTerrainPatternMap.
AutoTileContext
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 ProbabilitySet of tiles, representing how a tile should be randomly selected once a pattern is chosen.
AutoTiler
The object responsible for autotiling and owning a hash map were the result is stored.
ConstraintFillRules
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.
HashConstraintMap
A pattern source that is stored in a hash map.
HashWfcConstraint
An implementation for WfcConstrain that 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.
ListTerrain
An implementation of TileTerrain based upon a slice of patterns.
NeededTerrain
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.
PatternBits
PatternBits represents a tile’s pattern as a 3x3 grid of i8 values for doing autotiling in 2D with Vector2<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.
ProbabilitySet
A set of values of type V where 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.
Vector2Diagonal
An offset to move from a Vector2<i32> position to an diagonal Vector2<i32>.
Vector2Offset
An offset to move from a Vector2<i32> position to an adjacent Vector2<i32> in one of the four cardinal directions.
Vector2OffsetCounter
A WaveOffsetCounter for Vector3 offsets, containing 4 usize values, one for each adjacent cell of a pattern in 2D.
Vector3Diagonal
An offset to move from a Vector2<i32> position to an diagonal Vector2<i32>.
Vector3Offset
An offset to move from a Vector3<i32> position to an adjacent Vector3<i32> in one of the six cardinal directions.
Vector3OffsetCounter
A WaveOffsetCounter for Vector3 offsets, containing 6 usize values, 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 WfcConstrain object that contains the rules for which patterns may be chosen.

Enums§

TileConstraint
The ways in which a cell’s choice of tile can be constrained.
WfcControlFlow
Wave function collapse is a multi-step that may require a significant amount of time, depending on how may cells need to be filled. WfcControlFlow allows 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§

AutoConstrain
The contraints that control how the autotiler searches for tiles at each position.
OffsetPosition
Position types for tiles that provides abstract access to all of the position’s adjacent positions.
PatternSource
Trait for objects that represent a constraining environment for the autotiler. Given any position, a PatternSource object can supply a TileConstraint for that position. While a TerrainSource object alone may be enough to tell the autotiler what positions it needs to fill with tiles, a PatternSource can provide information about the neighboring tiles, and thus give the autotiler a complete picture of the environment it is tiling.
TerrainSource
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.
TilePattern
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.
TileTerrain
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.
WaveOffsetCounter
A trait for counting types that store a usize for each of the offsets from some OffsetPosition type. 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.
WavePosition
A WavePosition is like an OffsetPosition but it also has a counter type that the wave propagator can use to keep count of how many possible matching patterns are available from each Offset.
WfcConstrain
Trait for an object that specifies the rules by which wave function collapse tiles are chosen.

Type Aliases§

AutoPatternValueMap
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 ProbabilitySet that can be used to randomly select a tile based upon the relative frequency of each tile.
AutoTerrainPatternMap
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.