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)) {…

php mysql database connection

Connecting to mysql via php. <?php $servername = “hostname”; $username = “username”; $password = “password”; $dbname = “database”; $loggedin = false; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { //handle it } ?> this is nice to keep in a separate file (inc/conn.php)…

upload via FTP with c#

Quick and easy way to get files uploaded with c#; static void Upload(string pathSource, string pathDest, string ftpServer, string ftpUsername, string ftpPassword ) { using (WebClient client = new WebClient()) { client.Credentials = new NetworkCredential(ftpUsername, ftpPassword); try { client.UploadFile(ftpServer + pathDest, “STOR”, pathSource); } catch(System.Net.WebException…

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…