Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an LBTextureFilter for Stencil Layer using the LBStencil instance GUID and the GUID of the stencil layer
        /// </summary>
        /// <param name="lbStencilGUID"></param>
        /// <param name="lbStencilLayerGUID"></param>
        /// <param name="showErrors"></param>
        /// <returns></returns>
        public static LBTextureFilter CreateFilter(string lbStencilGUID, string lbStencilLayerGUID, bool showErrors)
        {
            LBTextureFilter lbFilter = null;

            if (string.IsNullOrEmpty(lbStencilGUID))
            {
                if (showErrors)
                {
                    Debug.LogWarning("LBTextureFilter.CreateFilter - lbStencilGUID is an empty string");
                }
            }
            else if (string.IsNullOrEmpty(lbStencilLayerGUID))
            {
                if (showErrors)
                {
                    Debug.LogWarning("LBTextureFilter.CreateFilter - lbStencilLayerGUID is an empty string");
                }
            }
            else
            {
                lbFilter = new LBTextureFilter(FilterType.StencilLayer, FilterMode.AND);
                if (lbFilter == null)
                {
                    if (showErrors)
                    {
                        Debug.LogWarning("LBTextureFilter.CreateFilter - could not create LBTextureFilter");
                    }
                }
                else
                {
                    lbFilter.lbStencilGUID      = lbStencilGUID;
                    lbFilter.lbStencilLayerGUID = lbStencilLayerGUID;
                }
            }

            return(lbFilter);
        }
Exemplo n.º 3
0
        /// <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());
        }