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…

Accessing strings in c++ from c#

Scenario; You may have some c++ code you wish to output string data to be used in a c# application. #include <stdio.h> #include <string.h> extern “C” { __declspec(dllexport) int GetString(char* buf,int n) { strncpy(buf,”my string in cpp”, n); return 0; } } using System.Runtime.InteropServices; [DllImport(“mycppdll.dll”,…

SQL to JSON with C#

This seems to work quite well. If there is a more efficient way please let me know. string SQLtoJSON(string _sqlCon, string _sqlQuery) { using (SqlConnection con = new SqlConnection(_sqlCon)) { using (SqlCommand cmd = new SqlCommand(_sqlQuery, con)) { using (SqlDataAdapter adapter = new SqlDataAdapter(cmd)) {…

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…