/*public void SetSurfacePoints(Vector3Int[] points) * { * for (int i = 0; i < points.Length; i++) * if (!surfacePoints.Contains(points[i])) * surfacePoints.Add(points[i]); * }*/ public void SetBlockAtLocation(Vector3 position, byte type) { Vector3Int voxelPos = VoxelConversions.WorldToVoxel(position); Vector3Int chunk = VoxelConversions.VoxelToChunk(voxelPos); Vector3Int localVoxel = VoxelConversions.GlobalVoxToLocalChunkVoxCoord(chunk, voxelPos); if (BuilderExists(chunk.x, chunk.y, chunk.z)) { Chunks[new Vector3Int(chunk.x, chunk.y, chunk.z)].EditNextFrame(new Chunk.BlockChange[] { new Chunk.BlockChange(position, type) }); } }
public byte GetBlock(int x, int y, int z) { Vector3Int chunk = VoxelConversions.VoxelToChunk(new Vector3Int(x, y, x)); Vector3Int localVoxel = VoxelConversions.GlobalVoxToLocalChunkVoxCoord(chunk, new Vector3Int(x, y, z)); byte result = 1; if (x >= 0 && y >= 0 && z >= 0 && BuilderExists(chunk.x, chunk.y, chunk.z)) { result = Chunks[new Vector3Int(chunk.x, chunk.y, chunk.z)].GetBlock(x, y, z); } return(result); }
} // needs to be changed if using superchunks. public byte GetBlock(int x, int y, int z) { Vector3Int chunk = VoxelConversions.VoxelToChunk(new Vector3Int(x, y, x)); Vector3Int localVoxel = VoxelConversions.GlobalVoxToLocalChunkVoxCoord(chunk, new Vector3Int(x, y, z)); byte result = 1; if (x >= 0 && y >= 0 && z >= 0 && Chunks.ContainsKey(chunk)) { result = Chunks[chunk].GetBlock(x, y, z); } return(result); }
public void ChangeBlock(Chunk.BlockChange change) { Vector3Int chunk = VoxelConversions.VoxelToChunk(change.position); Vector3Int localVoxel = VoxelConversions.GlobalVoxToLocalChunkVoxCoord(chunk, change.position); //Debug.LogFormat("voxel: {0}, localVoxel: {1}, chunk: {2}", voxel, localVoxel, chunk); if (BuilderExists(chunk.x, chunk.y, chunk.z)) { if (localVoxel.x >= 0 && localVoxel.x < VoxelSettings.ChunkSizeX && localVoxel.y >= 0 && localVoxel.y < VoxelSettings.ChunkSizeY && localVoxel.z >= 0 && localVoxel.z < VoxelSettings.ChunkSizeZ) { Chunks[chunk].EditNextFrame(new Chunk.BlockChange(localVoxel, change.type)); } else { SafeDebug.LogError(string.Format("Out of Bounds: chunk: {0}, globalVoxel:{1}, localVoxel: {2}, Function: GenerateExplosion", chunk, change.position, localVoxel)); } } }
public void GenerateExplosion(Vector3 postion, int radius) { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); Loom.AddAsyncThread("Explosion"); Loom.QueueAsyncTask("Explosion", () => { Dictionary <Vector3Int, List <Chunk.BlockChange> > changes = new Dictionary <Vector3Int, List <Chunk.BlockChange> >(); Vector3Int voxelPos = VoxelConversions.WorldToVoxel(postion); for (int x = voxelPos.x - radius; x <= voxelPos.x + radius; x++) { for (int y = voxelPos.y - radius; y <= voxelPos.y + radius; y++) { for (int z = voxelPos.z - radius; z <= voxelPos.z + radius; z++) { Vector3Int voxel = new Vector3Int(x, y, z); Vector3Int chunk = VoxelConversions.VoxelToChunk(voxel); if (IsInSphere(voxelPos, radius, voxel)) { if (!changes.ContainsKey(chunk)) { changes.Add(chunk, new List <Chunk.BlockChange>()); } changes[chunk].Add(new Chunk.BlockChange(VoxelConversions.GlobalVoxToLocalChunkVoxCoord(chunk, voxel), 0)); //ChangeBlock(new Chunk.BlockChange(voxel, 0)); } } } } //Debug.Log("Iterated through exploded blocks: " + watch.Elapsed.ToString()); Loom.QueueOnMainThread(() => { foreach (Vector3Int chunkPos in changes.Keys) { ChangeBlock(chunkPos, changes[chunkPos].ToArray()); } watch.Stop(); //Debug.Log("Blocks changes sent to chunk: " + watch.Elapsed.ToString()); }); }); }