private MeshBuilder GetMeshBuilder(int x, int y, int z) { if (_chunksMeshes[x, y, z] == null) { _chunksMeshes.Init(x, y, z, BuildChunkMeshBuilder(x, y, z)); } return(_chunksMeshes[x, y, z]); }
public void SetVoxel(LoadedVoxelMaterial mat, ushort height, Vector3Int pos) { var cx = (pos.x + (pos.x < 0 ? 1 : 0)) / ChunkDataSettings.XSize - (pos.x < 0 ? 1 : 0); var cy = (pos.y + (pos.y < 0 ? 1 : 0)) / ChunkDataSettings.YSize - (pos.y < 0 ? 1 : 0); var cz = (pos.z + (pos.z < 0 ? 1 : 0)) / ChunkDataSettings.ZSize - (pos.z < 0 ? 1 : 0); var chunk = _chunks[cx, cy, cz] ?? _chunks.Init(cx, cy, cz, new FluidUpdater()); chunk.SetVoxel(mat, height, pos); }
public void SetVoxel(ushort material, Vector3Int pos) { var cx = (pos.x + (pos.x < 0 ? 1 : 0)) / ChunkDataSettings.XSize - (pos.x < 0 ? 1 : 0); var cy = (pos.y + (pos.y < 0 ? 1 : 0)) / ChunkDataSettings.YSize - (pos.y < 0 ? 1 : 0); var cz = (pos.z + (pos.z < 0 ? 1 : 0)) / ChunkDataSettings.ZSize - (pos.z < 0 ? 1 : 0); var chunk = _chunks[cx, cy, cz] ?? _chunks.Init(cx, cy, cz, new Chunk()); var p = new Vector3Int(Mod(pos.x, ChunkDataSettings.XSize), Mod(pos.y, ChunkDataSettings.YSize), Mod(pos.z, ChunkDataSettings.ZSize)); var neighbours = chunk.SetVoxelData(p, material, MaterialCollection); if (_batchMode) { var cp = new Vector3Int(cx, cy, cz); if (!chunk.NeedsUpdate) { chunk.NeedsUpdate = true; lock (Lock) { _batchedChunks.Add(cp); } } } else { var mySlice = _slice - cy * ChunkDataSettings.YSize; GetMeshBuilder(cx, cy, cz).BuildMeshAndApply(MaterialCollection, GetNeighbours(cx, cy, cz), chunk, mySlice, true); } foreach (var neighbour in neighbours) { var nPos = GetNeighbourPos(cx, cy, cz, neighbour); if (_chunksMeshes[nPos.x, nPos.y, nPos.z] != null) { if (_batchMode) { if (!_chunks[nPos.x, nPos.y, nPos.z].NeedsUpdate) { _chunks[nPos.x, nPos.y, nPos.z].NeedsUpdate = true; lock (Lock) { _batchedChunks.Add(nPos); } } } else { var mySlice = _slice - nPos.y * ChunkDataSettings.YSize; GetMeshBuilder(nPos.x, nPos.y, nPos.z).BuildMeshAndApply(MaterialCollection, GetNeighbours(nPos.x, nPos.y, nPos.z), _chunks[nPos.x, nPos.y, nPos.z], mySlice, true); } } } }