public void Generate(IModule module, int _seed, bool _enableCaves, float _amp, float _caveDensity, float _grassOffset) { try { Sampler = new TerrainSampler(module, _seed, _enableCaves, _amp, _caveDensity, _grassOffset);; Sampler.SetChunkSettings(VoxelsPerMeter, new Vector3Int(ChunkSizeX, ChunkSizeY, ChunkSizeZ), new Vector3Int(ChunkMeterSizeX, ChunkMeterSizeY, ChunkMeterSizeZ), skipDist, half, new Vector3(xSideLength, ySideLength, zSideLength)); Vector2Int bottomLeft = new Vector2(location.x * ChunkSizeX, location.z * ChunkSizeZ); Vector2Int topRight = new Vector2(location.x * ChunkSizeX + ChunkSizeX, location.z * ChunkSizeZ + ChunkSizeZ); watch.Start(); Sampler.SetSurfaceData(bottomLeft, topRight); watch.Stop(); noiseGenTime = watch.Elapsed.ToString(); int bottom = VoxelConversions.ChunkToVoxel(location).y; empty = bottom > Sampler.GetMax(); } catch (Exception e) { SafeDebug.LogError(string.Format("{0}\nFunction: Generate\n Chunk: {1}", e.Message, location.ToString()), e); } }
public void Generate(int height) { int chunkSizeX = SmoothVoxelSettings.ChunkSizeX; int chunkSizeY = SmoothVoxelSettings.ChunkSizeY; int chunkSizeZ = SmoothVoxelSettings.ChunkSizeZ; int meterSizeX = SmoothVoxelSettings.MeterSizeX; int meterSizeY = SmoothVoxelSettings.MeterSizeY; int meterSizeZ = SmoothVoxelSettings.MeterSizeZ; Sampler.SetChunkSettings(SmoothVoxelSettings.voxelsPerMeter, new Vector3Int(chunkSizeX, chunkSizeY, chunkSizeZ), new Vector3Int(meterSizeX, meterSizeY, meterSizeZ), Mathf.RoundToInt(1 / (float)SmoothVoxelSettings.voxelsPerMeter), ((1.0f / (float)SmoothVoxelSettings.voxelsPerMeter) / 2.0f), new Vector3(meterSizeX / (float)chunkSizeX, meterSizeY / (float)chunkSizeY, meterSizeZ / (float)chunkSizeZ)); Vector3Int topVoxel = VoxelConversions.WorldToVoxel(new Vector3(0, (float)Sampler.GetMax(), 0)); Vector3Int bottomVoxel = VoxelConversions.WorldToVoxel(new Vector3(0, (float)Sampler.GetMin(), 0)); int topChunk = VoxelConversions.VoxelToChunk(topVoxel).y; int bottomChunk = VoxelConversions.VoxelToChunk(bottomVoxel).y; if (NetworkMode) { for (int y = 0; y <= topChunk; y++) { SmoothChunk.CreateChunk(new Vector3Int(Location.x, y, Location.y), Sampler, Controller); } } else { Vector2Int bottomLeft = new Vector2(Location.x * chunkSizeX, Location.y * chunkSizeZ); Vector2Int topRight = new Vector2(Location.x * chunkSizeX + chunkSizeX, Location.y * chunkSizeZ + chunkSizeZ); Sampler.SetSurfaceData(bottomLeft, topRight); for (int y = 0; y <= topChunk; y++) { SmoothChunk.CreateChunk(new Vector3Int(Location.x, y, Location.y), Sampler, Controller); } Loom.QueueOnMainThread(() => { Debug.Log("Spawning grass..."); SpawnGrass(); }); } }