• Unlikely Objects
  • Ludography
    • Nonoku
    • Acquisition
    • Image Mark Up
  • About
Menu

Unlikely Objects

  • Unlikely Objects
  • Ludography
  • Pint Sized Planet
    • Nonoku
    • Acquisition
    • Image Mark Up
  • About

An Evening of Code: Simplex Noise and Mesh Building

February 7, 2015

On advice from the tutorials out there I've moved to using Simplex noise. It also now creates two layers of noise so that we can have dirt on top of the stone. 

Probably the biggest single change is that chunks now generate a mesh, rather than instantiating a cube for each voxel. This is (unsurprisingly) a lot faster and actually allows me to have stacks of blocks. 

Creating a mesh in Unity is pretty straightforward. Specify four Vector3s and define as two triangles to form a square face. Use 6 square faces to form a cube.

// Top Face
Vector3[] vertices = new Vector3[4];
vertices[0]  = new Vector3 (x,  y,  z + 1);
vertices[1] = new Vector3 (x + 1, y,  z + 1);
vertices[2] = new Vector3 (x + 1, y,  z );
vertices[3] new Vector3 (x,  y,  z );
        
// Triangles
int[] triangles = new int[6];   // Two triangles, 3 points each, 2 verts are shared
triangles[0] = 0;
triangles[1] = 1;
triangles[2] = 2;
triangles[3] = 0;
triangles[4] = 2;
triangles[5] = 3;

mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.Optimize();
mesh.RecalculateNormals();

col.sharedMesh = mesh;  // Use render mesh for collisions

A simple optimisation then is to check if there is another cube adjacent. Since there is no gap we don't need to include the face on that side. 

Lastly, track the block type and assign the appropriate texture.  

It's lacking a lot of features that would make it a game. I might look into some basic changes like supporting just because it's straightforward. Really though, this was to serve as a refresher in how to think about 3D and procedural content. In that, it's served its purpose. 

In An Evening of Code, Unity Tags unity, indiedev, gamedev, procedural
← LinkDump: L-SystemsTools - Unity →

Latest

Unlikely Objects
Fractal Plant in Godot
about a year ago
Binary Tree in Godot
about a year ago
Sierpinski Triangle in Godot
about a year ago
Re-visiting some old code
about a year ago
React - Starting a New Project
about 3 years ago
Satsuma Tosser
about 4 years ago
1HGJ #002: Deeper and Deeper
about 7 years ago
1HGJ #001: Telekinetic Bomberman Rush
about 7 years ago
Migrating to NSPersistentContainer
about 7 years ago
Nonoku - SpriteKit Shader
about 7 years ago

Powered by Squarespace