Show / Hide Table of Contents

Class VoxelMesher

This class manages a naive mesh for a voxel grid.

It can generate the naive mesh and can map any face index on the generated mesh to a voxel face. This is used by the tile map editor to select which voxel to fill/clear when clicking on the voxel grid. It can also be used at runtime to test for mouse clicks in a live level editor.

The generated meshes contain faces for each of the filled-to-unfilled surfaces in the grid, as well as walls surrounding the whole grid.

Inheritance
System.Object
VoxelMesher
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: CarbideFunction.Wildtile
Syntax
public class VoxelMesher

Properties

TempMeshInstance

Readonly access to the spawned GameObject.

Declaration
public GameObject TempMeshInstance { get; }
Property Value
Type Description
GameObject

Methods

ChangeMaterials(Material, Material)

Swap the materials of the surfaces in the already spawned GameObject.

Declaration
public void ChangeMaterials(Material material, Material wallsMaterial)
Parameters
Type Name Description
Material material
Material wallsMaterial

CreateAndGenerateMesh(VoxelGrid, Vector3, Vector3Int, Vector3Int)

Generates a simple mesh for the voxel grid, intended for use with level editors. It also populates trianglesToFaceDataToUpdate with information about which coordinate is behind the tile and which is in front of the tile, making it easier to add or remove tiles when you click on them.

The output includes two submeshes: Submesh zero holds the map's surface. Submesh one holds the map's boundary, facing inwards.

Declaration
public static VoxelMesher.GeneratedMesh CreateAndGenerateMesh(VoxelGrid map, Vector3 tileDimensions, Vector3Int editableAreaBias, Vector3Int editableAreaSize)
Parameters
Type Name Description
VoxelGrid map

A map of filled/empty cubes. This map's surface will be created and saved in the output meshToPopulate.

Vector3 tileDimensions

The size of a single cube. The mesh's points will be scaled to match, so the caller will not have to do any scaling afterwards.

Vector3Int editableAreaBias

The lower left corner of the area that will be meshed. This should be zero to create a mesh for the whole map. Accepts any value between 0 and the map's size in each vector component.

Vector3Int editableAreaSize

The size of the area that will be meshed, in each coordinate. This should be the map's dimensions for the whole map. Accepts any value between 0 and the map's size - editableAreaBias along each coordinate.

Returns
Type Description
VoxelMesher.GeneratedMesh

Returns the mesh and associated triangle data as a VoxelMesher.GeneratedMesh.

CreateMeshedVoxels(VoxelGrid, Vector3, Material, Material, Transform, Int32, Nullable<Vector3Int>, Nullable<Vector3Int>)

Immediately spawn a temporary mesh GameObject, create a mesh, and assign the mesh to the new GameObject

Declaration
public void CreateMeshedVoxels(VoxelGrid map, Vector3 tileDimensions, Material material, Material wallsMaterial, Transform targetTransform, int layerIndex, Vector3Int? editableAreaBias = null, Vector3Int? editableAreaSize = null)
Parameters
Type Name Description
VoxelGrid map
Vector3 tileDimensions
Material material
Material wallsMaterial
Transform targetTransform
System.Int32 layerIndex
System.Nullable<Vector3Int> editableAreaBias
System.Nullable<Vector3Int> editableAreaSize

DestroyMeshedVoxels()

Immediately destroy the spawned GameObject and release all references to the created mesh and creation data, allowing the C# GC to reclaim them.

Declaration
public void DestroyMeshedVoxels()

GetFaceDataForTriIndex(Int32)

Gets the VoxelMesher.FaceData for a triangle in the generated mesh. The mesh must have been generated first by calling RegenerateMeshedVoxels(VoxelGrid, Vector3, Nullable<Vector3Int>, Nullable<Vector3Int>).

The triangle index is expected to come from a physics raycast based on where the user clicks.

Declaration
public VoxelMesher.FaceData GetFaceDataForTriIndex(int triangleIndex)
Parameters
Type Name Description
System.Int32 triangleIndex
Returns
Type Description
VoxelMesher.FaceData

RegenerateMeshedVoxels(VoxelGrid, Vector3, Nullable<Vector3Int>, Nullable<Vector3Int>)

Recreate the mesh and apply it to the already spawned GameObject.

Declaration
public void RegenerateMeshedVoxels(VoxelGrid map, Vector3 tileDimensions, Vector3Int? editableAreaBias = null, Vector3Int? editableAreaSize = null)
Parameters
Type Name Description
VoxelGrid map
Vector3 tileDimensions
System.Nullable<Vector3Int> editableAreaBias
System.Nullable<Vector3Int> editableAreaSize
In This Article
Generated by DocFX Version: 4.1.0 - click to show/hide other versions