public KernelFiniteModifier(ATerrainGenerator tg) : base(tg) { // Kernel normalize float kernsum = 0f; for (int i = 0; i < kernelModifier.Length; i++) { kernsum += kernelModifier[i]; } for (int i = 0; i < kernelModifier.Length; i++) { kernelModifier[i] /= kernsum; } //for (int i = 0; i < kernelModifier.Length; i++) Debug.Log (kernelModifier[i]); }
/// <summary> /// Initializes the chunk file, chunk generation thread and initializes all needed variables. /// </summary> public void Start() { // Make sure we are at 0|0|0 this.transform.position = new Vector3(0, 0, 0); // Singleton if (instance != null) { Debug.LogError("Multiple CubicTerrain Script GameObject detected! Error! Disabling this instance."); this.enabled = false; return; } instance = this; // Terrain stream? if (this.serializeTerrain) { this.terrainFile = new CubicTerrainFile(this.chunkFilesPath + "table.clt", this.chunkFilesPath + "data.cfd"); } // Initialize lists this.chunkObjects = new List3D <GameObject> (); this.chunkData = new List3D <CubicTerrainData> (); this.generationJobs = new List3D <ChunkGenerationJob> (); this.terrainGenerator = this.GetComponent <ATerrainGenerator> (); this.chunkGenerationThread = new Thread(this.ChunkGenerationThread); this.chunkGenerationThread.Start(); // Init this.terrainMaterial.SetTexture("_MainTex", Blocks.textureAtlas); this.transparentTerrainMaterial.SetTexture("_MainTex", Blocks.textureAtlas); if (!this.loadPlayerChunkFirst) { return; } Vector3 chunkPosition = this.GetChunkPosition(this.playerTransform.position); this.GenerateChunk((int)chunkPosition.x, (int)chunkPosition.z); this.transformPosition = this.transform.position; }
public OptimizedInfiniteModifier(ATerrainGenerator tg) : base(tg) { optimizedFiniteModifier = new OptimizedFiniteModifier(tg); }
public InfiniteTerrainModifier(ATerrainGenerator tg) : base(tg) { finiteTerrainModifier = new FiniteTerrainModifier(tg); }
/// <summary> /// Initializes the chunk file, chunk generation thread and initializes all needed variables. /// </summary> public void Start() { // Make sure we are at 0|0|0 this.transform.position = new Vector3 (0, 0, 0); // Singleton if (instance != null) { Debug.LogError ("Multiple CubicTerrain Script GameObject detected! Error! Disabling this instance."); this.enabled = false; return; } instance = this; // Terrain stream? if (this.serializeTerrain) this.terrainFile = new CubicTerrainFile(this.chunkFilesPath+"table.clt", this.chunkFilesPath+"data.cfd"); // Initialize lists this.chunkObjects = new List3D<GameObject> (); this.chunkData = new List3D<CubicTerrainData> (); this.generationJobs = new List3D<ChunkGenerationJob> (); this.terrainGenerator = this.GetComponent<ATerrainGenerator> (); this.chunkGenerationThread = new Thread (this.ChunkGenerationThread); this.chunkGenerationThread.Start (); // Init this.terrainMaterial.SetTexture ("_MainTex", Blocks.textureAtlas); this.transparentTerrainMaterial.SetTexture ("_MainTex", Blocks.textureAtlas); if (!this.loadPlayerChunkFirst) return; Vector3 chunkPosition = this.GetChunkPosition(this.playerTransform.position); this.GenerateChunk((int)chunkPosition.x,(int)chunkPosition.z); this.transformPosition = this.transform.position; }
/** * Generate and create terrain */ void generateTerrain() { TerrainData groundTerrainData = this.groundTerrain.terrainData; TerrainData waterTerrainData = this.waterTerrain.terrainData; setTerrainObjects(); int res = (int)(Mathf.Pow(2, this.simulationSize - resolution + 1) + 1f); int size = res * 2 * (int)Mathf.Pow(2f, resolution - 1); ATerrainGenerator generator = this.getTerrainGenerator(this.terrainGenerator, numberFromString(this.generationSeed)); ATerrainModifier modifier; // Which terrain modifier should be used, finite or infinite? if (this.useInfiniteModifier) { modifier = new OptimizedInfiniteModifier(generator); } else { modifier = new OptimizedFiniteModifier(generator); } modifier.setScale(Mathf.Pow(2f, resolution - 1)); // Instantiate the erosion options if we are going to visualize the erosions ErosionOptions?erosionOptions = null; if (this.visualizeErosion) { erosionOptions = new ErosionOptions { rainAmount = rainAmount, solubility = solubility, evaporation = evaporation, sedimentCapacity = sedimentCapacity, generations = generations, erosionsPerGeneration = erosionsPerGeneration }; } // Start stopwatch to time the process System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // Generate the heightmap itself TerrainMerger terrainMerger = new TerrainMerger(modifier, res, mapSplits); terrainMerger.generate(erosionOptions, time - resolution + 1, waterAmount); this.groundHeightmap = terrainMerger.getTerrainHeightmap(); this.waterHeightmap = terrainMerger.getWaterHeightmap(); this.erosionMap = terrainMerger.getErosionHeightmap(); this.waterflowMap = terrainMerger.getWaterflowHeightmap(); this.updateTerrainVisualization(); // Stop stopwatch and show total processing time. sw.Stop(); float totalTime = (float)Math.Round(sw.ElapsedMilliseconds / 10f) / 100f; int s = res - 1; Debug.Log("Finished in " + totalTime + "s on (" + s + "x" + s + ") with res of " + resolution); }
public OptimizedFiniteModifier(ATerrainGenerator tg) : base(tg) { maxZoomLevel = 6; }
public FiniteTerrainModifier(ATerrainGenerator tg) : base(tg) { }
public ATerrainModifier(ATerrainGenerator terrainGenerator) { this.terrainGenerator = terrainGenerator; }