Created
August 28, 2023 22:21
-
-
Save PaperPrototype/fd20a2e099be33c894049da0b89ccaf6 to your computer and use it in GitHub Desktop.
Lookup tables for voxel terrain
This file contains 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 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 | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment