/// <summary> /// Sets a cell at the given cell coordinates. /// </summary> public void SetCell(int x, int y, int z, CellMaterial material, sbyte density) { Chunk chunk; var coord = new Vector3int16(RoundDownDivide(x, ChunkSize), RoundDownDivide(y, ChunkSize), RoundDownDivide(z, ChunkSize)); lock (Locker) { if (!_chunks.TryGetValue(coord, out chunk)) { chunk = new Chunk(this, coord); _chunks[coord] = chunk; } } chunk[ Math.Abs(x % ChunkSize), Math.Abs(y % ChunkSize), Math.Abs(z % ChunkSize)] = new Cell(material, density); if (chunk.OccupiedCells == 0) { _chunks.TryRemove(coord); } }
public Cell(CellMaterial material, sbyte density) { Material = material; if (material == CellMaterial.Air) { density = 0; } Density = density; }
/// <summary> /// Fills a region of terrain. /// </summary> /// <param name="region">The region to fill.</param> /// <param name="material">The material for each cell.</param> /// <param name="density">The density for each cell.</param> public void FillRegion(Region3int16 region, CellMaterial material, sbyte density) { Parallel.For(region.Min.x, region.Max.x, x => { for (short y = region.Min.y; y < region.Max.y; y++) { for (short z = region.Min.z; z < region.Max.z; z++) { SetCell(x, y, z, material, density); } } }); }
public void SetMaterial(GameObject prefab) { if (this._materialGO != null) { GameObject.Destroy(this._materialGO); } // spawn material prefab (visualization + values) this._materialGO = Instantiate(prefab); this._materialGO.transform.parent = transform; this._materialGO.transform.localPosition = new Vector3(0, 0.1f, 0); materialType = this._materialGO.GetComponent <CellMaterial>(); materialSet = true; }
private void SetCell(Vector3int16 cellPos, CellMaterial material, sbyte density) { SetCell(cellPos.x, cellPos.y, cellPos.z, material, density); }
public void SetMaterial(GameObject prefab) { if(this._materialGO != null) { GameObject.Destroy(this._materialGO); } // spawn material prefab (visualization + values) this._materialGO = Instantiate(prefab); this._materialGO.transform.parent = transform; this._materialGO.transform.localPosition = new Vector3(0, 0.1f, 0); materialType = this._materialGO.GetComponent<CellMaterial>(); materialSet = true; }