Chunk Class for Unity Voxel Engine (Example)

Here’s an example of a Chunk class i use in some variants of the engine. This one is a bit experimental but working OK so far.   using UnityEngine; using System.Collections.Generic; public enum ChunkState:int { Invalid = 0, Base = 1, Terra = 10, ReGen…

Creating a grid mesh programmatically in Unity 3D

using System; using System.Collections.Generic; using UnityEngine; public static class Grid { public static void Create(bool withCollision) { GameObject gridObject = new GameObject(); gridObject.name = “Grid”; gridObject.transform.position = Vector3.zero; List<int> triangles = new List<int>(); List<Vector3> vertices = new List<Vector3>(); List<Vector2> uvs = new List<Vector2>(); List<int> collision_triangles…

Some old voxel lighting code

If you look at some of the previous posts you will see this code or a variant of it in use. It may be useful to some. It is very much a hack and i hope to revisit it perhaps in c++ or java. public…

LWJGL OpenGL VBO Issue on Linux

I struggled for a while with some code that generates 2 triangles using indices with more modern OpenGL methods. It worked fine when run on my windows boxes but not on my 2011 MBP running linux. There were no errors or anything i could see…

Compressing Voxel Data

My first attempt at saving and loading voxel data seems to work reasonably well. It manages to save approx 4 million voxel points in about 64kb which seems reasonable. The compression ratio would decrease as the usefulness of RLE (Run Length Encoding) wanes due to…

Mesh Optimization

Below is my custom version of a greedy mesh optimizer for voxel data in Unity3d translated from JavaScript to c# using the original awesome mind bending code of Mikola Lysenko. This is useful if you need to use mesh for collision data and it can…