public static HeightMap GenBasicTerrainMap(HeightmapProperties heightProps, int seed) { HeightMap h = new HeightMap(heightProps.size, seed); h.AddPerlinNoise(heightProps.perlinFreq); h.Perturb(heightProps.perturb, heightProps.perturb); for (int i = 0; i < HeightMapGen.erodePasses; i++ ) h.Erode(heightProps.erode); h.Smoothen(); return h; }
public static void GenerateSubTerrain(Planet planet, HeightmapProperties heightProps, float scale, int seed, float cutoff = 0f) { GameObject sphere = planet.land.gameObject; System.Random rand = new System.Random(seed); UnityEngine.Random.seed = rand.Next (); HeightMap terrainMap = HeightMapGen.GenBasicTerrainMap(heightProps, rand.Next()); int subTimes = UnityEngine.Random.Range (8, 16); for (int i = 0; i < subTimes; i++) { UnityEngine.Random.seed = rand.Next (); string blendMode = HeightmapProperties.heightBlendModes[UnityEngine.Random.Range (0, HeightmapProperties.heightBlendModes.Length - 1)]; float blendAmount = 1f + UnityEngine.Random.value; int posX = UnityEngine.Random.Range (0, Mathf.Abs (terrainMap.Heights.GetLength(0) - 1)); int posY = UnityEngine.Random.Range (0, Mathf.Abs (terrainMap.Heights.GetLength(1) - 1)); int nx = rand.Next (); HeightmapProperties submap = HeightmapProperties.GetRandSub(nx); HeightMap subTerrainMap = HeightMapGen.GenBasicTerrainMap(submap, rand.Next()); terrainMap.Blend(subTerrainMap, blendMode, posX, posY, blendAmount); } terrainMap.AntiAlias (); terrainMap.Smoothen (); terrainMap.MendSeams (); SphereGenerator.ApplyHeightMap(sphere, scale, terrainMap.Heights, cutoff); }