void Awake() { terrain = Track.Instance.Terrain; terrainToolkit = new TerrainToolkit(); heightmapWidth = terrain.terrainData.heightmapWidth; heightmapHeight = terrain.terrainData.heightmapHeight; }
public void Start() { dungeonGenerator = GetComponent<DungeonGenerator> (); terrainCarver = GetComponent<TerrainCarver> (); textureGenerator = GetComponent<TerrainTextureGenerator> (); toolkit = ter.GetComponent<TerrainToolkit> (); }
// Use this for initialization void Start() { GameManager ss = mm.GetComponent <GameManager>(); //MapGenerator tt = nn.GetComponent<MapGenerator>(); MapGenerator tt = transform.parent.GetComponent <MapGenerator>(); TerrainToolkit toolkit = GetComponent <TerrainToolkit>(); toolkit.resetTerrain(); Scene scene = SceneManager.GetActiveScene(); switch ((int)scene.buildIndex) { case 1: textures = new Texture2D[] { cliffTexture, sandTexture, grassTexture, rockTexture }; slopeStops = new float[] { 30.0f, 45.0f }; heightStops = new float[] { .025f, .05f, .06f, .07f }; normalizeFactor = 0.02f; toolkit.VoronoiGenerator(com.heparo.terrain.toolkit.TerrainToolkit.FeatureType.Hills, 20, 1, 0.75f, 0.25f); break; case 3: textures = new Texture2D[] { Textures[18], Textures[19], Textures[20], Textures[19] }; slopeStops = new float[] { 30.025f, 30.05f }; heightStops = new float[] { .025f, .05f, .06f, .07f }; toolkit.VoronoiGenerator(com.heparo.terrain.toolkit.TerrainToolkit.FeatureType.Plateaus, 5, 1, 0.0f, 0.25f); //toolkit.PerlinGenerator(2, 0.5f, 9, 1.0f); normalizeFactor = 0.02f; break; case 5: textures = new Texture2D[] { Textures[21], Textures[21], Textures[20], Textures[21] }; slopeStops = new float[] { 30.025f, 30.05f }; heightStops = new float[] { .025f, .05f, .06f, .07f }; toolkit.VoronoiGenerator(com.heparo.terrain.toolkit.TerrainToolkit.FeatureType.Mountains, 5, 1, 0.0f, 0.25f); //toolkit.PerlinGenerator(2, 0.5f, 9, 1.0f); normalizeFactor = 0.04f; break; } /********* * //PerlinGenerator(int frequency, float amplitude, int octaves, float blend) *********/ //toolkit.PerlinGenerator(2, 0.5f, 9, 1.0f); /******** * VoronoiGenerator(FeatureType featureType, int cells, float features, float scale, float blend) **********/ //TextureTerrain(float[] slopeStops, float[] heightStops, Texture2D[] textures) toolkit.TextureTerrain(slopeStops, heightStops, textures); //NormaliseTerrain(float minHeight, float maxHeight, float blend) toolkit.NormaliseTerrain(0f, normalizeFactor, 1.0f); floor.BuildNavMesh(); tt.setobj(); ss.beginGame(); }
void Start() { terrain = GetComponent <Terrain>(); if (terrain == null) { return; } toolkit = GetComponent <TerrainToolkit>(); if (toolkit == null) { return; } // Thread thread = new Thread(GenerateTerrain); // thread.Start(); GenerateTerrain(); }
public void setWindErosionPreset(TerrainToolkit.windErosionPresetData preset) { this.erosionTypeInt = 3; this.erosionType = TerrainToolkit.ErosionType.Wind; this.windIterations = preset.windIterations; this.windDirection = preset.windDirection; this.windForce = preset.windForce; this.windLift = preset.windLift; this.windGravity = preset.windGravity; this.windCapacity = preset.windCapacity; this.windEntropy = preset.windEntropy; this.windSmoothing = preset.windSmoothing; }
public void setVelocityHydraulicErosionPreset(TerrainToolkit.velocityHydraulicErosionPresetData preset) { this.erosionTypeInt = 1; this.erosionType = TerrainToolkit.ErosionType.Hydraulic; this.hydraulicTypeInt = 2; this.hydraulicType = TerrainToolkit.HydraulicType.Velocity; this.hydraulicIterations = preset.hydraulicIterations; this.hydraulicVelocityRainfall = preset.hydraulicVelocityRainfall; this.hydraulicVelocityEvaporation = preset.hydraulicVelocityEvaporation; this.hydraulicVelocitySedimentSolubility = preset.hydraulicVelocitySedimentSolubility; this.hydraulicVelocitySedimentSaturation = preset.hydraulicVelocitySedimentSaturation; this.hydraulicVelocity = preset.hydraulicVelocity; this.hydraulicMomentum = preset.hydraulicMomentum; this.hydraulicEntropy = preset.hydraulicEntropy; this.hydraulicDowncutting = preset.hydraulicDowncutting; }
public void setThermalErosionPreset(TerrainToolkit.thermalErosionPresetData preset) { this.erosionTypeInt = 0; this.erosionType = TerrainToolkit.ErosionType.Thermal; this.thermalIterations = preset.thermalIterations; this.thermalMinSlope = preset.thermalMinSlope; this.thermalFalloff = preset.thermalFalloff; }
public void setFullHydraulicErosionPreset(TerrainToolkit.fullHydraulicErosionPresetData preset) { this.erosionTypeInt = 1; this.erosionType = TerrainToolkit.ErosionType.Hydraulic; this.hydraulicTypeInt = 1; this.hydraulicType = TerrainToolkit.HydraulicType.Full; this.hydraulicIterations = preset.hydraulicIterations; this.hydraulicRainfall = preset.hydraulicRainfall; this.hydraulicEvaporation = preset.hydraulicEvaporation; this.hydraulicSedimentSolubility = preset.hydraulicSedimentSolubility; this.hydraulicSedimentSaturation = preset.hydraulicSedimentSaturation; }
public void setFastHydraulicErosionPreset(TerrainToolkit.fastHydraulicErosionPresetData preset) { this.erosionTypeInt = 1; this.erosionType = TerrainToolkit.ErosionType.Hydraulic; this.hydraulicTypeInt = 0; this.hydraulicType = TerrainToolkit.HydraulicType.Fast; this.hydraulicIterations = preset.hydraulicIterations; this.hydraulicMaxSlope = preset.hydraulicMaxSlope; this.hydraulicFalloff = preset.hydraulicFalloff; }
public void erodeAllTerrain(TerrainToolkit.ErosionProgressDelegate erosionProgressDelegate) { int num; this.erosionMode = TerrainToolkit.ErosionMode.Filter; this.convertIntVarsToEnums(); Terrain component = (Terrain)base.GetComponent(typeof(Terrain)); if (component == null) { return; } try { TerrainData terrainDatum = component.terrainData; int num1 = terrainDatum.heightmapWidth; int num2 = terrainDatum.heightmapHeight; float[,] heights = terrainDatum.GetHeights(0, 0, num1, num2); switch (this.erosionType) { case TerrainToolkit.ErosionType.Thermal: { num = this.thermalIterations; heights = this.fastErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate); break; } case TerrainToolkit.ErosionType.Hydraulic: { num = this.hydraulicIterations; switch (this.hydraulicType) { case TerrainToolkit.HydraulicType.Fast: { heights = this.fastErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate); break; } case TerrainToolkit.HydraulicType.Full: { heights = this.fullHydraulicErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate); break; } case TerrainToolkit.HydraulicType.Velocity: { heights = this.velocityHydraulicErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate); break; } } break; } case TerrainToolkit.ErosionType.Tidal: { Vector3 vector3 = terrainDatum.size; if (this.tidalSeaLevel < base.transform.position.y || this.tidalSeaLevel > base.transform.position.y + vector3.y) { Debug.LogError("Sea level does not intersect terrain object. Erosion operation failed."); } else { num = this.tidalIterations; heights = this.fastErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate); } break; } case TerrainToolkit.ErosionType.Wind: { num = this.windIterations; heights = this.windErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate); break; } default: { return; } } terrainDatum.SetHeights(0, 0, heights); } catch (Exception exception) { Debug.LogError(string.Concat("An error occurred: ", exception)); } }
private float[,] fastErosion(float[,] heightMap, Vector2 arraySize, int iterations, TerrainToolkit.ErosionProgressDelegate erosionProgressDelegate) { int num; int num1; int num2; int num3; int num4; int num5; int k; int j; int l; int m; float single; float single1; int num6 = (int)arraySize.y; int num7 = (int)arraySize.x; float[,] singleArray = new float[num6, num7]; Vector3 component = ((Terrain)base.GetComponent(typeof(Terrain))).terrainData.size; float single2 = 0f; float single3 = 0f; float single4 = 0f; float single5 = 0f; float single6 = 0f; float single7 = 0f; float single8 = 0f; float single9 = 0f; float single10 = 0f; switch (this.erosionType) { case TerrainToolkit.ErosionType.Thermal: { single2 = component.x / (float)num6 * Mathf.Tan(this.thermalMinSlope * 0.0174532924f) / component.y; if (single2 > 1f) { single2 = 1f; } if (this.thermalFalloff == 1f) { this.thermalFalloff = 0.999f; } float single11 = this.thermalMinSlope + (90f - this.thermalMinSlope) * this.thermalFalloff; single3 = component.x / (float)num6 * Mathf.Tan(single11 * 0.0174532924f) / component.y; if (single3 > 1f) { single3 = 1f; } break; } case TerrainToolkit.ErosionType.Hydraulic: { single5 = component.x / (float)num6 * Mathf.Tan(this.hydraulicMaxSlope * 0.0174532924f) / component.y; if (this.hydraulicFalloff == 0f) { this.hydraulicFalloff = 0.001f; } float single12 = this.hydraulicMaxSlope * (1f - this.hydraulicFalloff); single4 = component.x / (float)num6 * Mathf.Tan(single12 * 0.0174532924f) / component.y; break; } case TerrainToolkit.ErosionType.Tidal: { float single13 = this.tidalSeaLevel - base.transform.position.y; Vector3 vector3 = base.transform.position; single6 = single13 / (vector3.y + component.y); float single14 = this.tidalSeaLevel; Vector3 vector31 = base.transform.position; float single15 = single14 - vector31.y - this.tidalRangeAmount; Vector3 vector32 = base.transform.position; single7 = single15 / (vector32.y + component.y); float single16 = this.tidalSeaLevel; Vector3 vector33 = base.transform.position; float single17 = single16 - vector33.y + this.tidalRangeAmount; Vector3 vector34 = base.transform.position; single8 = single17 / (vector34.y + component.y); single9 = single8 - single6; single10 = component.x / (float)num6 * Mathf.Tan(this.tidalCliffLimit * 0.0174532924f) / component.y; break; } default: { return heightMap; } } for (int i = 0; i < iterations; i++) { for (j = 0; j < num7; j++) { if (j == 0) { num1 = 2; num3 = 0; num5 = 0; } else if (j != num7 - 1) { num1 = 3; num3 = -1; num5 = 1; } else { num1 = 2; num3 = -1; num5 = 1; } for (k = 0; k < num6; k++) { if (k == 0) { num = 2; num2 = 0; num4 = 0; } else if (k != num6 - 1) { num = 3; num2 = -1; num4 = 1; } else { num = 2; num2 = -1; num4 = 1; } float single18 = 1f; float single19 = 0f; float single20 = 0f; float single21 = heightMap[k + num4 + num2, j + num5 + num3]; float single22 = single21; int num8 = 0; for (l = 0; l < num1; l++) { for (m = 0; m < num; m++) { if ((m != num4 || l != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (m == num4 || l == num5))) { float single23 = heightMap[k + m + num2, j + l + num3]; single22 = single22 + single23; single = single21 - single23; if (single > 0f) { single20 = single20 + single; if (single < single18) { single18 = single; } if (single > single19) { single19 = single; } } num8++; } } } float single24 = single20 / (float)num8; bool flag = false; switch (this.erosionType) { case TerrainToolkit.ErosionType.Thermal: { if (single24 >= single2) { flag = true; } break; } case TerrainToolkit.ErosionType.Hydraulic: { if (single24 > 0f && single24 <= single5) { flag = true; } break; } case TerrainToolkit.ErosionType.Tidal: { if (single24 > 0f && single24 <= single10 && single21 < single8 && single21 > single7) { flag = true; } break; } default: { return heightMap; } } if (flag) { if (this.erosionType != TerrainToolkit.ErosionType.Tidal) { if (this.erosionType == TerrainToolkit.ErosionType.Thermal) { single1 = (single24 <= single3 ? (single24 - single2) / (single3 - single2) : 1f); } else if (single24 >= single4) { float single25 = single5 - single4; single1 = 1f - (single24 - single4) / single25; } else { single1 = 1f; } float single26 = single18 / 2f * single1; float single27 = heightMap[k + num4 + num2, j + num5 + num3]; if (this.erosionMode == TerrainToolkit.ErosionMode.Filter || this.erosionMode == TerrainToolkit.ErosionMode.Brush && this.useDifferenceMaps) { float single28 = singleArray[k + num4 + num2, j + num5 + num3]; float single29 = single28 - single26; singleArray[k + num4 + num2, j + num5 + num3] = single29; } else { float single30 = single27 - single26; if (single30 < 0f) { single30 = 0f; } heightMap[k + num4 + num2, j + num5 + num3] = single30; } for (l = 0; l < num1; l++) { for (m = 0; m < num; m++) { if ((m != num4 || l != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (m == num4 || l == num5))) { float single31 = heightMap[k + m + num2, j + l + num3]; single = single27 - single31; if (single > 0f) { float single32 = single26 * (single / single20); if (this.erosionMode == TerrainToolkit.ErosionMode.Filter || this.erosionMode == TerrainToolkit.ErosionMode.Brush && this.useDifferenceMaps) { float single33 = singleArray[k + m + num2, j + l + num3]; float single34 = single33 + single32; singleArray[k + m + num2, j + l + num3] = single34; } else { single31 = single31 + single32; if (single31 < 0f) { single31 = 0f; } heightMap[k + m + num2, j + l + num3] = single31; } } } } } } else { float single35 = single22 / (float)(num8 + 1); float single36 = Mathf.Abs(single6 - single21); single1 = single36 / single9; float single37 = single21 * single1 + single35 * (1f - single1); float single38 = Mathf.Pow(single36, 3f); heightMap[k + num4 + num2, j + num5 + num3] = single6 * single38 + single37 * (1f - single38); } } } } if ((this.erosionMode == TerrainToolkit.ErosionMode.Filter || this.erosionMode == TerrainToolkit.ErosionMode.Brush && this.useDifferenceMaps) && this.erosionType != TerrainToolkit.ErosionType.Tidal) { for (j = 0; j < num7; j++) { for (k = 0; k < num6; k++) { float single39 = heightMap[k, j] + singleArray[k, j]; if (single39 > 1f) { single39 = 1f; } else if (single39 < 0f) { single39 = 0f; } heightMap[k, j] = single39; singleArray[k, j] = 0f; } } } if (this.erosionMode == TerrainToolkit.ErosionMode.Filter) { string empty = string.Empty; string str = string.Empty; switch (this.erosionType) { case TerrainToolkit.ErosionType.Thermal: { empty = "Applying Thermal Erosion"; str = "Applying thermal erosion."; break; } case TerrainToolkit.ErosionType.Hydraulic: { empty = "Applying Hydraulic Erosion"; str = "Applying hydraulic erosion."; break; } case TerrainToolkit.ErosionType.Tidal: { empty = "Applying Tidal Erosion"; str = "Applying tidal erosion."; break; } default: { return heightMap; } } float single40 = (float)i / (float)iterations; erosionProgressDelegate(empty, str, i, iterations, single40); } } return heightMap; }
public void VoronoiGenerator(TerrainToolkit.FeatureType featureType, int cells, float features, float scale, float blend) { this.generatorTypeInt = 0; this.generatorType = TerrainToolkit.GeneratorType.Voronoi; switch (featureType) { case TerrainToolkit.FeatureType.Mountains: { this.voronoiTypeInt = 0; this.voronoiType = TerrainToolkit.VoronoiType.Linear; break; } case TerrainToolkit.FeatureType.Hills: { this.voronoiTypeInt = 1; this.voronoiType = TerrainToolkit.VoronoiType.Sine; break; } case TerrainToolkit.FeatureType.Plateaus: { this.voronoiTypeInt = 2; this.voronoiType = TerrainToolkit.VoronoiType.Tangent; break; } } this.voronoiCells = cells; this.voronoiFeatures = features; this.voronoiScale = scale; this.voronoiBlend = blend; this.generateTerrain(new TerrainToolkit.GeneratorProgressDelegate(this.dummyGeneratorProgress)); }
private void OnTexturingInspectorGUI(TerrainToolkit terrain) { Rect buttonRect; Terrain ter = (Terrain) terrain.GetComponent(typeof(Terrain)); if (ter == null) { return; } TerrainData terData = ter.terrainData; terrain.splatPrototypes = terData.splatPrototypes; EditorGUILayout.Separator(); float mouseX; EditorGUILayout.BeginHorizontal(); GUI.skin = terrain.guiSkin; GUILayout.Label("Texture Slope"); GUI.skin = null; EditorGUILayout.EndHorizontal(); Rect gradientRect = EditorGUILayout.BeginHorizontal(); float gradientWidth = gradientRect.width - 55; gradientRect.width = 15; gradientRect.height = 19; GUI.skin = terrain.guiSkin; // Slope stop 1... if (dragControl == "slopeStop1" && Event.current.type == EventType.MouseDrag) { mouseX = Event.current.mousePosition.x - 7; if (mouseX < 20) { mouseX = 20; } else if (mouseX > 19 + gradientWidth * (terrain.slopeBlendMaxAngle / 90)) { mouseX = 19 + gradientWidth * (terrain.slopeBlendMaxAngle / 90); } gradientRect.x = mouseX; terrain.slopeBlendMinAngle = ((mouseX - 20) / (gradientWidth + 1)) * 90; } else { gradientRect.x = 20 + gradientWidth * (terrain.slopeBlendMinAngle / 90); } if (Event.current.type == EventType.MouseDown && gradientRect.Contains(Event.current.mousePosition)) { dragControl = "slopeStop1"; } if (dragControl == "slopeStop1" && Event.current.type == EventType.MouseUp) { dragControl = ""; } GUI.Box(gradientRect, "", "slopeStop1"); // Slope stop 2... if (dragControl == "slopeStop2" && Event.current.type == EventType.MouseDrag) { mouseX = Event.current.mousePosition.x - 7; if (mouseX < 21 + gradientWidth * (terrain.slopeBlendMinAngle / 90)) { mouseX = 21 + gradientWidth * (terrain.slopeBlendMinAngle / 90); } else if (mouseX > 21 + gradientWidth) { mouseX = 21 + gradientWidth; } gradientRect.x = mouseX; terrain.slopeBlendMaxAngle = ((mouseX - 20) / (gradientWidth + 1)) * 90; } else { gradientRect.x = 20 + gradientWidth * (terrain.slopeBlendMaxAngle / 90); } if (Event.current.type == EventType.MouseDown && gradientRect.Contains(Event.current.mousePosition)) { dragControl = "slopeStop2"; } if (dragControl == "slopeStop2" && Event.current.type == EventType.MouseUp) { dragControl = ""; } GUI.Box(gradientRect, "", "slopeStop2"); gradientRect.y += 19; gradientRect.width = gradientWidth * (terrain.slopeBlendMinAngle / 90); gradientRect.x = 27; GUI.Box(gradientRect, "", "black"); gradientRect.width = gradientWidth * ((terrain.slopeBlendMaxAngle / 90) - (terrain.slopeBlendMinAngle / 90)); gradientRect.x = 27 + gradientWidth * (terrain.slopeBlendMinAngle / 90); GUI.Box(gradientRect, "", "blackToWhite"); gradientRect.width = gradientWidth - gradientWidth * (terrain.slopeBlendMaxAngle / 90); gradientRect.x = 27 + gradientWidth * (terrain.slopeBlendMaxAngle / 90); GUI.Box(gradientRect, "", "white"); GUI.skin = null; EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Cliff start"); terrain.slopeBlendMinAngle = EditorGUILayout.FloatField(terrain.slopeBlendMinAngle); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Cliff end"); terrain.slopeBlendMaxAngle = EditorGUILayout.FloatField(terrain.slopeBlendMaxAngle); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUI.skin = terrain.guiSkin; GUILayout.Label("Texture Height"); GUI.skin = null; EditorGUILayout.EndHorizontal(); gradientRect = EditorGUILayout.BeginHorizontal(); gradientWidth = gradientRect.width - 55; gradientRect.width = 15; gradientRect.height = 19; Rect gradientRect2 = gradientRect; gradientRect2.y += 19; GUI.skin = terrain.guiSkin; string[] gradientStyles = new string[9]; gradientStyles[0] = "red"; gradientStyles[1] = "redToYellow"; gradientStyles[2] = "yellow"; gradientStyles[3] = "yellowToGreen"; gradientStyles[4] = "green"; gradientStyles[5] = "greenToCyan"; gradientStyles[6] = "cyan"; gradientStyles[7] = "cyanToBlue"; gradientStyles[8] = "blue"; List<float> heightBlendPoints = terrain.heightBlendPoints; int numPoints = heightBlendPoints.Count; float firstLimit = 1; if (numPoints > 0) { firstLimit = (float) heightBlendPoints[0]; } else { gradientRect.x = 20; GUI.Box(gradientRect, "", "greyStop"); gradientRect.x = 20 + gradientWidth; GUI.Box(gradientRect, "", "greyStop"); } gradientRect2.width = gradientWidth * firstLimit; gradientRect2.x = 27; if (terrain.splatPrototypes.Length < 2) { GUI.Box(gradientRect2, "", "grey"); } else { GUI.Box(gradientRect2, "", "red"); } for (i = 0; i < numPoints; i++) { // Height stop... float lowerLimit = 0; float upperLimit = 1; if (i > 0) { lowerLimit = (float) heightBlendPoints[i - 1]; } if (i < numPoints - 1) { upperLimit = (float) heightBlendPoints[i + 1]; } if (dragControl == "heightStop"+i && Event.current.type == EventType.MouseDrag) { mouseX = Event.current.mousePosition.x - 7; if (mouseX < 20 + gradientWidth * lowerLimit) { mouseX = 20 + gradientWidth * lowerLimit; } else if (mouseX > 19 + gradientWidth * upperLimit) { mouseX = 19 + gradientWidth * upperLimit; } gradientRect.x = mouseX; heightBlendPoints[i] = (mouseX - 20) / (gradientWidth + 1); } else { gradientRect.x = 20 + gradientWidth * (float) heightBlendPoints[i]; } if (Event.current.type == EventType.MouseDown && gradientRect.Contains(Event.current.mousePosition)) { dragControl = "heightStop"+i; } if (dragControl == "heightStop"+i && Event.current.type == EventType.MouseUp) { dragControl = ""; } int stopNum = (int) Mathf.Ceil((float) i / 2) + 1; if (i % 2 == 0) { GUI.Box(gradientRect, ""+stopNum, "blackStop"); } else { GUI.Box(gradientRect, ""+stopNum, "whiteStop"); } gradientRect2.width = gradientWidth * (upperLimit - (float) heightBlendPoints[i]); gradientRect2.x = 27 + gradientWidth * (float) heightBlendPoints[i]; GUI.Box(gradientRect2, "", gradientStyles[i + 1]); } GUI.skin = null; EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); string startOrEnd = "end"; for (i = 0; i < numPoints; i++) { EditorGUILayout.BeginHorizontal(); int floatFieldNum = (int) Mathf.Ceil((float) i / 2) + 1; EditorGUILayout.PrefixLabel("Texture "+floatFieldNum+" "+startOrEnd); heightBlendPoints[i] = EditorGUILayout.FloatField((float) heightBlendPoints[i]); EditorGUILayout.EndHorizontal(); if (startOrEnd == "end") { startOrEnd = "start"; } else { startOrEnd = "end"; } } terrain.heightBlendPoints = heightBlendPoints; EditorGUILayout.BeginHorizontal(); GUI.skin = terrain.guiSkin; GUILayout.Label("Textures"); GUI.skin = null; EditorGUILayout.EndHorizontal(); int nTextures = 0; EditorGUILayout.Separator(); if (GUI.changed) { EditorUtility.SetDirty(terrain); } GUI.changed = false; EditorGUILayout.BeginHorizontal(); EditorGUIUtility.LookLikeControls(80, 0); foreach (SplatPrototype splatPrototype in terrain.splatPrototypes) { Rect textureRect = EditorGUILayout.BeginHorizontal(); if (nTextures == 0) { splatPrototype.texture = EditorGUILayout.ObjectField("Cliff texture", splatPrototype.texture, typeof(Texture2D), false) as Texture2D; } else { splatPrototype.texture = EditorGUILayout.ObjectField("Texture "+nTextures, splatPrototype.texture, typeof(Texture2D), false) as Texture2D; } GUI.skin = terrain.guiSkin; textureRect.x += 146; textureRect.width = 18; textureRect.height = 18; if (GUI.Button(textureRect, "", "deleteButton")) { GUI.changed = true; terrain.deleteSplatPrototype(terrain.tempTexture, nTextures); EditorUtility.SetDirty(terrain); } GUI.skin = null; EditorGUILayout.EndHorizontal(); if (nTextures % 2 == 1) { EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); } nTextures++; if (nTextures > 5) { break; } } EditorGUIUtility.LookLikeControls(); EditorGUILayout.EndHorizontal(); if (GUI.changed) { terData.splatPrototypes = terrain.splatPrototypes; } if (nTextures == 0 && !assignTexture) { EditorGUILayout.BeginHorizontal(); GUI.skin = terrain.guiSkin; GUILayout.Label("No textures have been assigned! Assign a texture.", "errorText"); GUI.skin = null; EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); } if (nTextures < 6) { EditorGUILayout.Separator(); buttonRect = EditorGUILayout.BeginHorizontal(); buttonRect.x = buttonRect.width / 2 - 50; buttonRect.width = 100; buttonRect.height = 18; if (GUI.Button(buttonRect, "Add texture")) { terrain.addSplatPrototype(terrain.defaultTexture, nTextures); terData.splatPrototypes = terrain.splatPrototypes; EditorUtility.SetDirty(terrain); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); } EditorGUILayout.Separator(); buttonRect = EditorGUILayout.BeginHorizontal(); buttonRect.x = buttonRect.width / 2 - 100; buttonRect.width = 200; buttonRect.height = 18; GUI.skin = terrain.guiSkin; if (nTextures < 2) { GUI.Box(buttonRect, "Apply procedural texture", "disabledButton"); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("This feature is disabled! You must assign at least 2 textures.", "errorText"); } else { if (GUI.Button(buttonRect, "Apply procedural texture")) { // Undo not supported! TerrainToolkit.TextureProgressDelegate textureProgressDelegate = new TerrainToolkit.TextureProgressDelegate(updateTextureProgress); terrain.textureTerrain(textureProgressDelegate); EditorUtility.ClearProgressBar(); GUIUtility.ExitGUI(); } } GUI.skin = null; EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); drawAdvancedSettingsGUI(); // If the user has added or removed textures in the Terrain component, correct the number of blend points... if (Event.current.type == EventType.Repaint) { if (numPoints % 2 != 0) { terrain.deleteAllBlendPoints(); } int correctNumPoints = (nTextures - 2) * 2; if (nTextures < 3) { correctNumPoints = 0; } if (numPoints < correctNumPoints) { terrain.addBlendPoints(); } else if (numPoints > correctNumPoints) { terrain.deleteBlendPoints(); } } }
private void Start() { tk = FindObjectOfType <TerrainToolkit>(); }
private float[,] windErosion(float[,] heightMap, Vector2 arraySize, int iterations, TerrainToolkit.ErosionProgressDelegate erosionProgressDelegate) { int num; int num1; int num2; int num3; int num4; int num5; int j; int i; float single; float single1; TerrainData component = ((Terrain)base.GetComponent(typeof(Terrain))).terrainData; Quaternion quaternion = Quaternion.Euler(0f, this.windDirection + 180f, 0f); Vector3 vector3 = quaternion * Vector3.forward; int num6 = (int)arraySize.x; int num7 = (int)arraySize.y; float[,] singleArray = new float[num6, num7]; float[,] singleArray1 = new float[num6, num7]; float[,] singleArray2 = new float[num6, num7]; float[,] singleArray3 = new float[num6, num7]; float[,] singleArray4 = new float[num6, num7]; float[,] singleArray5 = new float[num6, num7]; float[,] singleArray6 = new float[num6, num7]; for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { singleArray[j, i] = 0f; singleArray1[j, i] = 0f; singleArray2[j, i] = 0f; singleArray3[j, i] = 0f; singleArray4[j, i] = 0f; singleArray5[j, i] = 0f; singleArray6[j, i] = 0f; } } for (int k = 0; k < iterations; k++) { for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { single1 = singleArray2[j, i]; float single2 = heightMap[j, i]; float single3 = singleArray4[j, i]; float single4 = single3 * this.windGravity; singleArray4[j, i] = single3 - single4; heightMap[j, i] = single2 + single4; } } for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { float single5 = heightMap[j, i]; Vector3 interpolatedNormal = component.GetInterpolatedNormal((float)j / (float)num6, (float)i / (float)num7); float single6 = (Vector3.Angle(interpolatedNormal, vector3) - 90f) / 90f; if (single6 < 0f) { single6 = 0f; } singleArray[j, i] = single6 * single5; float single7 = 1f - Mathf.Abs(Vector3.Angle(interpolatedNormal, vector3) - 90f) / 90f; singleArray1[j, i] = single7 * single5; float single8 = single7 * single5 * this.windForce; float single9 = singleArray2[j, i] + single8; singleArray2[j, i] = single9; single = singleArray4[j, i]; float single10 = this.windLift * single9; if (single + single10 > this.windCapacity) { single10 = this.windCapacity - single; } singleArray4[j, i] = single + single10; heightMap[j, i] = single5 - single10; } } for (i = 0; i < num7; i++) { if (i == 0) { num1 = 2; num3 = 0; num5 = 0; } else if (i != num7 - 1) { num1 = 3; num3 = -1; num5 = 1; } else { num1 = 2; num3 = -1; num5 = 1; } for (j = 0; j < num6; j++) { if (j == 0) { num = 2; num2 = 0; num4 = 0; } else if (j != num6 - 1) { num = 3; num2 = -1; num4 = 1; } else { num = 2; num2 = -1; num4 = 1; } float single11 = singleArray1[j, i]; float single12 = singleArray[j, i]; single = singleArray4[j, i]; for (int l = 0; l < num1; l++) { for (int m = 0; m < num; m++) { if ((m != num4 || l != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (m == num4 || l == num5))) { Vector3 vector31 = new Vector3((float)(m + num2), 0f, (float)(-1 * (l + num3))); float single13 = (90f - Vector3.Angle(vector31, vector3)) / 90f; if (single13 < 0f) { single13 = 0f; } float single14 = singleArray3[j + m + num2, i + l + num3]; float single15 = single13 * (single11 - single12) * 0.1f; if (single15 < 0f) { single15 = 0f; } float single16 = single14 + single15; singleArray3[j + m + num2, i + l + num3] = single16; float single17 = singleArray3[j, i]; singleArray3[j, i] = single17 - single15; float single18 = singleArray5[j + m + num2, i + l + num3]; float single19 = single * single15; float single20 = single18 + single19; singleArray5[j + m + num2, i + l + num3] = single20; float single21 = singleArray5[j, i]; singleArray5[j, i] = single21 - single19; } } } } } for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { float single22 = singleArray4[j, i] + singleArray5[j, i]; if (single22 > 1f) { single22 = 1f; } else if (single22 < 0f) { single22 = 0f; } singleArray4[j, i] = single22; singleArray5[j, i] = 0f; } } for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { single1 = singleArray2[j, i] + singleArray3[j, i]; single1 = single1 * (1f - this.windEntropy); if (single1 > 1f) { single1 = 1f; } else if (single1 < 0f) { single1 = 0f; } singleArray2[j, i] = single1; singleArray3[j, i] = 0f; } } this.smoothIterations = 1; this.smoothBlend = 0.25f; float[,] singleArray7 = (float[,])heightMap.Clone(); TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate = new TerrainToolkit.GeneratorProgressDelegate(this.dummyGeneratorProgress); singleArray7 = this.smooth(singleArray7, arraySize, generatorProgressDelegate); for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { float single23 = heightMap[j, i]; float single24 = singleArray7[j, i]; float single25 = singleArray[j, i] * this.windSmoothing; float single26 = single24 * single25 + single23 * (1f - single25); heightMap[j, i] = single26; } } float single27 = (float)k / (float)iterations; erosionProgressDelegate("Applying Wind Erosion", "Applying wind erosion.", k, iterations, single27); } return heightMap; }
public voronoiPresetData(string pn, TerrainToolkit.VoronoiType vt, int c, float vf, float vs, float vb) { this.presetName = pn; this.voronoiType = vt; this.voronoiCells = c; this.voronoiFeatures = vf; this.voronoiScale = vs; this.voronoiBlend = vb; }
private float[,] fullHydraulicErosion(float[,] heightMap, Vector2 arraySize, int iterations, TerrainToolkit.ErosionProgressDelegate erosionProgressDelegate) { int j; int i; int num; int num1; int num2; int num3; int num4; int num5; int m; int l; float single; float single1; float single2; float single3; float single4; float single5; int num6 = (int)arraySize.x; int num7 = (int)arraySize.y; float[,] singleArray = new float[num6, num7]; float[,] singleArray1 = new float[num6, num7]; float[,] singleArray2 = new float[num6, num7]; float[,] singleArray3 = new float[num6, num7]; for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { singleArray[j, i] = 0f; singleArray1[j, i] = 0f; singleArray2[j, i] = 0f; singleArray3[j, i] = 0f; } } for (int k = 0; k < iterations; k++) { for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { float single6 = singleArray[j, i] + this.hydraulicRainfall; if (single6 > 1f) { single6 = 1f; } singleArray[j, i] = single6; } } for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { float single7 = singleArray2[j, i]; single3 = singleArray[j, i] * this.hydraulicSedimentSaturation; if (single7 < single3) { float single8 = singleArray[j, i] * this.hydraulicSedimentSolubility; if (single7 + single8 > single3) { single8 = single3 - single7; } single1 = heightMap[j, i]; if (single8 > single1) { single8 = single1; } singleArray2[j, i] = single7 + single8; heightMap[j, i] = single1 - single8; } } } for (i = 0; i < num7; i++) { if (i == 0) { num1 = 2; num3 = 0; num5 = 0; } else if (i != num7 - 1) { num1 = 3; num3 = -1; num5 = 1; } else { num1 = 2; num3 = -1; num5 = 1; } for (j = 0; j < num6; j++) { if (j == 0) { num = 2; num2 = 0; num4 = 0; } else if (j != num6 - 1) { num = 3; num2 = -1; num4 = 1; } else { num = 2; num2 = -1; num4 = 1; } float single9 = 0f; float single10 = 0f; single1 = heightMap[j + num4 + num2, i + num5 + num3]; float single11 = singleArray[j + num4 + num2, i + num5 + num3]; float single12 = single1; int num8 = 0; for (l = 0; l < num1; l++) { for (m = 0; m < num; m++) { if ((m != num4 || l != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (m == num4 || l == num5))) { single2 = heightMap[j + m + num2, i + l + num3]; single5 = singleArray[j + m + num2, i + l + num3]; single = single1 + single11 - (single2 + single5); if (single > 0f) { single9 = single9 + single; single12 = single12 + (single2 + single5); num8++; if (single > single10) { single = single10; } } } } } float single13 = single12 / (float)(num8 + 1); float single14 = single1 + single11 - single13; float single15 = Mathf.Min(single11, single14); float single16 = singleArray1[j + num4 + num2, i + num5 + num3]; float single17 = single16 - single15; singleArray1[j + num4 + num2, i + num5 + num3] = single17; float single18 = singleArray2[j + num4 + num2, i + num5 + num3]; float single19 = single18 * (single15 / single11); float single20 = singleArray3[j + num4 + num2, i + num5 + num3]; float single21 = single20 - single19; singleArray3[j + num4 + num2, i + num5 + num3] = single21; for (l = 0; l < num1; l++) { for (m = 0; m < num; m++) { if ((m != num4 || l != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (m == num4 || l == num5))) { single2 = heightMap[j + m + num2, i + l + num3]; single5 = singleArray[j + m + num2, i + l + num3]; single = single1 + single11 - (single2 + single5); if (single > 0f) { float single22 = singleArray1[j + m + num2, i + l + num3]; float single23 = single22 + single15 * (single / single9); singleArray1[j + m + num2, i + l + num3] = single23; float single24 = singleArray3[j + m + num2, i + l + num3]; float single25 = single24 + single19 * (single / single9); singleArray3[j + m + num2, i + l + num3] = single25; } } } } } } for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { float single26 = singleArray[j, i] + singleArray1[j, i]; single26 = single26 - single26 * this.hydraulicEvaporation; if (single26 < 0f) { single26 = 0f; } singleArray[j, i] = single26; singleArray1[j, i] = 0f; } } for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { single4 = singleArray2[j, i] + singleArray3[j, i]; if (single4 > 1f) { single4 = 1f; } else if (single4 < 0f) { single4 = 0f; } singleArray2[j, i] = single4; singleArray3[j, i] = 0f; } } for (i = 0; i < num7; i++) { for (j = 0; j < num6; j++) { single3 = singleArray[j, i] * this.hydraulicSedimentSaturation; single4 = singleArray2[j, i]; if (single4 > single3) { float single27 = single4 - single3; singleArray2[j, i] = single3; float single28 = heightMap[j, i]; heightMap[j, i] = single28 + single27; } } } float single29 = (float)k / (float)iterations; erosionProgressDelegate("Applying Hydraulic Erosion", "Applying hydraulic erosion.", k, iterations, single29); } return heightMap; }
public void generateTerrain(TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate) { this.convertIntVarsToEnums(); Terrain component = (Terrain)base.GetComponent(typeof(Terrain)); if (component == null) { return; } TerrainData terrainDatum = component.terrainData; int num = terrainDatum.heightmapWidth; int num1 = terrainDatum.heightmapHeight; float[,] heights = terrainDatum.GetHeights(0, 0, num, num1); float[,] singleArray = (float[,])heights.Clone(); switch (this.generatorType) { case TerrainToolkit.GeneratorType.Voronoi: { singleArray = this.generateVoronoi(singleArray, new Vector2((float)num, (float)num1), generatorProgressDelegate); break; } case TerrainToolkit.GeneratorType.DiamondSquare: { singleArray = this.generateDiamondSquare(singleArray, new Vector2((float)num, (float)num1), generatorProgressDelegate); break; } case TerrainToolkit.GeneratorType.Perlin: { singleArray = this.generatePerlin(singleArray, new Vector2((float)num, (float)num1), generatorProgressDelegate); break; } case TerrainToolkit.GeneratorType.Smooth: { singleArray = this.smooth(singleArray, new Vector2((float)num, (float)num1), generatorProgressDelegate); break; } case TerrainToolkit.GeneratorType.Normalise: { singleArray = this.normalise(singleArray, new Vector2((float)num, (float)num1), generatorProgressDelegate); break; } default: { return; } } for (int i = 0; i < num1; i++) { for (int j = 0; j < num; j++) { float single = heights[j, i]; float single1 = singleArray[j, i]; float single2 = 0f; switch (this.generatorType) { case TerrainToolkit.GeneratorType.Voronoi: { single2 = single1 * this.voronoiBlend + single * (1f - this.voronoiBlend); break; } case TerrainToolkit.GeneratorType.DiamondSquare: { single2 = single1 * this.diamondSquareBlend + single * (1f - this.diamondSquareBlend); break; } case TerrainToolkit.GeneratorType.Perlin: { single2 = single1 * this.perlinBlend + single * (1f - this.perlinBlend); break; } case TerrainToolkit.GeneratorType.Smooth: { single2 = single1 * this.smoothBlend + single * (1f - this.smoothBlend); break; } case TerrainToolkit.GeneratorType.Normalise: { single2 = single1 * this.normaliseBlend + single * (1f - this.normaliseBlend); break; } } heights[j, i] = single2; } } terrainDatum.SetHeights(0, 0, heights); }
private float[,] generateDiamondSquare(float[,] heightMap, Vector2 arraySize, TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate) { int num = (int)arraySize.x; int num1 = (int)arraySize.y; float single = 1f; int num2 = num - 1; heightMap[0, 0] = 0.5f; heightMap[num - 1, 0] = 0.5f; heightMap[0, num1 - 1] = 0.5f; heightMap[num - 1, num1 - 1] = 0.5f; generatorProgressDelegate("Fractal Generator", "Generating height map. Please wait.", 0f); while (num2 > 1) { for (int i = 0; i < num - 1; i = i + num2) { for (int j = 0; j < num1 - 1; j = j + num2) { int num3 = i + (num2 >> 1); int num4 = j + (num2 >> 1); Vector2[] vector2 = new Vector2[] { new Vector2((float)i, (float)j), new Vector2((float)(i + num2), (float)j), new Vector2((float)i, (float)(j + num2)), new Vector2((float)(i + num2), (float)(j + num2)) }; this.dsCalculateHeight(heightMap, arraySize, num3, num4, vector2, single); } } for (int k = 0; k < num - 1; k = k + num2) { for (int l = 0; l < num1 - 1; l = l + num2) { int num5 = num2 >> 1; int num6 = k + num5; int num7 = l; int num8 = k; int num9 = l + num5; Vector2[] vector2Array = new Vector2[] { new Vector2((float)(num6 - num5), (float)num7), new Vector2((float)num6, (float)(num7 - num5)), new Vector2((float)(num6 + num5), (float)num7), new Vector2((float)num6, (float)(num7 + num5)) }; Vector2[] vector21 = new Vector2[] { new Vector2((float)(num8 - num5), (float)num9), new Vector2((float)num8, (float)(num9 - num5)), new Vector2((float)(num8 + num5), (float)num9), new Vector2((float)num8, (float)(num9 + num5)) }; this.dsCalculateHeight(heightMap, arraySize, num6, num7, vector2Array, single); this.dsCalculateHeight(heightMap, arraySize, num8, num9, vector21, single); } } single = single * this.diamondSquareDelta; num2 = num2 >> 1; } generatorProgressDelegate("Fractal Generator", "Generating height map. Please wait.", 1f); return heightMap; }
public void setFractalPreset(TerrainToolkit.fractalPresetData preset) { this.generatorTypeInt = 1; this.generatorType = TerrainToolkit.GeneratorType.DiamondSquare; this.diamondSquareDelta = preset.diamondSquareDelta; this.diamondSquareBlend = preset.diamondSquareBlend; }
private float[,] generatePerlin(float[,] heightMap, Vector2 arraySize, TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate) { int k; int num = (int)arraySize.x; int num1 = (int)arraySize.y; for (int i = 0; i < num1; i++) { for (int j = 0; j < num; j++) { heightMap[j, i] = 0f; } } TerrainToolkit.PerlinNoise2D[] perlinNoise2D = new TerrainToolkit.PerlinNoise2D[this.perlinOctaves]; int num2 = this.perlinFrequency; float single = 1f; for (k = 0; k < this.perlinOctaves; k++) { perlinNoise2D[k] = new TerrainToolkit.PerlinNoise2D(num2, single); num2 = num2 * 2; single = single / 2f; } for (k = 0; k < this.perlinOctaves; k++) { double frequency = (double)((float)num / (float)perlinNoise2D[k].Frequency); double frequency1 = (double)((float)num1 / (float)perlinNoise2D[k].Frequency); for (int l = 0; l < num; l++) { for (int m = 0; m < num1; m++) { int num3 = (int)((double)l / frequency); int num4 = num3 + 1; int num5 = (int)((double)m / frequency1); int num6 = num5 + 1; double interpolatedPoint = perlinNoise2D[k].getInterpolatedPoint(num3, num4, num5, num6, (double)l / frequency - (double)num3, (double)m / frequency1 - (double)num5); heightMap[l, m] = heightMap[l, m] + (float)(interpolatedPoint * (double)perlinNoise2D[k].Amplitude); } } float single1 = (float)((k + 1) / this.perlinOctaves); generatorProgressDelegate("Perlin Generator", "Generating height map. Please wait.", single1); } TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate1 = new TerrainToolkit.GeneratorProgressDelegate(this.dummyGeneratorProgress); float single2 = this.normaliseMin; float single3 = this.normaliseMax; float single4 = this.normaliseBlend; this.normaliseMin = 0f; this.normaliseMax = 1f; this.normaliseBlend = 1f; heightMap = this.normalise(heightMap, arraySize, generatorProgressDelegate1); this.normaliseMin = single2; this.normaliseMax = single3; this.normaliseBlend = single4; for (int n = 0; n < num; n++) { for (int o = 0; o < num1; o++) { heightMap[n, o] = heightMap[n, o] * this.perlinAmplitude; } } for (k = 0; k < this.perlinOctaves; k++) { perlinNoise2D[k] = null; } perlinNoise2D = null; return heightMap; }
public void setPerlinPreset(TerrainToolkit.perlinPresetData preset) { this.generatorTypeInt = 2; this.generatorType = TerrainToolkit.GeneratorType.Perlin; this.perlinFrequency = preset.perlinFrequency; this.perlinAmplitude = preset.perlinAmplitude; this.perlinOctaves = preset.perlinOctaves; this.perlinBlend = preset.perlinBlend; }
private float[,] generateVoronoi(float[,] heightMap, Vector2 arraySize, TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate) { int i; int k; int j; float single; int num = (int)arraySize.x; int num1 = (int)arraySize.y; ArrayList arrayLists = new ArrayList(); for (i = 0; i < this.voronoiCells; i++) { TerrainToolkit.Peak vector2 = new TerrainToolkit.Peak(); int num2 = (int)Mathf.Floor(UnityEngine.Random.@value * (float)num); int num3 = (int)Mathf.Floor(UnityEngine.Random.@value * (float)num1); float single1 = UnityEngine.Random.@value; if (UnityEngine.Random.@value > this.voronoiFeatures) { single1 = 0f; } vector2.peakPoint = new Vector2((float)num2, (float)num3); vector2.peakHeight = single1; arrayLists.Add(vector2); } float single2 = 0f; for (j = 0; j < num1; j++) { for (k = 0; k < num; k++) { ArrayList arrayLists1 = new ArrayList(); for (i = 0; i < this.voronoiCells; i++) { Vector2 item = ((TerrainToolkit.Peak)arrayLists[i]).peakPoint; float single3 = Vector2.Distance(item, new Vector2((float)k, (float)j)); TerrainToolkit.PeakDistance peakDistance = new TerrainToolkit.PeakDistance() { id = i, dist = single3 }; arrayLists1.Add(peakDistance); } arrayLists1.Sort(); TerrainToolkit.PeakDistance item1 = (TerrainToolkit.PeakDistance)arrayLists1[0]; TerrainToolkit.PeakDistance peakDistance1 = (TerrainToolkit.PeakDistance)arrayLists1[1]; int num4 = item1.id; float single4 = item1.dist; float single5 = peakDistance1.dist; float single6 = Mathf.Abs(single4 - single5) / ((float)(num + num1) / Mathf.Sqrt((float)this.voronoiCells)); float item2 = (float)((TerrainToolkit.Peak)arrayLists[num4]).peakHeight; float single7 = item2 - Mathf.Abs(single4 / single5) * item2; switch (this.voronoiType) { case TerrainToolkit.VoronoiType.Sine: { single = single7 * 3.14159274f - 1.57079637f; single7 = 0.5f + Mathf.Sin(single) / 2f; break; } case TerrainToolkit.VoronoiType.Tangent: { single = single7 * 3.14159274f / 2f; single7 = 0.5f + Mathf.Tan(single) / 2f; break; } } single7 = single7 * single6 * this.voronoiScale + single7 * (1f - this.voronoiScale); if (single7 < 0f) { single7 = 0f; } else if (single7 > 1f) { single7 = 1f; } heightMap[k, j] = single7; if (single7 > single2) { single2 = single7; } } float single8 = (float)(j * num1); float single9 = (float)(num * num1); generatorProgressDelegate("Voronoi Generator", "Generating height map. Please wait.", single8 / single9); } for (j = 0; j < num1; j++) { for (k = 0; k < num; k++) { float single10 = heightMap[k, j] * (1f / single2); heightMap[k, j] = single10; } } return heightMap; }
public void setTidalErosionPreset(TerrainToolkit.tidalErosionPresetData preset) { this.erosionTypeInt = 2; this.erosionType = TerrainToolkit.ErosionType.Tidal; this.tidalIterations = preset.tidalIterations; this.tidalRangeAmount = preset.tidalRangeAmount; this.tidalCliffLimit = preset.tidalCliffLimit; }
private float[,] normalise(float[,] heightMap, Vector2 arraySize, TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate) { int j; int i; int num = (int)arraySize.x; int num1 = (int)arraySize.y; float single = 0f; float single1 = 1f; generatorProgressDelegate("Normalise Filter", "Normalising height map. Please wait.", 0f); for (i = 0; i < num1; i++) { for (j = 0; j < num; j++) { float single2 = heightMap[j, i]; if (single2 < single1) { single1 = single2; } else if (single2 > single) { single = single2; } } } generatorProgressDelegate("Normalise Filter", "Normalising height map. Please wait.", 0.5f); float single3 = single - single1; float single4 = this.normaliseMax - this.normaliseMin; for (i = 0; i < num1; i++) { for (j = 0; j < num; j++) { float single5 = (heightMap[j, i] - single1) / single3 * single4; heightMap[j, i] = this.normaliseMin + single5; } } generatorProgressDelegate("Normalise Filter", "Normalising height map. Please wait.", 1f); return heightMap; }
public void setVoronoiPreset(TerrainToolkit.voronoiPresetData preset) { this.generatorTypeInt = 0; this.generatorType = TerrainToolkit.GeneratorType.Voronoi; this.voronoiTypeInt = (int)preset.voronoiType; this.voronoiType = preset.voronoiType; this.voronoiCells = preset.voronoiCells; this.voronoiFeatures = preset.voronoiFeatures; this.voronoiScale = preset.voronoiScale; this.voronoiBlend = preset.voronoiBlend; }
private float[,] smooth(float[,] heightMap, Vector2 arraySize, TerrainToolkit.GeneratorProgressDelegate generatorProgressDelegate) { int num; int num1; int num2; int num3; int num4; int num5; int num6 = (int)arraySize.x; int num7 = (int)arraySize.y; for (int i = 0; i < this.smoothIterations; i++) { for (int j = 0; j < num7; j++) { if (j == 0) { num1 = 2; num3 = 0; num5 = 0; } else if (j != num7 - 1) { num1 = 3; num3 = -1; num5 = 1; } else { num1 = 2; num3 = -1; num5 = 1; } for (int k = 0; k < num6; k++) { if (k == 0) { num = 2; num2 = 0; num4 = 0; } else if (k != num6 - 1) { num = 3; num2 = -1; num4 = 1; } else { num = 2; num2 = -1; num4 = 1; } float single = 0f; int num8 = 0; for (int l = 0; l < num1; l++) { for (int m = 0; m < num; m++) { if (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (m == num4 || l == num5)) { float single1 = heightMap[k + m + num2, j + l + num3]; single = single + single1; num8++; } } } float single2 = single / (float)num8; heightMap[k + num4 + num2, j + num5 + num3] = single2; } } float single3 = (float)((i + 1) / this.smoothIterations); generatorProgressDelegate("Smoothing Filter", "Smoothing height map. Please wait.", single3); } return heightMap; }
public void textureTerrain(TerrainToolkit.TextureProgressDelegate textureProgressDelegate) { int num; int num1; int num2; int num3; int num4; int num5; int n; int m; Terrain component = (Terrain)base.GetComponent(typeof(Terrain)); if (component == null) { return; } TerrainData terrainDatum = component.terrainData; this.splatPrototypes = terrainDatum.splatPrototypes; int length = (int)this.splatPrototypes.Length; if (length < 2) { Debug.LogError("Error: You must assign at least 2 textures."); return; } textureProgressDelegate("Procedural Terrain Texture", "Generating height and slope maps. Please wait.", 0.1f); int num6 = terrainDatum.heightmapWidth - 1; int num7 = terrainDatum.heightmapHeight - 1; float[,] singleArray = new float[num6, num7]; float[,] singleArray1 = new float[num6, num7]; terrainDatum.alphamapResolution = num6; float[,,] alphamaps = terrainDatum.GetAlphamaps(0, 0, num6, num6); Vector3 vector3 = terrainDatum.size; float single = vector3.x / (float)num6 * Mathf.Tan(this.slopeBlendMinAngle * 0.0174532924f) / vector3.y; float single1 = vector3.x / (float)num6 * Mathf.Tan(this.slopeBlendMaxAngle * 0.0174532924f) / vector3.y; try { float single2 = 0f; float[,] heights = terrainDatum.GetHeights(0, 0, num6, num7); for (int i = 0; i < num7; i++) { if (i == 0) { num1 = 2; num3 = 0; num5 = 0; } else if (i != num7 - 1) { num1 = 3; num3 = -1; num5 = 1; } else { num1 = 2; num3 = -1; num5 = 1; } for (int j = 0; j < num6; j++) { if (j == 0) { num = 2; num2 = 0; num4 = 0; } else if (j != num6 - 1) { num = 3; num2 = -1; num4 = 1; } else { num = 2; num2 = -1; num4 = 1; } float single3 = heights[j + num4 + num2, i + num5 + num3]; if (single3 > single2) { single2 = single3; } singleArray[j, i] = single3; float single4 = 0f; float single5 = (float)(num * num1 - 1); for (int k = 0; k < num1; k++) { for (int l = 0; l < num; l++) { if (l != num4 || k != num5) { float single6 = Mathf.Abs(single3 - heights[j + l + num2, i + k + num3]); single4 = single4 + single6; } } } singleArray1[j, i] = single4 / single5; } } for (m = 0; m < num7; m++) { for (n = 0; n < num6; n++) { float single7 = singleArray1[n, m]; if (single7 < single) { single7 = 0f; } else if (single7 < single1) { single7 = (single7 - single) / (single1 - single); } else if (single7 > single1) { single7 = 1f; } singleArray1[n, m] = single7; alphamaps[n, m, 0] = single7; } } for (int o = 1; o < length; o++) { for (m = 0; m < num7; m++) { for (n = 0; n < num6; n++) { float item = 0f; float item1 = 0f; float item2 = 1f; float item3 = 1f; float single8 = 0f; if (o > 1) { item = (float)this.heightBlendPoints[o * 2 - 4]; item1 = (float)this.heightBlendPoints[o * 2 - 3]; } if (o < length - 1) { item2 = (float)this.heightBlendPoints[o * 2 - 2]; item3 = (float)this.heightBlendPoints[o * 2 - 1]; } float single9 = singleArray[n, m]; if (single9 >= item1 && single9 <= item2) { single8 = 1f; } else if (single9 >= item && single9 < item1) { single8 = (single9 - item) / (item1 - item); } else if (single9 > item2 && single9 <= item3) { single8 = 1f - (single9 - item2) / (item3 - item2); } single8 = single8 - singleArray1[n, m]; if (single8 < 0f) { single8 = 0f; } alphamaps[n, m, o] = single8; } } } textureProgressDelegate("Procedural Terrain Texture", "Generating splat map. Please wait.", 0.9f); terrainDatum.SetAlphamaps(0, 0, alphamaps); singleArray = null; singleArray1 = null; alphamaps = null; } catch (Exception exception1) { Exception exception = exception1; singleArray = null; singleArray1 = null; alphamaps = null; Debug.LogError(string.Concat("An error occurred: ", exception)); } }
private float[,] velocityHydraulicErosion(float[,] heightMap, Vector2 arraySize, int iterations, TerrainToolkit.ErosionProgressDelegate erosionProgressDelegate) { int j; int i; int num; int num1; int num2; int num3; int num4; int num5; float single; float single1; int l; int k; float single2; float single3; float single4; int num6; float single5; float single6; float single7; float single8; int num7 = (int)arraySize.x; int num8 = (int)arraySize.y; float[,] singleArray = new float[num7, num8]; float[,] singleArray1 = new float[num7, num8]; float[,] singleArray2 = new float[num7, num8]; float[,] singleArray3 = new float[num7, num8]; float[,] singleArray4 = new float[num7, num8]; float[,] singleArray5 = new float[num7, num8]; float[,] singleArray6 = new float[num7, num8]; float[,] singleArray7 = new float[num7, num8]; for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { singleArray2[j, i] = 0f; singleArray3[j, i] = 0f; singleArray4[j, i] = 0f; singleArray5[j, i] = 0f; singleArray6[j, i] = 0f; singleArray7[j, i] = 0f; } } for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { singleArray[j, i] = heightMap[j, i]; } } for (i = 0; i < num8; i++) { if (i == 0) { num1 = 2; num3 = 0; num5 = 0; } else if (i != num8 - 1) { num1 = 3; num3 = -1; num5 = 1; } else { num1 = 2; num3 = -1; num5 = 1; } for (j = 0; j < num7; j++) { if (j == 0) { num = 2; num2 = 0; num4 = 0; } else if (j != num7 - 1) { num = 3; num2 = -1; num4 = 1; } else { num = 2; num2 = -1; num4 = 1; } single1 = 0f; single3 = heightMap[j + num4 + num2, i + num5 + num3]; num6 = 0; for (k = 0; k < num1; k++) { for (l = 0; l < num; l++) { if ((l != num4 || k != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (l == num4 || k == num5))) { single4 = heightMap[j + l + num2, i + k + num3]; single2 = Mathf.Abs(single3 - single4); single1 = single1 + single2; num6++; } } } float single9 = single1 / (float)num6; singleArray1[j + num4 + num2, i + num5 + num3] = single9; } } for (int m = 0; m < iterations; m++) { for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { float single10 = singleArray2[j, i] + singleArray[j, i] * this.hydraulicVelocityRainfall; if (single10 > 1f) { single10 = 1f; } singleArray2[j, i] = single10; } } for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { float single11 = singleArray6[j, i]; single = singleArray2[j, i] * this.hydraulicVelocitySedimentSaturation; if (single11 < single) { float single12 = singleArray2[j, i] * singleArray4[j, i] * this.hydraulicVelocitySedimentSolubility; if (single11 + single12 > single) { single12 = single - single11; } single3 = heightMap[j, i]; if (single12 > single3) { single12 = single3; } singleArray6[j, i] = single11 + single12; heightMap[j, i] = single3 - single12; } } } for (i = 0; i < num8; i++) { if (i == 0) { num1 = 2; num3 = 0; num5 = 0; } else if (i != num8 - 1) { num1 = 3; num3 = -1; num5 = 1; } else { num1 = 2; num3 = -1; num5 = 1; } for (j = 0; j < num7; j++) { if (j == 0) { num = 2; num2 = 0; num4 = 0; } else if (j != num7 - 1) { num = 3; num2 = -1; num4 = 1; } else { num = 2; num2 = -1; num4 = 1; } single1 = 0f; single3 = heightMap[j, i]; float single13 = single3; float single14 = singleArray2[j, i]; num6 = 0; for (k = 0; k < num1; k++) { for (l = 0; l < num; l++) { if ((l != num4 || k != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (l == num4 || k == num5))) { single4 = heightMap[j + l + num2, i + k + num3]; single5 = singleArray2[j + l + num2, i + k + num3]; single2 = single3 + single14 - (single4 + single5); if (single2 > 0f) { single1 = single1 + single2; single13 = single13 + (single3 + single14); num6++; } } } } float single15 = singleArray4[j, i]; float single16 = singleArray1[j, i]; float single17 = singleArray6[j, i]; float single18 = single15 + this.hydraulicVelocity * single16; float single19 = single13 / (float)(num6 + 1); float single20 = single3 + single14 - single19; float single21 = Mathf.Min(single14, single20 * (1f + single15)); float single22 = singleArray3[j, i]; singleArray3[j, i] = single22 - single21; float single23 = single18 * (single21 / single14); float single24 = single17 * (single21 / single14); for (k = 0; k < num1; k++) { for (l = 0; l < num; l++) { if ((l != num4 || k != num5) && (this.neighbourhood == TerrainToolkit.Neighbourhood.Moore || this.neighbourhood == TerrainToolkit.Neighbourhood.VonNeumann && (l == num4 || k == num5))) { single4 = heightMap[j + l + num2, i + k + num3]; single5 = singleArray2[j + l + num2, i + k + num3]; single2 = single3 + single14 - (single4 + single5); if (single2 > 0f) { float single25 = singleArray3[j + l + num2, i + k + num3]; float single26 = single25 + single21 * (single2 / single1); singleArray3[j + l + num2, i + k + num3] = single26; float single27 = singleArray5[j + l + num2, i + k + num3]; float single28 = single23 * this.hydraulicMomentum * (single2 / single1); float single29 = single27 + single28; singleArray5[j + l + num2, i + k + num3] = single29; float single30 = singleArray7[j + l + num2, i + k + num3]; float single31 = single24 * this.hydraulicMomentum * (single2 / single1); float single32 = single30 + single31; singleArray7[j + l + num2, i + k + num3] = single32; } } } } float single33 = singleArray5[j, i]; singleArray5[j, i] = single33 - single23; } } for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { single6 = singleArray4[j, i] + singleArray5[j, i]; single6 = single6 * (1f - this.hydraulicEntropy); if (single6 > 1f) { single6 = 1f; } else if (single6 < 0f) { single6 = 0f; } singleArray4[j, i] = single6; singleArray5[j, i] = 0f; } } for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { float single34 = singleArray2[j, i] + singleArray3[j, i]; single34 = single34 - single34 * this.hydraulicVelocityEvaporation; if (single34 > 1f) { single34 = 1f; } else if (single34 < 0f) { single34 = 0f; } singleArray2[j, i] = single34; singleArray3[j, i] = 0f; } } for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { single7 = singleArray6[j, i] + singleArray7[j, i]; if (single7 > 1f) { single7 = 1f; } else if (single7 < 0f) { single7 = 0f; } singleArray6[j, i] = single7; singleArray7[j, i] = 0f; } } for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { single = singleArray2[j, i] * this.hydraulicVelocitySedimentSaturation; single7 = singleArray6[j, i]; if (single7 > single) { float single35 = single7 - single; singleArray6[j, i] = single; single8 = heightMap[j, i]; heightMap[j, i] = single8 + single35; } } } for (i = 0; i < num8; i++) { for (j = 0; j < num7; j++) { single6 = singleArray2[j, i]; single8 = heightMap[j, i]; float single36 = 1f - Mathf.Abs(0.5f - single8) * 2f; single8 = single8 - this.hydraulicDowncutting * single6 * single36; heightMap[j, i] = single8; } } float single37 = (float)m / (float)iterations; erosionProgressDelegate("Applying Hydraulic Erosion", "Applying hydraulic erosion.", m, iterations, single37); } return heightMap; }