Show / Hide Table of Contents

Class TesseraGenerator

GameObjects with this behaviour contain utilities to generate tile based levels using Wave Function Collapse (WFC). Call Generate(TesseraGenerateOptions) or StartGenerate(TesseraGenerateOptions) to run. The generation takes the following steps:

  • Inspect the tiles in tiles and work out how they rotate and connect to each other.
  • Setup any initial constraints that fix parts of the generation (initialConstraints).
  • Fix the boundary of the generation if skyBox is set.
  • Generate a set of tile instances that fits the above tiles and constraints.
  • Optionally retries or backtrack.
  • Instantiates the tile instances.
Inheritance
Object
TesseraGenerator
Namespace: Tessera
Assembly: cs.temp.dll.dll
Syntax
public class TesseraGenerator : MonoBehaviour

Fields

algorithm

Controls the algorithm used internally for Wave Function Collapse.

Declaration
public TesseraWfcAlgorithm algorithm
Field Value
Type Description
TesseraWfcAlgorithm

backtrack

If set, backtracking will be used during generation. Backtracking can find solutions that would otherwise be failures, but can take a long time.

Declaration
public bool backtrack
Field Value
Type Description
Boolean

contradictionTile

Game object to show in cells that cannot be solved.

Declaration
public GameObject contradictionTile
Field Value
Type Description
GameObject

failureMode

Controls what is output when the generation fails.

Declaration
public FailureMode failureMode
Field Value
Type Description
FailureMode

filterSurfaceSubmeshTiles

If true, and a surfaceMesh is set with multiple submeshes (materials), then use surfaceSubmeshTiles.

Declaration
public bool filterSurfaceSubmeshTiles
Field Value
Type Description
Boolean

modelType

Sets which sort of model the generator uses. The model dictates how nearby tiles relate to each other.

Declaration
public ModelType modelType
Field Value
Type Description
ModelType

overlapSize

The size of the overlap parameter for the overlapping model. Overlapping

Declaration
public Vector3Int overlapSize
Field Value
Type Description
Vector3Int

recordUndo

Records undo/redo when run by pressing the Generate button in the Inspector.

Declaration
public bool recordUndo
Field Value
Type Description
Boolean

retries

If backtracking is off, how many times to retry generation if a solution cannot be found.

Declaration
public int retries
Field Value
Type Description
Int32

samples

For overlapping models, a list of objects to use as input samples. Each one will have its children inspected and read out. Overlapping

Declaration
public List<GameObject> samples
Field Value
Type Description
List<GameObject>

scaleUncertainyTile

If true, the uncertainty tiles shrink as the solver gets more certain.

Declaration
public bool scaleUncertainyTile
Field Value
Type Description
Boolean

searchInitialConstraints

If true, then active tiles in the scene will be taken as initial constraints. If false, then no initial constraints are used. Using initialConstraints overrides either outcome.

Declaration
public bool searchInitialConstraints
Field Value
Type Description
Boolean

seed

Fixes the seed for random number generator. If the value is zero, the seed is taken from Unity.Random

Declaration
public int seed
Field Value
Type Description
Int32

skyBox

If set, this tile is used to define extra initial constraints for the boundary.

Declaration
public TesseraTileBase skyBox
Field Value
Type Description
TesseraTileBase

stepLimit

How many steps to take before retrying from the start.

Declaration
public int stepLimit
Field Value
Type Description
Int32

surfaceMesh

If set, then tiles are generated on the surface of this mesh instead of a regular grid.

Declaration
public Mesh surfaceMesh
Field Value
Type Description
Mesh

surfaceOffset

Height above the surface mesh that the bottom layer of tiles is generated at.

Declaration
public float surfaceOffset
Field Value
Type Description
Single

surfaceSmoothNormals

Controls how normals are treated for meshes deformed to fit the surfaceMesh.

Declaration
public bool surfaceSmoothNormals
Field Value
Type Description
Boolean

surfaceSubmeshTiles

A list of tiles to filter each submesh of surfaceMesh to. Ignored unless filterSurfaceSubmeshTiles is true.

Declaration
public List<TileList> surfaceSubmeshTiles
Field Value
Type Description
List<TileList>

tiles

The list of tiles eligible for generation.

Declaration
public List<TileEntry> tiles
Field Value
Type Description
List<TileEntry>

tileSize

The stride between each cell in the generation. "big" tiles may occupy a multiple of this tile size.

Declaration
public Vector3 tileSize
Field Value
Type Description
Vector3

uncertaintyTile

Game object to show in cells that have yet to be fully solved.

Declaration
public GameObject uncertaintyTile
Field Value
Type Description
GameObject

Properties

bounds

The area of generation. Setting this will cause the size to be rounded to a multiple of tileSize

Declaration
public Bounds bounds { get; set; }
Property Value
Type Description
Bounds

CellType

Indicates the cell type of the tiles set up.

Declaration
public ICellType CellType { get; }
Property Value
Type Description
ICellType

center

The local position of the center of the area to generate.

Declaration
public Vector3 center { get; set; }
Property Value
Type Description
Vector3

origin

Declaration
public Vector3 origin { get; set; }
Property Value
Type Description
Vector3

palette

Inherited from the first tile in tiles.

Declaration
public TesseraPalette palette { get; }
Property Value
Type Description
TesseraPalette

size

The size of the generator area, counting in cells each of size tileSize.

Declaration
public Vector3Int size { get; set; }
Property Value
Type Description
Vector3Int

Methods

Clear()

Clears previously generated content.

Declaration
public void Clear()

Generate(TesseraGenerateOptions)

Synchronously runs the generation process described in the class docs.

Declaration
public TesseraCompletion Generate(TesseraGenerateOptions options = null)
Parameters
Type Name Description
TesseraGenerateOptions options
Returns
Type Description
TesseraCompletion

GetCellTypes()

For validation purposes

Declaration
public IList<ICellType> GetCellTypes()
Returns
Type Description
IList<ICellType>

GetInitialConstraintBuilder()

Declaration
public TesseraInitialConstraintBuilder GetInitialConstraintBuilder()
Returns
Type Description
TesseraInitialConstraintBuilder

GetMissizedTiles()

For validation purposes

Declaration
public IEnumerable<TesseraTileBase> GetMissizedTiles()
Returns
Type Description
IEnumerable<TesseraTileBase>

GetTileOutput(Boolean)

Declaration
public ITesseraTileOutput GetTileOutput(bool forceIncremental = false)
Parameters
Type Name Description
Boolean forceIncremental
Returns
Type Description
ITesseraTileOutput

Instantiate(TesseraTileInstance, Transform)

Utility function that instantiates a tile instance in the scene. This is the default function used when you do not pass onCreate to the Generate method. It is essentially the same as Unity's normal Instantiate method with extra features:

  • respects instantiateChildrenOnly
  • applies mesh transformations (Pro only)
Declaration
public static GameObject[] Instantiate(TesseraTileInstance instance, Transform parent)
Parameters
Type Name Description
TesseraTileInstance instance

The instance being created.

Transform parent

The game object to parent the new game object to. This does not affect the world position of the instance

Returns
Type Description
GameObject[]

The game objects created.

Instantiate(TesseraTileInstance, Transform, GameObject, Boolean)

Utility function that instantiates a tile instance in the scene. This is the default function used when you do not pass onCreate to the Generate method. It is essentially the same as Unity's normal Instantiate method with extra features:

  • respects instantiateChildrenOnly
  • applies mesh transformations (Pro only)
Declaration
public static GameObject[] Instantiate(TesseraTileInstance instance, Transform parent, GameObject gameObject, bool instantiateChildrenOnly)
Parameters
Type Name Description
TesseraTileInstance instance

The instance being created.

Transform parent

The game object to parent the new game object to. This does not affect the world position of the instance

GameObject gameObject

The game object to actually instantiate

Boolean instantiateChildrenOnly

Should gameObject be created, or just it's children.

Returns
Type Description
GameObject[]

The game objects created.

Regenerate(TesseraGenerateOptions)

Runs Clear, then Generate

Declaration
public TesseraCompletion Regenerate(TesseraGenerateOptions options = null)
Parameters
Type Name Description
TesseraGenerateOptions options
Returns
Type Description
TesseraCompletion

StartGenerate(TesseraGenerateOptions)

Asynchronously runs the generation process described in the class docs, for use with StartCoroutine.

Declaration
public EnumeratorWithResult<TesseraCompletion> StartGenerate(TesseraGenerateOptions options = null)
Parameters
Type Name Description
TesseraGenerateOptions options
Returns
Type Description
EnumeratorWithResult<TesseraCompletion>
Remarks

The default instantiation is still synchronous, so this can still cause frame glitches unless you override onCreate.

Back to top Generated by DocFX