// Class constructor public LBLayerFilter() { this.type = LayerFilterType.Height; this.minHeight = 0f; this.maxHeight = 0.5f; this.heightCurve = LBCurve.SetCurveFromPreset(LBCurve.FilterCurvePreset.WideRange); this.heightCurvePreset = LBCurve.FilterCurvePreset.WideRange; this.minInclination = 0f; this.maxInclination = 30f; this.inclinationCurve = LBCurve.SetCurveFromPreset(LBCurve.FilterCurvePreset.WideRange); this.inclinationCurvePreset = LBCurve.FilterCurvePreset.WideRange; this.map = null; // new Texture2D(1,1); this.mapColour = Color.white; this.mapTolerance = 0; this.mapInverse = false; this.mapToleranceBlendCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); this.smoothRate = 0f; this.lbStencilGUID = string.Empty; this.lbStencilLayerGUID = string.Empty; }
/// <summary> /// Script out the Texture for use in a runtime script. /// TextureIdx is the zero-based position in the terrainTexturesList /// </summary> /// <param name="TextureIdx"></param> /// <param name="EndOfLineMarker"></param> /// <returns></returns> public string ScriptTexture(int TextureIdx, string EndOfLineMarker = "\n") { // Create a new instance of StringBuilder and give it an estimated capacity System.Text.StringBuilder sb = new System.Text.StringBuilder(1000); string eol = " "; // We always need a space between lines OR a end of line marker like "\n" if (EndOfLineMarker.Length > 0) { eol = EndOfLineMarker; } string texInst = "lbTerrainTexture" + (TextureIdx + 1); string texInstAbrev = "Tex" + (TextureIdx + 1); sb.Append("// Texture Code generated from Landscape Builder 2 at " + System.DateTime.Now.ToShortTimeString() + " on " + System.DateTime.Now.ToLongDateString() + eol + eol); sb.Append("// BEGIN Public variables to populate in the editor - Uncomment and add these to top of class " + eol); sb.Append("//[Header(\"Texture" + (TextureIdx + 1) + "\")] " + eol); sb.Append("//public Texture2D texture" + texInstAbrev + "; " + eol); sb.Append("//public Texture2D normalMap" + texInstAbrev + "; " + eol); sb.Append("//public Texture2D heightMap" + texInstAbrev + "; " + eol); sb.Append("//public Texture2D map" + texInstAbrev + "; " + eol); sb.Append("// END Public variables" + eol + eol); sb.Append("#region LBTerrainTexture" + (TextureIdx + 1) + eol); sb.Append(LBCurve.ScriptCurve(mapToleranceBlendCurve, "\n", "mapToleranceBlendCurve" + texInstAbrev)); sb.Append("LBTerrainTexture " + texInst + " = new LBTerrainTexture(); " + eol); sb.Append("if (" + texInst + " != null)" + eol); sb.Append("{" + eol); sb.Append("\t" + texInst + ".texture = texture" + texInstAbrev + "; " + eol); sb.Append("\t" + texInst + ".normalMap = normalMap" + texInstAbrev + "; " + eol); sb.Append("\t" + texInst + ".heightMap = heightMap" + texInstAbrev + "; " + eol); sb.Append("\t" + texInst + ".textureName = " + (string.IsNullOrEmpty(textureName) ? "\"\"" : "\"" + textureName + "\"") + "; " + eol); sb.Append("\t" + texInst + ".normalMapName = " + (string.IsNullOrEmpty(normalMapName) ? "\"\"" : "\"" + normalMapName + "\"") + "; " + eol); sb.Append("\t" + texInst + ".tileSize = new Vector2(" + tileSize.x + ", " + tileSize.y + "); " + eol); sb.Append("\t" + texInst + ".smoothness = " + smoothness + "f; " + eol); sb.Append("\t" + texInst + ".metallic = " + metallic + "f; " + eol); sb.Append("\t" + texInst + ".minHeight = " + minHeight + "f; " + eol); sb.Append("\t" + texInst + ".maxHeight = " + maxHeight + "f; " + eol); sb.Append("\t" + texInst + ".minInclination = " + minInclination + "f; " + eol); sb.Append("\t" + texInst + ".maxInclination = " + maxInclination + "f; " + eol); sb.Append("\t" + texInst + ".strength = " + strength + "f; " + eol); sb.Append("\t" + texInst + ".texturingMode = LBTerrainTexture.TexturingMode." + texturingMode + "; " + eol); sb.Append("\t" + texInst + ".isCurvatureConcave = " + isCurvatureConcave.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".curvatureDistance = " + curvatureDistance + "f; " + eol); sb.Append("\t" + texInst + ".curvatureMinHeightDiff = " + curvatureMinHeightDiff + "f; " + eol); sb.Append("\t" + texInst + ".map = map" + texInstAbrev + "; " + eol); sb.Append("\t" + texInst + ".mapColour = new Color(" + mapColour.r + "f," + mapColour.g + "f," + mapColour.b + "f," + mapColour.a + "f); " + eol); sb.Append("\t" + texInst + ".isDisabled = " + isDisabled.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".mapTolerance = " + mapTolerance + "; " + eol); sb.Append("\t" + texInst + ".useNoise = " + useNoise.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".noiseTileSize = " + noiseTileSize + "f; " + eol); sb.Append("\t" + texInst + ".isMinimalBlendingEnabled = " + isMinimalBlendingEnabled.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".mapInverse = " + mapInverse.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".useAdvancedMapTolerance = " + useAdvancedMapTolerance.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".mapToleranceRed = " + mapToleranceRed + "; " + eol); sb.Append("\t" + texInst + ".mapToleranceGreen = " + mapToleranceGreen + "; " + eol); sb.Append("\t" + texInst + ".mapToleranceBlue = " + mapToleranceBlue + "; " + eol); sb.Append("\t" + texInst + ".mapToleranceAlpha = " + mapToleranceAlpha + "; " + eol); sb.Append("\t" + texInst + ".mapWeightRed = " + mapWeightRed + "f; " + eol); sb.Append("\t" + texInst + ".mapWeightGreen = " + mapWeightGreen + "f; " + eol); sb.Append("\t" + texInst + ".mapWeightBlue = " + mapWeightBlue + "f; " + eol); sb.Append("\t" + texInst + ".mapWeightAlpha = " + mapWeightAlpha + "f; " + eol); sb.Append("\t" + texInst + ".mapToleranceBlendCurvePreset = LBCurve.BlendCurvePreset." + mapToleranceBlendCurvePreset + "; " + eol); sb.Append("\t" + texInst + ".mapToleranceBlendCurve = mapToleranceBlendCurve" + texInstAbrev + "; " + eol); sb.Append("\t" + texInst + ".mapIsPath = " + mapIsPath.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".isTinted = " + isTinted.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".tintColour = new Color(" + tintColour.r + "f," + tintColour.g + "f," + tintColour.b + "f," + tintColour.a + "f); " + eol); sb.Append("\t" + texInst + ".tintStrength = " + tintStrength + "f; " + eol); if (isTinted) { sb.Append("\t" + texInst + ".tintedTexture = LBTextureOperations.TintTexture(texture" + texInstAbrev + ", new Color(" + tintColour.r + "f," + tintColour.g + "f," + tintColour.b + "f," + tintColour.a + "f)," + tintStrength + "f); " + eol); } else { sb.Append("\t" + texInst + ".tintedTexture = null; " + eol); } sb.Append("\t" + texInst + ".isRotated = " + isRotated.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".rotationAngle = " + rotationAngle + "f; " + eol); sb.Append("\t" + texInst + ".rotatedTexture = null; " + eol); sb.Append("\t" + texInst + ".showTexture = " + showTexture.ToString().ToLower() + "; " + eol); sb.Append("\t" + texInst + ".noiseOffset = " + noiseOffset + "f; " + eol); sb.Append("\t" + texInst + ".GUID = " + (string.IsNullOrEmpty(GUID) ? "\"\"" : "\"" + GUID + "\"") + "; " + eol); sb.Append("\t" + texInst + ".blendCurveMode = LBTerrainTexture.BlendCurveMode." + blendCurveMode + "; " + eol); sb.Append("\t" + texInst + ".filterList = new List<LBTextureFilter>(); " + eol); if (filterList != null) { // Create a unique variable if (filterList.Exists(f => f.filterType == LBTextureFilter.FilterType.StencilLayer)) { sb.Append("\tLBTextureFilter lbFilter" + texInstAbrev + " = null; " + eol); } for (int tf = 0; tf < filterList.Count; tf++) { LBTextureFilter lbFilterTexture = filterList[tf]; if (lbFilterTexture != null) { if (lbFilterTexture.filterType == LBTextureFilter.FilterType.StencilLayer) { sb.Append("\tlbFilter" + texInstAbrev + " = LBTextureFilter.CreateFilter(\"" + lbFilterTexture.lbStencilGUID + "\", \"" + lbFilterTexture.lbStencilLayerGUID + "\", false); " + eol); sb.Append("\tif (lbFilter" + texInstAbrev + " != null) " + eol); sb.Append("\t{ " + eol); sb.Append("\t\tlbFilter" + texInstAbrev + ".filterMode = LBTextureFilter.FilterMode." + lbFilterTexture.filterMode + ";" + eol); sb.Append("\t\t" + texInst + ".filterList.Add(lbFilter" + texInstAbrev + "); " + eol); sb.Append("\t} " + eol); sb.Append(eol); } else { sb.Append("\t// Currently we do not output Area filters for runtime Texturing. Contact support or post in our Unity forum if you need this feature." + eol); } } } } sb.Append("\t" + texInst + ".lbTerrainDataList = null; " + eol); sb.Append("\t// NOTE Add the new Texture to the landscape meta-data"); sb.Append(eol); sb.Append("\tlandscape.terrainTexturesList.Add(" + texInst + ");"); sb.Append(eol); sb.Append("}" + eol); sb.Append("#endregion" + eol); sb.Append("// END OF CODE SEGMENT" + eol); return(sb.ToString()); }
// Use this for initialization void Awake() { // This line just gets the starting time of the generation so that the total generation time // can be recorded and displayed float generationStartTime = Time.realtimeSinceStartup; RuntimeSampleHelper.RemoveDefaultCamera(); // Create the terrains and store references to them terrainsList = new List <Terrain>(); for (float tx = 0f; tx < landscapeSize.x - 1f; tx += 2000f) { for (float ty = 0f; ty < landscapeSize.y - 1f; ty += 2000f) { // Create a new gameobject GameObject terrainObj = new GameObject("Runtime Terrain"); // Correctly parent and position the terrain terrainObj.transform.parent = this.transform; terrainObj.transform.localPosition = new Vector3(tx, 0f, ty); // Add a terrain component Terrain newTerrain = terrainObj.AddComponent <Terrain>(); // Set terrain settings (depending on your situtation, you may need to set more or less than I have in this example) newTerrain.heightmapPixelError = 1; newTerrain.basemapDistance = 5000f; newTerrain.treeDistance = 5000f; newTerrain.treeBillboardDistance = 100f; newTerrain.detailObjectDistance = 150f; newTerrain.treeCrossFadeLength = 25f; // Set terrain data settings (same as above comment) TerrainData newTerrainData = new TerrainData(); // One thing to note here is that modfiying the heightmap resolution not only clears all terrai height data, // it also scales up or down the size of the terrain. So you should always set the heightmap resolution // BEFORE you set the terrain size newTerrainData.heightmapResolution = 513; newTerrainData.size = Vector3.one * 2000f; newTerrain.terrainData = newTerrainData; // Set up the terrain collider TerrainCollider newTerrainCol = terrainObj.AddComponent <TerrainCollider>(); newTerrainCol.terrainData = newTerrainData; // Add the terrain to the list of terrains terrainsList.Add(newTerrain); } } // Set the topography noise variables float maskWarpAmount = 0f; float maskNoiseTileSize = 10000f; float maskNoiseOffsetX = 0f; float maskNoiseOffsetY = 0f; AnimationCurve distanceToCentreMask = new AnimationCurve(); int keyInt = distanceToCentreMask.AddKey(0f, 1f); keyInt = distanceToCentreMask.AddKey(0.529f, 0.959f); keyInt = distanceToCentreMask.AddKey(1f, 0f); Keyframe[] curveKeys = distanceToCentreMask.keys; curveKeys[0].inTangent = 0f; curveKeys[0].outTangent = 0f; curveKeys[1].inTangent = -0.25f; curveKeys[1].outTangent = -0.25f; curveKeys[2].inTangent = 0f; curveKeys[2].outTangent = 0f; distanceToCentreMask = new AnimationCurve(curveKeys); AnimationCurve maskNoiseCurveModifier = AnimationCurve.Linear(0f, 0.5f, 1f, 1f); // Avoid warning of keyInt not being used. if (keyInt == 0) { } // Create the terrain topographies for (int t = 0; t < terrainsList.Count; t++) { // Use the LBLandscapeTerrain.PerlinNoiseHeightmap function for value based perlin noise // This example is using the values from the Rolling Hills preset terrainsList[t].terrainData = LBLandscapeTerrain.PerlinNoiseHeightmap(terrainsList[t].terrainData, terrainsList[t].transform.position, 7, 10000f, Vector2.zero, 1f, 2.00f, 0.40f, true, true, 1, 0.5f, 0, LBCurve.SetCurveFromPreset(LBCurve.CurvePreset.None), 1.5f); if (IsMaskingOn) { // Example of applying a mask to the terrain topography terrainsList[t].terrainData = LBLandscapeTerrain.MaskedHeightmap(terrainsList[t].terrainData, terrainsList[t].transform.position, landscapeSize, transform.position, 1, distanceToCentreMask, maskWarpAmount, maskNoiseTileSize, new Vector2(maskNoiseOffsetX, maskNoiseOffsetY), maskNoiseCurveModifier); } } // Create a list of LBTerrainTexture objects // These contain the textures and normal maps but also the rules for applying them to the terrain List <LBTerrainTexture> terrainTexturesList = new List <LBTerrainTexture>(); // Populate the list by creating temporary LBTerrainTexture objects and adjusting their settings, // then adding each one into the list // Grass Hill texture LBTerrainTexture tempTerrainTexture = new LBTerrainTexture(); tempTerrainTexture.texture = grassHillTexture; tempTerrainTexture.normalMap = grassHillNormalMap; tempTerrainTexture.tileSize = Vector2.one * 25f; tempTerrainTexture.minInclination = 0f; tempTerrainTexture.maxInclination = 45f; tempTerrainTexture.useNoise = true; tempTerrainTexture.noiseTileSize = 100f; tempTerrainTexture.texturingMode = LBTerrainTexture.TexturingMode.Inclination; terrainTexturesList.Add(tempTerrainTexture); // Rock Layered texture tempTerrainTexture = new LBTerrainTexture(); tempTerrainTexture.texture = rockLayeredTexture; tempTerrainTexture.normalMap = rockLayeredNormalMap; tempTerrainTexture.tileSize = Vector2.one * 100f; tempTerrainTexture.minInclination = 30f; tempTerrainTexture.maxInclination = 90f; tempTerrainTexture.useNoise = true; tempTerrainTexture.noiseTileSize = 100f; tempTerrainTexture.texturingMode = LBTerrainTexture.TexturingMode.Inclination; terrainTexturesList.Add(tempTerrainTexture); // Texture the terrains for (int t = 0; t < terrainsList.Count; t++) { // Use the LBLandscapeTerrain.TextureTerrain function for texturing the terrain terrainsList[t].terrainData = LBLandscapeTerrain.TextureTerrain(terrainsList[t].terrainData, terrainTexturesList, terrainsList[t].transform.position, landscapeSize, this.transform.position, false, null); } // Display the total time taken to generate the landscape (usually for debugging purposes) Debug.Log("Time taken to generate landscape: " + (Time.realtimeSinceStartup - generationStartTime).ToString("00.00") + " seconds."); }
// Class constructor public LBTerrainTexture() { this.texture = null; this.normalMap = null; this.heightMap = null; this.tileSize = Vector2.one * 25f; this.smoothness = 0f; this.metallic = 0f; this.minHeight = 0.25f; this.maxHeight = 0.75f; this.minInclination = 0f; this.maxInclination = 30f; this.strength = 1f; // v2.0.6 Beta 5a changed default from Height to ConstantInfluence this.texturingMode = TexturingMode.ConstantInfluence; // Added v2.0.7 Beta 6 this.isCurvatureConcave = false; this.curvatureMinHeightDiff = 1f; this.curvatureDistance = 5f; // Added v1.4.2 Beta 5b this.textureName = string.Empty; this.normalMapName = string.Empty; // Added v1.1 Beta 4-9 this.map = null; this.mapColour = UnityEngine.Color.red; this.isDisabled = false; this.mapTolerance = 1; this.useNoise = true; this.noiseTileSize = 100f; // Added v1.2 Beta 3 this.isMinimalBlendingEnabled = false; // Added v1.2 Beta 12 this.mapInverse = false; // Added v1.3.1 Beta 8f this.useAdvancedMapTolerance = false; this.mapToleranceRed = 0; this.mapToleranceGreen = 0; this.mapToleranceBlue = 0; this.mapToleranceAlpha = 0; this.mapWeightRed = 1f; this.mapWeightGreen = 1f; this.mapWeightBlue = 1f; this.mapWeightAlpha = 1f; this.mapToleranceBlendCurvePreset = (LBCurve.BlendCurvePreset)LBCurve.CurvePreset.Cubed; this.mapToleranceBlendCurve = LBCurve.SetCurveFromPreset((LBCurve.CurvePreset) this.mapToleranceBlendCurvePreset); // Added 1.3.2 Beta 5h this.mapIsPath = false; // Added 1.3.2 Beta 2e this.isTinted = false; this.tintColour = UnityEngine.Color.clear; this.tintStrength = 0.5f; this.tintedTexture = null; // Added 1.3.2 Beta 7c this.isRotated = false; this.rotationAngle = 0f; this.rotatedTexture = null; // Added v1.3.0 Beta 3a this.showTexture = true; // Added v1.4.2 Beta 4a this.lbTerrainDataList = null; // Noise offset cannot be modified from the editor as it is randomly set when the terrain is textured // Added v2.0.0 // Assign a unique identifier GUID = System.Guid.NewGuid().ToString(); // Added v2.2.4 blendCurveMode = BlendCurveMode.BlendMinMaxValues; }
// Use this for initialization void Awake() { // This line just gets the starting time of the generation so that the total generation time // can be recorded and displayed float generationStartTime = Time.realtimeSinceStartup; RuntimeSampleHelper.RemoveDefaultCamera(); // Create the terrains and store references to them terrainsList = new List <Terrain>(); for (float tx = 0f; tx < landscapeSize.x - 1f; tx += 2000f) { for (float ty = 0f; ty < landscapeSize.y - 1f; ty += 2000f) { // Create a new gameobject GameObject terrainObj = new GameObject("Runtime Terrain"); // Correctly parent and position the terrain terrainObj.transform.parent = this.transform; terrainObj.transform.localPosition = new Vector3(tx, 0f, ty); // Add a terrain component Terrain newTerrain = terrainObj.AddComponent <Terrain>(); // Set terrain settings (depending on your situtation, you may need to set more or less than I have in this example) newTerrain.heightmapPixelError = 1; newTerrain.basemapDistance = 5000f; newTerrain.treeDistance = 5000f; newTerrain.treeBillboardDistance = 100f; newTerrain.detailObjectDistance = 150f; newTerrain.treeCrossFadeLength = 25f; // Set terrain data settings (same as above comment) TerrainData newTerrainData = new TerrainData(); // One thing to note here is that modfiying the heightmap resolution not only clears all terrai height data, // it also scales up or down the size of the terrain. So you should always set the heightmap resolution // BEFORE you set the terrain size newTerrainData.heightmapResolution = 513; newTerrainData.size = Vector3.one * 2000f; newTerrain.terrainData = newTerrainData; // Set up the terrain collider TerrainCollider newTerrainCol = terrainObj.AddComponent <TerrainCollider>(); newTerrainCol.terrainData = newTerrainData; // Add the terrain to the list of terrains terrainsList.Add(newTerrain); } } // Create the terrain topographies for (int t = 0; t < terrainsList.Count; t++) { // Use the LBLandscapeTerrain.PerlinNoiseHeightmap function for value based perlin noise // This example is using the values from the Mountain Range preset terrainsList[t].terrainData = LBLandscapeTerrain.PerlinNoiseHeightmap(terrainsList[t].terrainData, terrainsList[t].transform.position, 7, 5000f, Vector2.zero, 2f, 1.95f, 0.49f, true, false, 0, 0f, 0, LBCurve.SetCurveFromPreset(LBCurve.CurvePreset.None), 1f); } // Create a list of LBTerrainTexture objects // These contain the textures and normal maps but also the rules for applying them to the terrain List <LBTerrainTexture> terrainTexturesList = new List <LBTerrainTexture>(); // Populate the list by creating temporary LBTerrainTexture objects and adjusting their settings, // then adding each one into the list // Grass Hill texture LBTerrainTexture tempTerrainTexture = new LBTerrainTexture(); tempTerrainTexture.texture = grassHillTexture; tempTerrainTexture.normalMap = grassHillNormalMap; tempTerrainTexture.tileSize = Vector2.one * 25f; tempTerrainTexture.minInclination = 0f; tempTerrainTexture.maxInclination = 45f; tempTerrainTexture.useNoise = true; tempTerrainTexture.noiseTileSize = 100f; tempTerrainTexture.texturingMode = LBTerrainTexture.TexturingMode.Inclination; terrainTexturesList.Add(tempTerrainTexture); // Rock Layered texture tempTerrainTexture = new LBTerrainTexture(); tempTerrainTexture.texture = rockLayeredTexture; tempTerrainTexture.normalMap = rockLayeredNormalMap; tempTerrainTexture.tileSize = Vector2.one * 100f; tempTerrainTexture.minInclination = 30f; tempTerrainTexture.maxInclination = 90f; tempTerrainTexture.useNoise = true; tempTerrainTexture.noiseTileSize = 100f; tempTerrainTexture.texturingMode = LBTerrainTexture.TexturingMode.Inclination; terrainTexturesList.Add(tempTerrainTexture); // Rock1 texture tempTerrainTexture = new LBTerrainTexture(); tempTerrainTexture.texture = rock1Texture; tempTerrainTexture.normalMap = rock1NormalMap; tempTerrainTexture.tileSize = Vector2.one * 100f; tempTerrainTexture.minInclination = 30f; tempTerrainTexture.maxInclination = 60f; tempTerrainTexture.useNoise = true; tempTerrainTexture.noiseTileSize = 100f; tempTerrainTexture.texturingMode = LBTerrainTexture.TexturingMode.Inclination; terrainTexturesList.Add(tempTerrainTexture); // Bot Cliff texture tempTerrainTexture = new LBTerrainTexture(); tempTerrainTexture.texture = botCliffTexture; tempTerrainTexture.normalMap = botCliffNormalMap; tempTerrainTexture.tileSize = Vector2.one * 100f; tempTerrainTexture.strength = 0.01f; tempTerrainTexture.useNoise = false; tempTerrainTexture.noiseTileSize = 100f; tempTerrainTexture.texturingMode = LBTerrainTexture.TexturingMode.ConstantInfluence; terrainTexturesList.Add(tempTerrainTexture); // Texture the terrains for (int t = 0; t < terrainsList.Count; t++) { // Use the LBLandscapeTerrain.TextureTerrain function for texturing the terrain terrainsList[t].terrainData = LBLandscapeTerrain.TextureTerrain(terrainsList[t].terrainData, terrainTexturesList, terrainsList[t].transform.position, landscapeSize, this.transform.position, false, null); } // Display the total time taken to generate the landscape (usually for debugging purposes) Debug.Log("Time taken to generate landscape: " + (Time.realtimeSinceStartup - generationStartTime).ToString("00.00") + " seconds."); }