public void Generate() { float smoothness = 0.4f; Block[,,] blocks = new Block[Chunk.size, Chunk.size, Chunk.size]; Vector3 chunkPosition = Vector3.zero; for (int i = 0; i < Size.x; i++) { for (int j = 0; j < Size.y; j++) { ChunkColumn chunkColumn = new ChunkColumn(); chunkColumn.localPosition = new Vector2(i, j); chunkColumn.globalPosition = new Vector3( i * Chunk.size, 0, j * Chunk.size ); chunkColumn.parent = this; Vector3 currentPosition = Camera.main.transform.position; chunkPosition = chunkColumn.globalPosition; for (int k = 0; k < ChunkColumn.chunksPerColumn; k++) { chunkPosition.y = Chunk.size * k; for (int l = 0; l < Chunk.size; l++) { for (int m = 0; m < Chunk.size; m++) { for (int n = 0; n < Chunk.size; n++) { Vector3 positionInChunk = new Vector3(l, m, n); Vector3 position = positionInChunk + chunkPosition; int maxHeight = 50 + (int)(50 * Mathf.PerlinNoise(position.x / worldMagnitude, position.z / worldMagnitude)); if (position.x == startPosition.x && position.z == startPosition.z) { startPosition.y = maxHeight; } float magnitude = PerlinNoise3d.Make(position / (worldMagnitude * smoothness)); Block block = BlockDecider(magnitude, position.y, maxHeight); blocks[l, m, n] = block; } } } Chunk.StaticSave(chunkColumn.localPosition, k, blocks); } chunkColumns[i, j] = chunkColumn; } } }
/// <inheritdoc /> protected override void SolveInstance(IGH_DataAccess DA) { GH_Vector scale = null; if (!DA.GetData(0, ref scale)) { return; } GH_Vector offset = null; if (!DA.GetData(1, ref offset)) { return; } switch (_type) { case NoiseType.Perlin: { var f = new PerlinNoise3d(scale.Value, offset.Value); DA.SetData(0, new GH_ObjectWrapper(f)); break; } case NoiseType.Simplex: { var f = new SimplexNoise3d(scale.Value, offset.Value); DA.SetData(0, new GH_ObjectWrapper(f)); break; } default: { throw new ArgumentException("The specified noise type is not supported."); } } }