public void GenerateBlockInstance(int x, int z) { if (!MapDatabaseScript.IsVacent(x, z)) { Debug.Log("Tried to generate block at (" + x + ", " + z + "). Aborted."); return; } Vector3 GetWorldCoordinates(float xIndex, float zIndex) { return(new Vector3(xIndex * block_VertexWidth, 0, zIndex * block_VertexWidth)); } // Generate biome and sub-biome, and get the gradient MapDatabaseScript.GeneratePossibleBiome(x, z); Tuple <uint[, ], float[, ]> subBiomeGradient = MapDatabaseScript.GetSubBiome(x, z); // Generate heightmap float[,] Heightmap = HeightmapGenScript.GenerateHeightmap(x, z, subBiomeGradient.Item1, subBiomeGradient.Item2); // Generate material Texture2D Texture = MaterialGenScript.GenerateTexture(Heightmap, subBiomeGradient.Item1); // TODO generate bumpmap and misc. // Generate model GameObject ModelGenInstance = (GameObject)GameObject.Instantiate(ModelGenPrefab, GetWorldCoordinates(x, z), Quaternion.identity); ModelGen ModelGenScript = ModelGenInstance.GetComponent <ModelGen>(); ModelGenScript.GenerateMesh(Heightmap, Texture, block_VertexWidth); // Place possible models on top of block Vector3 topLeft = new Vector3(ModelGenInstance.transform.position.x, 0f, ModelGenInstance.transform.position.z + block_VertexWidth); ModelPlacerScript.PlacePossibleModels(Heightmap, subBiomeGradient.Item1, topLeft); // Merge model to master mesh ModelGenInstance.transform.parent = MasterTerrainInstance.transform; }