/// <summary> /// Converts a TerrainLayers array into a Terrain Texture List /// </summary> /// <param name="terrainLayers"></param> /// <returns></returns> public static List <LBTerrainTexture> ToLBTerrainTextureList(TerrainLayer[] terrainLayers) { List <LBTerrainTexture> terrainTextureList = null; int numTerrainLayers = terrainLayers == null ? 0 : terrainLayers.Length; if (numTerrainLayers > 0) { terrainTextureList = new List <LBTerrainTexture>(); //Debug.Log("[DEBUG] numTerrainLayers: " + numTerrainLayers); for (int i = 0; i < terrainLayers.Length; i++) { LBTerrainTexture temp = new LBTerrainTexture(); if (terrainLayers[i] != null) { temp.texture = terrainLayers[i].diffuseTexture; temp.normalMap = terrainLayers[i].normalMapTexture; temp.smoothness = terrainLayers[i].smoothness; temp.metallic = terrainLayers[i].metallic; temp.tileSize = terrainLayers[i].tileSize; } //else //{ // Debug.Log("[DEBUG] terrainLayer: " + i + " is null"); //} terrainTextureList.Add(temp); temp = null; } } return(terrainTextureList); }
/// <summary> /// Converts a Splat Prototype array into a Terrain Texture List /// Added version 1.2 /// </summary> /// <param name="splatPrototypes"></param> /// <returns></returns> public static List <LBTerrainTexture> ToLBTerrainTextureList(SplatPrototype[] splatPrototypes) { List <LBTerrainTexture> terrainTextureList = null; if (splatPrototypes != null) { if (splatPrototypes.Length > 0) { terrainTextureList = new List <LBTerrainTexture>(); for (int i = 0; i < splatPrototypes.Length; i++) { LBTerrainTexture temp = new LBTerrainTexture(); temp.texture = splatPrototypes[i].texture; temp.normalMap = splatPrototypes[i].normalMap; temp.smoothness = splatPrototypes[i].smoothness; temp.metallic = splatPrototypes[i].metallic; temp.tileSize = splatPrototypes[i].tileSize; terrainTextureList.Add(temp); temp = null; } } } return(terrainTextureList); }
/// <summary> /// Get the zero-based index of the texture in the list, given the GUID of the LBTerrainTexture. /// Disabled textures are not counted. /// </summary> /// <param name="terrainTexturesList"></param> /// <returns></returns> public static int GetActiveTextureIndex(List <LBTerrainTexture> terrainTexturesList, string GUID) { int texIndex = -1; int numTex = terrainTexturesList == null ? 0 : terrainTexturesList.Count; LBTerrainTexture lbTerrainTexture = null; if (!string.IsNullOrEmpty(GUID)) { int activeIndex = 0; for (int i = 0; i < numTex; i++) { lbTerrainTexture = terrainTexturesList[i]; //Debug.Log("[DEBUG] Tex " + (i + 1).ToString() + " GUID: " + lbTerrainTexture.GUID); if (!lbTerrainTexture.isDisabled && lbTerrainTexture.texture != null) { if (lbTerrainTexture.GUID == GUID) { texIndex = activeIndex; break; } activeIndex++; } } } return(texIndex); }
/// <summary> /// Constructor to create a clone of a LBFilter instance /// </summary> /// <param name="lbFilter"></param> public LBFilter(LBFilter lbFilter) { this.filterType = lbFilter.filterType; this.filterMode = lbFilter.filterMode; this.areaRect = lbFilter.areaRect; this.showAreaHighlighter = lbFilter.showAreaHighlighter; this.minProximity = lbFilter.minProximity; this.layerMask = lbFilter.layerMask; this.filterByTag = lbFilter.filterByTag; this.terrainTexture = new LBTerrainTexture(lbFilter.terrainTexture); this.lbStencilGUID = lbFilter.lbStencilGUID; this.lbStencilLayerGUID = lbFilter.lbStencilLayerGUID; this.lbBiome = lbFilter.lbBiome; this.cutOff = lbFilter.cutOff; }
/// <summary> /// Get the total number of unique stencil layers of a given resolution within a list of LBTerrainTextures. /// NOTE: Assumes that stencil, stencilLayer and stencilLayerResolution has already been cached in the LBTextureFilter. /// </summary> /// <param name="terrainTextureList"></param> /// <param name="resolution"></param> /// <returns></returns> public static int GetNumStencilLayersByResolution(List <LBTerrainTexture> terrainTextureList, int resolution) { int numUniqueLayers = 0; LBTerrainTexture lbTerrainTexture = null; LBTextureFilter lbTextureFilter = null; int numLBTextures = (terrainTextureList == null ? 0 : terrainTextureList.Count); if (numLBTextures > 0) { // Create with some initial capacity List <string> stencilLayerGUIDList = new List <string>(10); for (int ttIdx = 0; ttIdx < numLBTextures; ttIdx++) { lbTerrainTexture = terrainTextureList[ttIdx]; // Get number of LBTerrainFilters for this LBTerrainTexture int numFilters = lbTerrainTexture.filterList == null ? 0 : lbTerrainTexture.filterList.Count; for (int fIdx = 0; fIdx < numFilters; fIdx++) { lbTextureFilter = lbTerrainTexture.filterList[fIdx]; if (lbTextureFilter != null && lbTextureFilter.filterType == LBTextureFilter.FilterType.StencilLayer && !string.IsNullOrEmpty(lbTextureFilter.lbStencilGUID) && !string.IsNullOrEmpty(lbTextureFilter.lbStencilLayerGUID) && lbTextureFilter.stencilLayerResolution == resolution) { // If it doesn't already exist, add it to the list of unique Stencil Layer GUIDs if (!stencilLayerGUIDList.Exists(guid => guid == lbTextureFilter.lbStencilLayerGUID)) { numUniqueLayers++; stencilLayerGUIDList.Add(lbTextureFilter.lbStencilLayerGUID); //Debug.Log("[DEBUG] GetNumStencilLayersByResolution - Adding " + lbTextureFilter.lbStencilLayerGUID + " resolution: " + resolution); } } } } } return(numUniqueLayers); }
/// <summary> /// Copy LB Texturing tab Textures to MicroSplat. /// Typically called from within the Texturing tab of LB Editor window. /// </summary> /// <param name="landscape"></param> /// <param name="terrainMaterialType"></param> /// <param name="terrainMat"></param> /// <param name="showErrors"></param> public static void MicroSplatCopyTextures(LBLandscape landscape, LBLandscape.TerrainMaterialType terrainMaterialType, Material terrainMat, bool showErrors) { string methodName = "LBEditorIntegration.MicroSplatCopyTextures"; // Basic validation if (landscape == null) { if (showErrors) { Debug.LogWarning(methodName + " - landscape cannot be null"); } } else if (terrainMaterialType != LBLandscape.TerrainMaterialType.MicroSplat) { if (showErrors) { Debug.LogWarning(methodName + " - The Landscape Terrain Settings needs to have a Material Type of MicroSplat. Please set and try again."); } } else if (terrainMat == null) { if (showErrors) { Debug.LogWarning(methodName + " - the landscape does not appear to have a MicroSplat material. Has it been initialised in the Landscape Terrain Settings?"); } } else { // Find the Texture Array Config file //JBooth.MicroSplat.TextureArrayConfig textureArrayConfig = LBEditorHelper.GetAsset<JBooth.MicroSplat.TextureArrayConfig>("MicroSplatData", terrainMat.name.Replace("MicroSplat","MicroSplatConfig") + ".asset"); JBooth.MicroSplat.TextureArrayConfig textureArrayConfig = GetTextureArrayConfig(terrainMat); if (textureArrayConfig == null) { if (showErrors) { Debug.LogWarning("ERROR: " + methodName + " could not find TextureArrayConfig [MicroSplatData/" + terrainMat.name.Replace("MicroSplat", "MicroSplatConfig") + ".asset]"); } } else { // Get existing list of Textures from MicroSplat List <JBooth.MicroSplat.TextureArrayConfig.TextureEntry> textureOldEntryList = textureArrayConfig.sourceTextures; //int numMSTextures = (textureOldEntryList == null ? 0 : textureOldEntryList.Count); int numLBTextures = (landscape.terrainTexturesList == null ? 0 : landscape.terrainTexturesList.Count); LBTerrainTexture lbTrnTex = null; JBooth.MicroSplat.TextureArrayConfig.TextureEntry textureEntry = null; //Debug.Log("[DEBUG] numMSTextures: " + numMSTextures + " numLBTextures:" + numLBTextures); // Create a new list List <JBooth.MicroSplat.TextureArrayConfig.TextureEntry> textureNewEntryList = new List <JBooth.MicroSplat.TextureArrayConfig.TextureEntry>(); // Loop through all the Landscape Builder Textures for (int lbTexIdx = 0; lbTexIdx < numLBTextures; lbTexIdx++) { lbTrnTex = landscape.terrainTexturesList[lbTexIdx]; if (lbTrnTex != null && !lbTrnTex.isDisabled) { // Find matching MicroSplat texture entry textureEntry = textureOldEntryList.Find(te => (lbTrnTex.texture != null && te.diffuse != null && te.diffuse.name == lbTrnTex.texture.name) && (lbTrnTex.normalMap == null && te.normal == null || (lbTrnTex.normalMap != null && te.normal != null && te.normal.name == lbTrnTex.normalMap.name)) && (lbTrnTex.heightMap == null && te.height == null || (lbTrnTex.heightMap != null && te.height != null && te.height.name == lbTrnTex.heightMap.name)) ); //textureEntry = textureOldEntryList.Find(te => lbTrnTex.texture != null && te.diffuse != null && te.diffuse.name == lbTrnTex.texture.name); if (textureEntry != null) { // update tinted texture if required textureEntry.diffuse = lbTrnTex.isTinted ? (lbTrnTex.tintedTexture == null ? lbTrnTex.texture : lbTrnTex.tintedTexture) : lbTrnTex.texture; textureNewEntryList.Add(textureEntry); //Debug.Log("[DEBUG] Added matching entry: " + textureEntry.diffuse.name); } else { // Add missing textures textureEntry = new JBooth.MicroSplat.TextureArrayConfig.TextureEntry(); if (textureEntry != null) { textureEntry.diffuse = lbTrnTex.isTinted ? (lbTrnTex.tintedTexture == null ? lbTrnTex.texture : lbTrnTex.tintedTexture) : lbTrnTex.texture; textureEntry.normal = lbTrnTex.normalMap; textureEntry.height = lbTrnTex.heightMap; textureNewEntryList.Add(textureEntry); //Debug.Log("[DEBUG] Adding new entry: " + lbTrnTex.texture.name); } } // In MicroSplat the first splatprototype sets the default tilesize if (lbTexIdx == 0) { // Convert UVs to MicroSplat tiling Vector3 terrainSize = landscape.GetLandscapeTerrainSize(); // scale, offset (default offset to 0,0) terrainMat.SetVector("_UVScale", new Vector4(1.0f / (lbTrnTex.tileSize.x / terrainSize.x), 1.0f / (lbTrnTex.tileSize.y / terrainSize.z), 0f, 0f)); } //Texture2DArray diff = textureArrayConfig.GetTexture("_Diffuse") as Texture2DArray; } } // Update the list of source textures in MicroSplat textureArrayConfig.sourceTextures = textureNewEntryList; staticMSTextureArrayConfig = textureArrayConfig; // Gets called once only, after all the Inspectors have been updated EditorApplication.delayCall += MicroSplatDelayedCompileConfig; } } }
/// <summary> /// Copy the Landscape textures from LB to MegaSplat /// EDITOR-ONLY /// </summary> /// <param name="landscape"></param> /// <param name="terrainMaterialType"></param> /// <param name="showErrors"></param> public static void MegaSplatCopyTextures(LBLandscape landscape, LBLandscape.TerrainMaterialType terrainMaterialType, bool showErrors) { string methodName = "LBEditorIntegration.MegaSplatCopyTextures"; // Basic validation if (landscape == null) { if (showErrors) { Debug.LogWarning(methodName + " - landscape cannot be null"); } } else if (terrainMaterialType != LBLandscape.TerrainMaterialType.MegaSplat) { if (showErrors) { Debug.LogWarning(methodName + " - The Landscape Terrain Settings needs to have a Material Type of Mega Splat. Please set and try again."); } } else if (landscape.terrainCustomMaterial == null) { if (showErrors) { Debug.LogWarning(methodName + " - the landscape does not appear to have a MegaSplat material. Has it been initialised in the Landscape Terrain Settings?"); } } else { UnityEngine.Object obj = UnityEditor.Selection.activeObject; if (obj != null) { System.Type cfgType = obj.GetType(); System.Type cfgEditorType = null; System.Type TerrainPainterWindowType = null; System.Type ITerrainPainterUtilityType = null; System.Type TerrainToMegaSplatConfigType = null; if (cfgType.FullName == "JBooth.MegaSplat.TextureArrayConfig") { //Debug.Log("MegaSplatCopyTextures cfgType found: " + cfgType.AssemblyQualifiedName); UnityEngine.Object objTerrainToMegaSplatConfig = LBIntegration.MegaSplatCreateTerrainToMegaSplatConfig(landscape, terrainMaterialType, obj, showErrors); // Get the textures from the landscape List <LBTerrainTexture> terrainTextureList = landscape.TerrainTexturesList(); if (terrainTextureList != null) { if (terrainTextureList.Count > 0) { // Add all the non-disabled textures to a list // Previously MegaSplat uses an array of Texture2Ds. Now it has a TextureEntry class // which can hold multiple textures (diffuse, normalmap, heightmap etc) List <JBooth.MegaSplat.TextureArrayConfig.TextureEntry> textureEntryList = new List <JBooth.MegaSplat.TextureArrayConfig.TextureEntry>(); JBooth.MegaSplat.TextureArrayConfig.TextureEntry textureEntry = null; for (int t = 0; t < terrainTextureList.Count; t++) { LBTerrainTexture lbTerrainTexture = terrainTextureList[t]; if (!lbTerrainTexture.isDisabled) { Texture2D texture2D = lbTerrainTexture.texture; if (texture2D != null) { textureEntry = new JBooth.MegaSplat.TextureArrayConfig.TextureEntry(); if (textureEntry != null) { textureEntry.diffuse = texture2D; textureEntry.normal = lbTerrainTexture.normalMap; textureEntry.height = lbTerrainTexture.heightMap; textureEntryList.Add(textureEntry); } } } } try { if (textureEntryList.Count > 0) { cfgEditorType = System.Type.GetType("JBooth.MegaSplat.TextureArrayConfigEditor, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true, true); TerrainPainterWindowType = System.Type.GetType("JBooth.TerrainPainter.TerrainPainterWindow, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true, true); ITerrainPainterUtilityType = System.Type.GetType("JBooth.TerrainPainter.ITerrainPainterUtility, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", true, true); TerrainToMegaSplatConfigType = objTerrainToMegaSplatConfig.GetType(); var cfgEditorWindow = UnityEditor.EditorWindow.GetWindow <UnityEditor.EditorWindow>("Inspector", false); if (cfgEditorType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find TextureArrayConfigEditor editor class. Please Report."); } } else if (TerrainPainterWindowType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find TerrainPainterWindowType editor class. Please Report."); } } else if (ITerrainPainterUtilityType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find ITerrainPainterUtilityType editor class. Please Report."); } } else if (TerrainToMegaSplatConfigType == null) { if (showErrors) { Debug.LogWarning(methodName + " - could not find TerrainToMegaSplatConfigType editor class. Please Report."); } } else { // LB 2.0.6 Beta 7j add compile step back in (was previously broken and had to be done manually in the editor) //string[] shaderFeatures = { "_TERRAIN" }; //LBIntegration.MegaSplatCompileShader(landscape, shaderFeatures, false, true); // Previously MegaSplat uses an array of Texture2Ds. Now it has a TextureEntry class cfgType.GetField("sourceTextures").SetValue(obj, textureEntryList); if (cfgEditorWindow != null) { cfgEditorType.InvokeMember("CompileConfig", System.Reflection.BindingFlags.InvokeMethod, null, null, new object[] { obj }); // Select the landscape in the Hierarchy and open the Terrain Painter window UnityEditor.Selection.activeGameObject = landscape.gameObject; var windowTerrainPainter = UnityEditor.EditorWindow.GetWindow(TerrainPainterWindowType, false); if (windowTerrainPainter == null) { Debug.LogWarning("LBIntegration.MegaSplatCopyTextures - Could not open TerrainPainter window. Please Report."); } else { // Add the TextureArrayConfig to the TerrainToMegaSplatConfig file TerrainToMegaSplatConfigType.InvokeMember("config", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.Public, null, objTerrainToMegaSplatConfig, new object[] { obj }); // Updates the Paint tab in Terrain Painter TerrainPainterWindowType.InvokeMember("config", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { obj }); // Initialise Utilities (else results in a timing issue where Utilities not found first time) TerrainPainterWindowType.InvokeMember("InitPluginUtilities", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { }); // We need to give time for MegaSplat to configure the Texture Array Debug.Log("INFO: Setting up MegaSplat Texture Array..."); // Update "config" field of the Terrain Converter on the Utilities tab IList utilitiesList = (IList)TerrainPainterWindowType.InvokeMember("utilities", System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { }); if (utilitiesList == null) { if (showErrors) { Debug.LogWarning("LBIntegration.MegaSplatCopyTextures - Could not find Utilities. Please Report."); } } else if (utilitiesList != null) { if (utilitiesList.Count == 0) { if (showErrors) { Debug.LogWarning("LBIntegration.MegaSplatCopyTextures - No Utilities found. Please Report."); } } // Located the Terrain To Splat Converter utility foreach (var tPainterInterface in utilitiesList) { if (tPainterInterface.ToString() == "JBooth.MegaSplat.TerrainToSplatConverter") { //Debug.Log("Interface: " + tPainterInterface.GetType().Name); tPainterInterface.GetType().InvokeMember("config", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic, null, tPainterInterface, new object[] { objTerrainToMegaSplatConfig }); int tabIndex = LBIntegration.MegaSplatGetTerrainPainterTabIndex("Utility", true); // Show the Utilities tab TerrainPainterWindowType.InvokeMember("tab", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { tabIndex }); //var terrainJobs = TerrainPainterWindowType.InvokeMember("terrains", System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public, null, windowTerrainPainter, new object[] { }); ////Debug.Log("Calling OnGUI"); //tPainterInterface.GetType().InvokeMember("OnGUI", System.Reflection.BindingFlags.InvokeMethod, null, tPainterInterface, new object[] { terrainJobs }); break; } } } LBIntegration.MegaSplatUpdateShaderSplat(landscape, "Albedo", false, obj, true); } } else { Debug.LogWarning(methodName + " - Could not open TextureArrayConfigEditor window. Please Report."); } } } } catch (System.Exception ex) { if (showErrors) { Debug.LogWarning(methodName + " something has gone wrong (MegaSplat 1.73+ required). Please report. " + ex.Message); } } } } } else { Debug.LogWarning("MegaSplatCopyTextures - Please select the Texture Array Config in the Project window and try again."); } } else { Debug.LogWarning("MegaSplatCopyTextures - Please select the Texture Array Config in the Project window and try again."); } } }
/// <summary> /// Given a LBTerrainTexture instance, attempt to find the matching one in a list. /// It will first attempt to use the GUID, then will attempt the first match based on: /// texture, normalMap, metallic, smoothness, and tileSize. /// WARNING: This will generate garbage (GC) due to FindIndex and string comparison. /// </summary> /// <param name="terrainTexturesList"></param> /// <param name="lbTerrainTexture"></param> /// <returns></returns> public static string GetMatchingTextureGUID(List <LBTerrainTexture> terrainTexturesList, LBTerrainTexture lbTerrainTexture) { if (terrainTexturesList == null || lbTerrainTexture == null) { return(null); } int texIndex = terrainTexturesList.FindIndex(ftx => (!string.IsNullOrEmpty(lbTerrainTexture.GUID) && ftx.GUID == lbTerrainTexture.GUID) || (ftx.texture == lbTerrainTexture.texture && ftx.normalMap == lbTerrainTexture.normalMap && ftx.metallic == lbTerrainTexture.metallic && ftx.smoothness == lbTerrainTexture.smoothness && ftx.tileSize == lbTerrainTexture.tileSize) ); if (texIndex >= 0) { return(terrainTexturesList[texIndex].GUID); } else { return(null); } }
/// <summary> /// Clone Constructor /// </summary> /// <param name="lbTerrainTexture"></param> public LBTerrainTexture(LBTerrainTexture lbTerrainTexture) { this.texture = lbTerrainTexture.texture; this.normalMap = lbTerrainTexture.normalMap; this.heightMap = lbTerrainTexture.heightMap; if (lbTerrainTexture.textureName == null) { this.textureName = string.Empty; } else { this.textureName = lbTerrainTexture.textureName; } if (lbTerrainTexture.normalMapName == null) { this.normalMapName = string.Empty; } else { this.normalMapName = lbTerrainTexture.normalMapName; } this.tileSize = lbTerrainTexture.tileSize; this.smoothness = lbTerrainTexture.smoothness; this.metallic = lbTerrainTexture.metallic; this.minHeight = lbTerrainTexture.minHeight; this.maxHeight = lbTerrainTexture.maxHeight; this.minInclination = lbTerrainTexture.minInclination; this.maxInclination = lbTerrainTexture.maxInclination; this.strength = lbTerrainTexture.strength; this.texturingMode = lbTerrainTexture.texturingMode; this.isCurvatureConcave = lbTerrainTexture.isCurvatureConcave; this.curvatureDistance = lbTerrainTexture.curvatureDistance; this.curvatureMinHeightDiff = lbTerrainTexture.curvatureMinHeightDiff; this.map = lbTerrainTexture.map; this.mapColour = lbTerrainTexture.mapColour; this.isDisabled = lbTerrainTexture.isDisabled; this.mapTolerance = lbTerrainTexture.mapTolerance; this.useNoise = lbTerrainTexture.useNoise; this.noiseTileSize = lbTerrainTexture.noiseTileSize; this.isMinimalBlendingEnabled = lbTerrainTexture.isMinimalBlendingEnabled; this.mapInverse = lbTerrainTexture.mapInverse; this.useAdvancedMapTolerance = lbTerrainTexture.useAdvancedMapTolerance; this.mapToleranceRed = lbTerrainTexture.mapToleranceRed; this.mapToleranceGreen = lbTerrainTexture.mapToleranceGreen; this.mapToleranceBlue = lbTerrainTexture.mapToleranceBlue; this.mapToleranceAlpha = lbTerrainTexture.mapToleranceAlpha; this.mapWeightRed = lbTerrainTexture.mapWeightRed; this.mapWeightGreen = lbTerrainTexture.mapWeightGreen; this.mapWeightBlue = lbTerrainTexture.mapWeightBlue; this.mapWeightAlpha = lbTerrainTexture.mapWeightAlpha; this.mapToleranceBlendCurvePreset = lbTerrainTexture.mapToleranceBlendCurvePreset; this.mapToleranceBlendCurve = lbTerrainTexture.mapToleranceBlendCurve; this.mapIsPath = lbTerrainTexture.mapIsPath; this.isTinted = lbTerrainTexture.isTinted; this.tintColour = lbTerrainTexture.tintColour; this.tintStrength = lbTerrainTexture.tintStrength; this.tintedTexture = lbTerrainTexture.tintedTexture; this.isRotated = lbTerrainTexture.isRotated; this.rotationAngle = lbTerrainTexture.rotationAngle; this.rotatedTexture = lbTerrainTexture.rotatedTexture; this.showTexture = lbTerrainTexture.showTexture; this.noiseOffset = lbTerrainTexture.noiseOffset; if (lbTerrainTexture.filterList != null) { this.filterList = new List <LBTextureFilter>(lbTerrainTexture.filterList); } else { this.filterList = new List <LBTextureFilter>(); } if (lbTerrainTexture.lbTerrainDataList == null) { this.lbTerrainDataList = null; } else { this.lbTerrainDataList = new List <LBTerrainData>(lbTerrainTexture.lbTerrainDataList); } lbTerrainTexture.blendCurveMode = BlendCurveMode.Auto; this.GUID = lbTerrainTexture.GUID; }
public void InitialiseTextureArrays() { isTexturingPresent = LBGroup.IsApplyTexturesPresent(activeGroupList); isObjPathTexturingPresent = LBGroup.IsApplyObjPathTexturesPresent(activeGroupList) && !isGroupDesignerEnabled; // A texture array needs to be size of the sum of all alphamap arrays in each terrain terrainAlphamapResolution = lbGroupParams.landscape.GetLandscapeTerrainAlphaMapResolution(); textureArrayCellsListWidth = numTerrainsWide * terrainAlphamapResolution; totalTextureArrayCells = textureArrayCellsListWidth * textureArrayCellsListWidth; // Texture array: 255 = add highest strength, 0 = add nothing // Find out how many texture arrays we need, then pack them all into a single array // NOTE: This may cause issues for Imported Terrains with different textures in each terrain. totalTextureAdditionArrays = lbGroupParams.landscape.GetNumActiveTerrainTextures(true); textureAdditionArraySize = totalTextureAdditionArrays * totalTextureArrayCells; textureAdditionArray = new byte[textureAdditionArraySize]; // Set defaults for each array for (int i = 0; i < textureAdditionArraySize; i++) { textureAdditionArray[i] = 0; } // Calculate the size in metres of each cell textureArrayCellSize = lbGroupParams.landscape.size.x / textureArrayCellsListWidth; // Initialise texture array variables thisTextureArrayCellIndex = 0; textureArrayCellXCoord = 0; textureArrayCellZCoord = 0; textureAreaRadius = 0; textureAreaNoBlendRadius = 0f; textureAreaCentreXIndex = 0; textureAreaCentreZIndex = 0; textureAreaMinXIndex = 0; textureAreaMaxXIndex = 0; textureAreaMinZIndex = 0; textureAreaMaxZIndex = 0; textureAdditionArrayIndexShift = 0; // Initialise texture placement variables texturePlacementDist = 0f; textureBlendFactor = 0f; terrainTextureList = lbGroupParams.landscape.TerrainTexturesList(); terrainTextureListSize = terrainTextureList == null ? 0 : terrainTextureList.Count; txIdx = 0; // The Group-level Tex option tab contains GUIDs that reference LBTerrainTexture instances in the // landscape class terrainTexturesList. These are LBTerrainTexture instances that have been applied // to the landscape. Some LBTerrainTexture instances may be disabled or don't have a valid Texture2D. // This list contains the matching index of the Texturing Tab's LBTerrainTexture in the // array of unique splatPrototypes for all terrains. terrainTextureArrayIndexList = new List <int>(new int[terrainTextureListSize]); // Fill the lookup array with -ve numbers to show there is no matching splatprototype to begin with for (int txArrayIdx = 0; txArrayIdx < terrainTextureListSize; txArrayIdx++) { terrainTextureArrayIndexList[txArrayIdx] = -1; } if ((isTexturingPresent || isObjPathTexturingPresent) && terrainTextureList != null) { // Get a list of unique textures from the terrain data for (int t = 0; t < numTerrains; t++) { #if UNITY_2018_3_OR_NEWER List <LBTerrainTexture> splatTextures = LBTerrainTexture.ToLBTerrainTextureList(terrainDataArray[t].terrainLayers); #else List <LBTerrainTexture> splatTextures = LBTerrainTexture.ToLBTerrainTextureList(terrainDataArray[t].splatPrototypes); #endif if (splatTextures != null) { for (txIdx = 0; txIdx < terrainTextureListSize; txIdx++) { // Skip textures that have already been matched if (terrainTextureArrayIndexList[txIdx] < 0) { LBTerrainTexture lbTerrainTexture = terrainTextureList[txIdx]; // Attempt to match this Texture with a splatPrototype // Check for tinted textures //int splatIdx = splatTextures.FindIndex(stx => stx.texture == (lbTerrainTexture.isTinted ? lbTerrainTexture.tintedTexture : lbTerrainTexture.texture) && int splatIdx = splatTextures.FindIndex(stx => lbTerrainTexture.CompareToTexture2D(stx.texture) && stx.normalMap == lbTerrainTexture.normalMap && stx.smoothness == lbTerrainTexture.smoothness && stx.metallic == lbTerrainTexture.metallic && stx.tileSize == lbTerrainTexture.tileSize); if (splatIdx >= 0) { // Add this splatPrototype index to the array of LBTerrainTexture indexes // This will enable us to tell which splatPrototype (if any) matches the current LBTerrainTexture terrainTextureArrayIndexList[txIdx] = splatIdx; } } } } } } }