internal override ushort GetVoxel(int x, int y, int z, ushort height) { if (y < height) { return(VoxelManager.GetVoxel("debug_red").Id); } else { return(VoxelManager.AirVoxel); } }
void GetMeshData(int x, int y, int z) { int addedVertices = 0; int indiceOffset = vertices.Count; //Left if (IsSolid(x, y, z - 1)) { vertices.Add(new Vector3(x + 0, y + 0, z + 0)); vertices.Add(new Vector3(x + 1, y + 1, z + 0)); vertices.Add(new Vector3(x + 1, y + 0, z + 0)); vertices.Add(new Vector3(x + 0, y + 1, z + 0)); indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 3, indiceOffset + 1 }); normals.AddRange(new Vector3[] { -Vector3.UnitZ, -Vector3.UnitZ, -Vector3.UnitZ, -Vector3.UnitZ }); addedVertices += 4; indiceOffset += 4; } //Right if (IsSolid(x, y, z + 1)) { vertices.Add(new Vector3(x + 0, y + 0, z + 1)); vertices.Add(new Vector3(x + 1, y + 0, z + 1)); vertices.Add(new Vector3(x + 1, y + 1, z + 1)); vertices.Add(new Vector3(x + 0, y + 1, z + 1)); indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 2, indiceOffset + 3 }); normals.AddRange(new Vector3[] { Vector3.UnitZ, Vector3.UnitZ, Vector3.UnitZ, Vector3.UnitZ }); addedVertices += 4; indiceOffset += 4; } //Front if (IsSolid(x - 1, y, z)) { vertices.Add(new Vector3(x + 0, y + 0, z + 0)); vertices.Add(new Vector3(x + 0, y + 1, z + 1)); vertices.Add(new Vector3(x + 0, y + 1, z + 0)); vertices.Add(new Vector3(x + 0, y + 0, z + 1)); indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 3, indiceOffset + 1 }); normals.AddRange(new Vector3[] { -Vector3.UnitX, -Vector3.UnitX, -Vector3.UnitX, -Vector3.UnitX }); addedVertices += 4; indiceOffset += 4; } //Back if (IsSolid(x + 1, y, z)) { vertices.Add(new Vector3(x + 1, y + 0, z + 0)); vertices.Add(new Vector3(x + 1, y + 1, z + 0)); vertices.Add(new Vector3(x + 1, y + 1, z + 1)); vertices.Add(new Vector3(x + 1, y + 0, z + 1)); indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 2, indiceOffset + 3 }); normals.AddRange(new Vector3[] { Vector3.UnitX, Vector3.UnitX, Vector3.UnitX, Vector3.UnitX }); addedVertices += 4; indiceOffset += 4; } //Bottom if (IsSolid(x, y - 1, z)) { vertices.Add(new Vector3(x + 0, y + 0, z + 0)); vertices.Add(new Vector3(x + 1, y + 0, z + 0)); vertices.Add(new Vector3(x + 1, y + 0, z + 1)); vertices.Add(new Vector3(x + 0, y + 0, z + 1)); indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 2, indiceOffset + 3 }); normals.AddRange(new Vector3[] { -Vector3.UnitY, -Vector3.UnitY, -Vector3.UnitY, -Vector3.UnitY }); addedVertices += 4; indiceOffset += 4; } //Top if (IsSolid(x, y + 1, z)) { vertices.Add(new Vector3(x + 1, y + 1, z + 0)); vertices.Add(new Vector3(x + 0, y + 1, z + 0)); vertices.Add(new Vector3(x + 1, y + 1, z + 1)); vertices.Add(new Vector3(x + 0, y + 1, z + 1)); indices.AddRange(new int[] { indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 1, indiceOffset + 3, indiceOffset + 2 }); normals.AddRange(new Vector3[] { Vector3.UnitY, Vector3.UnitY, Vector3.UnitY, Vector3.UnitY }); addedVertices += 4; indiceOffset += 4; } if (addedVertices > 0) { Vector4b voxelColor = VoxelManager.GetVoxel(parentChunk.voxels[x, y, z]).Color; for (int i = 0; i < addedVertices; i++) { colors.Add(voxelColor); } } }
void GetMeshData(int x, int y, int z) { int addedVertices = 0; int indiceOffset = Vertices.Count; //Left if (IsSolid(x, y, z - 1)) { Vertices.Add(new Vector3(x + 0, y + 0, z + 0)); Vertices.Add(new Vector3(x + 1, y + 1, z + 0)); Vertices.Add(new Vector3(x + 1, y + 0, z + 0)); Vertices.Add(new Vector3(x + 0, y + 1, z + 0)); Indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 3, indiceOffset + 1 }); Normals.AddRange(new Vector3[] { -Vector3.forward, -Vector3.forward, -Vector3.forward, -Vector3.forward }); addedVertices += 4; indiceOffset += 4; } //Right if (IsSolid(x, y, z + 1)) { Vertices.Add(new Vector3(x + 0, y + 0, z + 1)); Vertices.Add(new Vector3(x + 1, y + 0, z + 1)); Vertices.Add(new Vector3(x + 1, y + 1, z + 1)); Vertices.Add(new Vector3(x + 0, y + 1, z + 1)); Indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 2, indiceOffset + 3 }); Normals.AddRange(new Vector3[] { Vector3.forward, Vector3.forward, Vector3.forward, Vector3.forward }); addedVertices += 4; indiceOffset += 4; } //Front if (IsSolid(x - 1, y, z)) { Vertices.Add(new Vector3(x + 0, y + 0, z + 0)); Vertices.Add(new Vector3(x + 0, y + 1, z + 1)); Vertices.Add(new Vector3(x + 0, y + 1, z + 0)); Vertices.Add(new Vector3(x + 0, y + 0, z + 1)); Indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 3, indiceOffset + 1 }); Normals.AddRange(new Vector3[] { -Vector3.right, -Vector3.right, -Vector3.right, -Vector3.right }); addedVertices += 4; indiceOffset += 4; } //Back if (IsSolid(x + 1, y, z)) { Vertices.Add(new Vector3(x + 1, y + 0, z + 0)); Vertices.Add(new Vector3(x + 1, y + 1, z + 0)); Vertices.Add(new Vector3(x + 1, y + 1, z + 1)); Vertices.Add(new Vector3(x + 1, y + 0, z + 1)); Indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 2, indiceOffset + 3 }); Normals.AddRange(new Vector3[] { Vector3.right, Vector3.right, Vector3.right, Vector3.right }); addedVertices += 4; indiceOffset += 4; } //Bottom if (IsSolid(x, y - 1, z)) { Vertices.Add(new Vector3(x + 0, y + 0, z + 0)); Vertices.Add(new Vector3(x + 1, y + 0, z + 0)); Vertices.Add(new Vector3(x + 1, y + 0, z + 1)); Vertices.Add(new Vector3(x + 0, y + 0, z + 1)); Indices.AddRange(new int[] { indiceOffset + 0, indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 2, indiceOffset + 3 }); Normals.AddRange(new Vector3[] { -Vector3.up, -Vector3.up, -Vector3.up, -Vector3.up }); addedVertices += 4; indiceOffset += 4; } //Top if (IsSolid(x, y + 1, z)) { Vertices.Add(new Vector3(x + 1, y + 1, z + 0)); Vertices.Add(new Vector3(x + 0, y + 1, z + 0)); Vertices.Add(new Vector3(x + 1, y + 1, z + 1)); Vertices.Add(new Vector3(x + 0, y + 1, z + 1)); Indices.AddRange(new int[] { indiceOffset + 1, indiceOffset + 2, indiceOffset + 0, indiceOffset + 1, indiceOffset + 3, indiceOffset + 2 }); Normals.AddRange(new Vector3[] { Vector3.up, Vector3.up, Vector3.up, Vector3.up }); addedVertices += 4; indiceOffset += 4; } if (addedVertices > 0) { Color32 voxelColor = VoxelManager.GetVoxel(voxels[x, y, z]).Color; for (int i = 0; i < addedVertices; i++) { Colors.Add(voxelColor); } } }
public Voxel(string voxel, int[] position) { this.voxel = VoxelManager.GetVoxel(voxel).Id; this.position = new Vector3Int(position[0], position[1], position[2]); }