/// <summary> /// Run a test for the marching cubes algorithm. /// </summary> private static void TestMarchingCubes() { var terrain = new VoxelTerrain(); var chunkIndex = new Position(0, 0); var noiseGenerator = new NoiseGenerator(1, 16, 0.001f, 0.25f); var voxelGenerator = new ChunkVoxelGenerator(noiseGenerator, 0, 50); // Load the chunk var chunkLoader = new ChunkLoader(voxelGenerator); chunkLoader.LoadChunk(terrain, chunkIndex); // Generate the mesh var meshGenerator = new MarchingCubesGenerator(terrain, 7); meshGenerator.UpdateChunk(chunkIndex); }
/// <summary> /// Run a test for the noise generator. /// </summary> private static void TestNoiseGenerator() { int seed = 3; byte octaves = 16; float baseFrequency = 0.0025f; float persistence = 0.25f; var generator = new NoiseGenerator(seed, octaves, baseFrequency, persistence); float[] vals = new float[2000]; for (int x = 0; x < vals.Length; x++) { vals[x] = generator.Generate(x); } var voxelGenerator = new ChunkVoxelGenerator(generator, 0, 50); float[] surfaceValues = voxelGenerator.GenerateSurfaceHeights(0); }
/// <summary> /// Initialises a new instance of the ChunkVoxelGenerator class. /// </summary> /// <param name="noiseGenerator">The noise generator.</param> /// <param name="surfaceOrigin">The Y position around which the generated surface oscillates.</param> /// <param name="surfaceAmplitude">The maximum Y distance that the surface can fluctuate from the origin (above /// or below).</param> public ChunkVoxelGenerator(NoiseGenerator noiseGenerator, int surfaceOrigin, int surfaceAmplitude) { this.NoiseGenerator = noiseGenerator; this.SurfaceOrigin = surfaceOrigin; this.SurfaceAmplitude = surfaceAmplitude; }
/// <summary> /// Initialises the component. /// </summary> public void Start() { this.cTerrain = this.GetComponent<TerrainComponent>(); // Initialise the noise and voxel generator var noiseGenerator = new NoiseGenerator(this.Seed, (byte)this.Octaves, this.BaseFrequency, this.Persistence); var voxelGenerator = new ChunkVoxelGenerator(noiseGenerator, this.SurfaceOrigin, this.SurfaceAmplitude); // Create the chunk loader this.ChunkLoader = new ChunkLoader(voxelGenerator); }