public SavedChunkInfo(Chunk chunk) { unityPosition = chunk.transform.position; worldPos = chunk.Pos; initEmpty = chunk.initEmpty; hasBlocks = false; for (var x = 0; x < World.ChunkSize; x++) { for (var y = 0; y < World.ChunkSize; y++) { for (var z = 0; z < World.ChunkSize; z++) { if (!chunk.isDefault && chunk.Blocks[x, y, z].BlockType == VoxBlockType.Empty) continue; if (!chunk.Blocks[x, y, z].Modified) continue; var pos = new WorldPos(x,y,z); Blocks.Add(pos, chunk.Blocks[x, y, z]); hasBlocks = true; } } } }
public Chunk ChunkGen(Chunk chunk) { for (var x = chunk.Pos.x; x < chunk.Pos.x + World.ChunkSize; x++) { for (var z = chunk.Pos.z; z < chunk.Pos.z + World.ChunkSize; z++) { chunk = ChunkColumnGen(chunk, x, z); } } return chunk; }
public static void SaveChunk(Chunk chunk) { var save = new VoxSave(chunk); if (save.Blocks.Count == 0) return; var path = Path.Combine(SaveLocation(chunk.World.WorldName), FileName(chunk.Pos)); IFormatter formatter = new BinaryFormatter(); var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, save); stream.Close(); }
public VoxSave(Chunk chunk) { for (var x = 0; x < World.ChunkSize; x++) { for (var y = 0; y < World.ChunkSize; y++) { for (var z = 0; z < World.ChunkSize; z++) { if (!chunk.Blocks[x, y, z].Modified) continue; var pos = new WorldPos(x,y,z); Blocks.Add(pos, chunk.Blocks[x, y, z]); } } } }
public static bool Load(Chunk chunk) { var path = Path.Combine(SaveLocation(chunk.World.WorldName), FileName(chunk.Pos)); if (!File.Exists(path)) return false; IFormatter formatter = new BinaryFormatter(); var stream = new FileStream(path, FileMode.Open); var save = (VoxSave)formatter.Deserialize(stream); foreach (var block in save.Blocks) { chunk.Blocks[block.Key.x, block.Key.y, block.Key.z] = block.Value; } stream.Close(); return true; }
public Chunk ChunkColumnGen(Chunk chunk, int x, int z) { var stoneHeight = Mathf.FloorToInt(StoneBaseHeight); //stoneHeight += GetNoise(x, 0, z, StoneMountainFrequency, Mathf.FloorToInt(StoneMountainHeight)); stoneHeight += GetNoisePerlin(x + randomSeed, 0, z + randomSeed, StoneMountainFrequency, Mathf.FloorToInt(StoneMountainHeight)); //stoneHeight += Mathf.PerlinNoise(x, z); if (stoneHeight < StoneMinHeight) stoneHeight = Mathf.FloorToInt(StoneMinHeight); stoneHeight += GetNoise(x + randomSeed, 0, z + randomSeed, StoneBaseNoise, Mathf.FloorToInt(StoneBaseNoiseHeight)); var dirtHeight = stoneHeight + Mathf.FloorToInt(DirtBaseHeight); dirtHeight += GetNoise(x, 100, z, DirtNoise, Mathf.FloorToInt(DirtNoiseHeight)); for (var y = chunk.Pos.y; y < chunk.Pos.y + World.ChunkSize; y++) { if (y <= stoneHeight) { //chunk.SetBlock(x - chunk.Pos.x, y - chunk.Pos.y, z - chunk.Pos.z, new Block(colorB)); chunk.SetBlock(x - chunk.Pos.x, y - chunk.Pos.y, z - chunk.Pos.z, VoxBlockType.Default, colorB); } else if (y <= dirtHeight) { //chunk.SetBlock(x - chunk.Pos.x, y - chunk.Pos.y, z - chunk.Pos.z, new Block(colorA)); chunk.SetBlock(x - chunk.Pos.x, y - chunk.Pos.y, z - chunk.Pos.z, VoxBlockType.Default, colorA); } else { //chunk.SetBlock(x - chunk.Pos.x, y - chunk.Pos.y, z - chunk.Pos.z, new BlockEmpty()); chunk.SetBlock(x - chunk.Pos.x, y - chunk.Pos.y, z - chunk.Pos.z, VoxBlockType.Empty, Color.white); } } return chunk; }
public virtual MeshData Blockdata(Chunk chunk, int x, int y, int z, float scale, float worldScale, MeshData meshData) { if (BlockType == VoxBlockType.Empty) return meshData; meshData.UseRenderDataForCol = true; if (!chunk.GetBlock(x, y + 1, z).IsSolid(Direction.Down)) { meshData = FaceDataUp(chunk, x, y, z, scale, worldScale, meshData); } if (!chunk.GetBlock(x, y - 1, z).IsSolid(Direction.Up)) { meshData = FaceDataDown(chunk, x, y, z, scale, worldScale, meshData); } if (!chunk.GetBlock(x, y, z + 1).IsSolid(Direction.South)) { meshData = FaceDataNorth(chunk, x, y, z, scale, worldScale, meshData); } if (!chunk.GetBlock(x, y, z - 1).IsSolid(Direction.North)) { meshData = FaceDataSouth(chunk, x, y, z, scale, worldScale, meshData); } if (!chunk.GetBlock(x + 1, y, z).IsSolid(Direction.West)) { meshData = FaceDataEast(chunk, x, y, z, scale, worldScale, meshData); } if (!chunk.GetBlock(x - 1, y, z).IsSolid(Direction.East)) { meshData = FaceDataWest(chunk, x, y, z, scale, worldScale, meshData); } return meshData; }
protected virtual MeshData FaceDataWest(Chunk chunk, int x, int y, int z, float scale, float worldScale, MeshData meshData) { meshData.AddVertex(new Vector3(x * worldScale - scale, y * worldScale - scale, z * worldScale + scale), BlockColor); meshData.AddVertex(new Vector3(x * worldScale - scale, y * worldScale + scale, z * worldScale + scale), BlockColor); meshData.AddVertex(new Vector3(x * worldScale - scale, y * worldScale + scale, z * worldScale - scale), BlockColor); meshData.AddVertex(new Vector3(x * worldScale - scale, y * worldScale - scale, z * worldScale - scale), BlockColor); meshData.AddQuadTriangles(); meshData.uv.AddRange(FaceUVs(Direction.West)); return meshData; }