PlanarLazyMeshGrid
Quick facts | |
---|---|
Grid | PlanarLazyMeshGrid |
CellType | NGonCellType* |
CellDir | CellDir* |
CellRotation | CellRotation* |
Bound | SquareBound |
Properties | 2d, Planar, Infinite |
*NGonCellType represents any polygon. But for 4 and 6 sided faces, the values overlap with SquareCellType and HexCellType, and the corresponding SquareDir, SquareRotation, PTHexDir, HexRotation. |
PlanarLazyMeshGrid is a variant of PeriodicPlanarMeshGrid. While PeriodicPlanarMeshGrid takes a single mesh, and repeats it over the plane, instead PlanarLazyMeshGrid uses a different mesh at each position, called a chunk, stitching them all together.
To do so, you must supply a function that builds each of the meshes for the chunk, and give some information about the placement of each mesh, which must be periodic. PlanarLazyMeshGrid will invoke the function as necessary (i.e. lazily) and store the results, stitching together the meshes into a single grid.
Constructor
The constructor for PlanarLazyMeshGrid is somewhat complicated, you may wish to use the alternative constructors further below.
public PlanarLazyMeshGrid(Func<Vector2Int, MeshData> getMeshData, Vector2 strideX, Vector2 strideY, Vector2 aabbBottomLeft, Vector2 aabbSize, MeshGridOptions meshGridOptions = null, SquareBound bound = null, IEnumerable<ICellType> cellTypes = null, ICachePolicy cachePolicy = null)
The arguments are
getMeshData
- GetsMeshData
for a given chunk.strideX
/strideY
- Function as in PeriodicPlanarMeshGrid, these describe the distance between meshes.aabbBottomLeft
,aabbSize
- These give constant bounds on the output ofgetMeshData(new Vector2Int(0, 0))
, and similarly for other chunks, translated by strideX/strideY. The aabb's of chunks may overlap.MeshGridOptions
- as documented in MeshGridbound
- the bounds to restrict this grid to. This restricts which chunks are generated, there's no bounds within-chunks.cellTypes
- the value to output forIGrid.GetCellTypes
cachePolicy
- see caching.
Alternative constructor
To make it easier to work with, there are alternative constructors for common periodic spacing:
public PlanarLazyMeshGrid(Func<Cell, MeshData> getMeshData, HexGrid chunkGrid, float margin = 0.0f, MeshGridOptions meshGridOptions = null, SquareBound bound = null, IEnumerable<ICellType> cellTypes = null, ICachePolicy cachePolicy = null)
public PlanarLazyMeshGrid(Func<Cell, MeshData> getMeshData, SquareGrid chunkGrid, float margin = 0.0f, MeshGridOptions meshGridOptions = null, SquareBound bound = null, IEnumerable<ICellType> cellTypes = null, ICachePolicy cachePolicy = null)
Here, each mesh is expected to fill a single cell of chunkGrid
. getMeshData
takes a Cell
argument naming the cell to be filled. margin
allows the meshes to go outside the bounds of the cell by a fixed amount. Other arguments work the same.
Cell co-ordinates
The x value indicates the face in the mesh, and the y and z values indicate the multiple of stride moved in the two directions.