Created
August 29, 2023 00:01
-
-
Save PaperPrototype/8333a7eb03818bc3b7a120e2c3516931 to your computer and use it in GitHub Desktop.
Voxel tables for making voxel mesh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using Unity.Mathematics; | |
using UnityEngine; | |
public static class VoxelTables | |
{ | |
// all 8 possible vertices for a voxel | |
public static readonly Vector3[] Vertices = new Vector3[8] | |
{ | |
new Vector3(0.0f, 0.0f, 0.0f), | |
new Vector3(1.0f, 0.0f, 0.0f), | |
new Vector3(1.0f, 1.0f, 0.0f), | |
new Vector3(0.0f, 1.0f, 0.0f), | |
new Vector3(0.0f, 0.0f, 1.0f), | |
new Vector3(1.0f, 0.0f, 1.0f), | |
new Vector3(1.0f, 1.0f, 1.0f), | |
new Vector3(0.0f, 1.0f, 1.0f), | |
}; | |
// vertices to build a quad for each side of a voxel | |
public static readonly int[,] QuadVerticesIndex = new int[6, 4] | |
{ | |
// quad order | |
// right, left, up, down, front, back | |
// 0 1 2 2 1 3 <- triangle numbers | |
// quads | |
{1, 2, 5, 6}, // right quad | |
{4, 7, 0, 3}, // left quad | |
{3, 7, 2, 6}, // up quad | |
{1, 5, 0, 4}, // down quad | |
{5, 6, 4, 7}, // front quad | |
{0, 3, 1, 2}, // back quad | |
}; | |
// offset to neighboring voxel position | |
public static readonly int3[] VoxelNeighborOffsets = new int3[6] | |
{ | |
new int3( 1, 0, 0), // right | |
new int3(-1, 0, 0), // left | |
new int3( 0, 1, 0), // up | |
new int3( 0, -1, 0), // down | |
new int3( 0, 0, 1), // front | |
new int3( 0, 0, -1), // back | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment