コード例 #1
0
 public RecoloringData(string data)
 {
     if (data.Contains(","))//CSV value, parse from floats
     {
         string[] values = data.Split(',');
         int      len    = values.Length;
         if (len < 3)
         {
             MonoBehaviour.print("ERROR: Not enough data in: " + data + " to construct color values.");
             values = new string[] { "255", "255", "255", "0", "0" };
         }
         string redString   = values[0];
         string greenString = values[1];
         string blueString  = values[2];
         string specString  = len > 3 ? values[3] : "0";
         string metalString = len > 4 ? values[4] : "0";
         float  r           = Utils.safeParseFloat(redString);
         float  g           = Utils.safeParseFloat(greenString);
         float  b           = Utils.safeParseFloat(blueString);
         color    = new Color(r, g, b);
         specular = Utils.safeParseFloat(specString);
         metallic = Utils.safeParseFloat(metalString);
     }
     else //preset color, load from string value
     {
         RecoloringDataPreset preset = PresetColor.getColor(data);
         color    = preset.color;
         specular = preset.specular;
         metallic = preset.metallic;
     }
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <param name="defaultMode"></param>
        public TextureSet(ConfigNode node, string defaultMode)
        {
            name  = node.GetStringValue("name");
            title = node.GetStringValue("title", name);
            ConfigNode[] texNodes = node.GetNodes("MATERIAL");
            int          len      = texNodes.Length;

            if (len == 0)
            {
                Log.log("Did not find any MATERIAL nodes in texture set:" + name + ", searching for legacy styled TEXTURE nodes.");
                Log.log("Please update the config for the texture-set to fix this error.");
                texNodes = node.GetNodes("TEXTURE");
                len      = texNodes.Length;
            }
            textureData = new TextureSetMaterialData[len];
            for (int i = 0; i < len; i++)
            {
                textureData[i] = new TextureSetMaterialData(this, texNodes[i], defaultMode);
            }
            supportsRecoloring     = node.GetBoolValue("recolorable", false);
            recolorableChannelMask = node.GetIntValue("channelMask", 1 | 2 | 4);
            featureMask            = node.GetIntValue("featureMask", 1 | 2 | 4);
            if (node.HasNode("COLORS"))
            {
                ConfigNode     colorsNode = node.GetNode("COLORS");
                RecoloringData c1         = RecoloringData.ParseColorsBlockEntry(colorsNode.GetStringValue("mainColor"));
                RecoloringData c2         = RecoloringData.ParseColorsBlockEntry(colorsNode.GetStringValue("secondColor"));
                RecoloringData c3         = RecoloringData.ParseColorsBlockEntry(colorsNode.GetStringValue("detailColor"));
                maskColors = new RecoloringData[] { c1, c2, c3 };
            }
            else
            {
                maskColors = new RecoloringData[3];
                Color white = PresetColor.getColor("white").color;//will always return -something-, even if 'white' is undefined
                maskColors[0] = new RecoloringData(white, 0, 0, 1);
                maskColors[1] = new RecoloringData(white, 0, 0, 1);
                maskColors[2] = new RecoloringData(white, 0, 0, 1);
            }
            //loop through materials, and auto-enable 'recoloring' flag if recoloring keyword is set
            len = textureData.Length;
            for (int i = 0; i < len; i++)
            {
                int len2 = textureData[i].shaderProperties.Length;
                for (int k = 0; k < len2; k++)
                {
                    if (textureData[i].shaderProperties[k].name == "TU_RECOLOR")
                    {
                        supportsRecoloring = true;
                    }
                }
            }
        }
コード例 #3
0
        private void drawPresetColorArea()
        {
            if (sectionData == null)
            {
                return;
            }
            GUILayout.Label("Select a preset color: ");
            presetColorScrollPos = GUILayout.BeginScrollView(presetColorScrollPos, false, true);
            bool  update   = false;
            Color old      = GUI.color;
            Color guiColor = old;
            List <RecoloringDataPreset> presetColors = PresetColor.getColorList(groupName);
            int len = presetColors.Count;

            GUILayout.BeginHorizontal();
            for (int i = 0; i < len; i++)
            {
                if (i > 0 && i % 2 == 0)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
                GUILayout.Label(presetColors[i].title, nonWrappingLabelStyle, GUILayout.Width(115));
                guiColor   = presetColors[i].color;
                guiColor.a = 1f;
                GUI.color  = guiColor;
                if (GUILayout.Button("Select", GUILayout.Width(55)))
                {
                    editingColor = presetColors[i].getRecoloringData();
                    rStr         = (editingColor.color.r * 255f).ToString("F0");
                    gStr         = (editingColor.color.g * 255f).ToString("F0");
                    bStr         = (editingColor.color.b * 255f).ToString("F0");
                    aStr         = (editingColor.specular * 255f).ToString("F0");
                    mStr         = (editingColor.metallic * 255f).ToString("F0");
                    //dStr = (editingColor.detail * 100f).ToString("F0");//leave detail mult as pre-specified value (user/config); it does not pull from preset colors at all
                    update = true;
                }
                GUI.color = old;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();
            GUI.color = old;
            if (sectionData.colors != null)
            {
                sectionData.colors[colorIndex] = editingColor;
                if (update)
                {
                    sectionData.updateColors();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Load a recoloring data instance from an input CSV string.  This method attempts intelligent parsing based on the values provided.
        /// If the value contains commas and periods, attempt to parse as floating point.  If the value contains commas only, attempt to parse
        /// as bytes.  If the value contains neither period nor comma, attempt to parse as a 'presetColor' name.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static RecoloringData ParseColorsBlockEntry(string data)
        {
            Color color;
            float specular, metallic, detail;

            detail = 1;
            if (data.Contains(","))//CSV value, parse from floats
            {
                string[] values = data.Split(',');
                int      len    = values.Length;
                if (len < 3)
                {
                    Log.error("ERROR: Not enough data in: " + data + " to construct color values.");
                    color    = Color.white;
                    specular = 0;
                    metallic = 0;
                }
                else if (data.Contains("."))
                {
                    string rgb          = values[0] + "," + values[1] + "," + values[2] + ",1.0";
                    string specString   = len > 3 ? values[3] : "0";
                    string metalString  = len > 4 ? values[4] : "0";
                    string detailString = len > 5 ? values[5] : "1";
                    color    = Utils.parseColor(rgb);
                    specular = Utils.safeParseFloat(specString);
                    metallic = Utils.safeParseFloat(metalString);
                    detail   = Utils.safeParseFloat(detailString);
                }
                else
                {
                    string rgb          = values[0] + "," + values[1] + "," + values[2] + ",255";
                    string specString   = len > 3 ? values[3] : "0";
                    string metalString  = len > 4 ? values[4] : "0";
                    string detailString = len > 5 ? values[5] : "255";
                    color    = Utils.parseColor(rgb);
                    specular = Utils.safeParseInt(specString) / 255f;
                    metallic = Utils.safeParseInt(metalString) / 255f;
                    detail   = Utils.safeParseInt(detailString) / 255f;
                }
            }
            else //preset color, load from string value
            {
                RecoloringDataPreset preset = PresetColor.getColor(data);
                color    = preset.color;
                specular = preset.specular;
                metallic = preset.metallic;
                detail   = 1;
            }
            return(new RecoloringData(color, specular, metallic, detail));
        }
コード例 #5
0
        private static void load()
        {
            MonoBehaviour.print("KSPShaderLoader - Initializing shader and texture set data.");
            ConfigNode config = GameDatabase.Instance.GetConfigNodes("TEXTURES_UNLIMITED")[0];

            logReplacements = config.GetBoolValue("logReplacements", logReplacements);
            logErrors       = config.GetBoolValue("logErrors", logErrors);
            Dictionary <string, Shader> dict = new Dictionary <string, Shader>();

            loadBundles(dict);
            buildShaderSets(dict);
            PresetColor.loadColors();
            loadTextureSets();
            applyToModelDatabase();
            MonoBehaviour.print("KSPShaderLoader - Calling PostLoad handlers");
            foreach (Action act in postLoadCallbacks)
            {
                act.Invoke();
            }
            dumpUVMaps();
        }
コード例 #6
0
        private void load()
        {
            //clear any existing data in case of module-manager reload
            loadedShaders.Clear();
            loadedModelShaderSets.Clear();
            iconShaders.Clear();
            loadedTextureSets.Clear();
            textureColors.Clear();
            transparentShaderData.Clear();
            Log.log("TexturesUnlimited - Initializing shader and texture set data.");
            ConfigNode[] allTUNodes = GameDatabase.Instance.GetConfigNodes("TEXTURES_UNLIMITED");
            ConfigNode   config     = Array.Find(allTUNodes, m => m.GetStringValue("name") == "default");

            configurationNode = config;

            logAll                  = config.GetBoolValue("logAll", logAll);
            logReplacements         = config.GetBoolValue("logReplacements", logReplacements);
            logErrors               = config.GetBoolValue("logErrors", logErrors);
            recolorGUIWidth         = config.GetIntValue("recolorGUIWidth");
            recolorGUITotalHeight   = config.GetIntValue("recolorGUITotalHeight");
            recolorGUISectionHeight = config.GetIntValue("recolorGUISectionHeight");
            if (config.GetBoolValue("displayDX9Warning", true))
            {
                //disable API check as long as using stock reflection system
                //doAPICheck();
            }
            loadBundles();
            buildShaderSets();
            PresetColor.loadColors();
            loadTextureSets();
            applyToModelDatabase();
            Log.log("TexturesUnlimited - Calling PostLoad handlers");
            foreach (Action act in postLoadCallbacks)
            {
                act.Invoke();
            }
            dumpUVMaps();
            fixStockBumpMaps();
            //NormMaskCreation.processBatch();
        }
コード例 #7
0
        private void drawSectionRecoloringArea()
        {
            if (sectionData == null)
            {
                return;
            }
            bool updated = false;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Editing: ", GUILayout.Width(60));
            GUILayout.Label(sectionData.sectionName);
            GUILayout.Label(getSectionLabel(colorIndex) + " Color");
            GUILayout.FlexibleSpace();//to force everything to the left instead of randomly spaced out, while still allowing dynamic length adjustments
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (drawColorInputLine("Red", ref editingColor.color.r, ref rStr, sectionData.colorSupported(), 255, 1))
            {
                updated = true;
            }
            if (GUILayout.Button("Load Pattern", GUILayout.Width(120)))
            {
                sectionData.colors[0] = storedPattern[0];
                sectionData.colors[1] = storedPattern[1];
                sectionData.colors[2] = storedPattern[2];
                editingColor          = sectionData.colors[colorIndex];
                updated = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (drawColorInputLine("Green", ref editingColor.color.g, ref gStr, sectionData.colorSupported(), 255, 1))
            {
                updated = true;
            }
            if (GUILayout.Button("Store Pattern", GUILayout.Width(120)))
            {
                storedPattern    = new RecoloringData[3];
                storedPattern[0] = sectionData.colors[0];
                storedPattern[1] = sectionData.colors[1];
                storedPattern[2] = sectionData.colors[2];
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (drawColorInputLine("Blue", ref editingColor.color.b, ref bStr, sectionData.colorSupported(), 255, 1))
            {
                updated = true;
            }
            if (GUILayout.Button("Load Color", GUILayout.Width(120)))
            {
                editingColor = storedColor;
                updated      = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (drawColorInputLine("Specular", ref editingColor.specular, ref aStr, sectionData.specularSupported(), 255, 1))
            {
                updated = true;
            }
            if (GUILayout.Button("Store Color", GUILayout.Width(120)))
            {
                storedColor = editingColor;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (sectionData.metallicSupported())
            {
                if (drawColorInputLine("Metallic", ref editingColor.metallic, ref mStr, true, 255, 1))
                {
                    updated = true;
                }
            }
            else if (sectionData.hardnessSupported())
            {
                if (drawColorInputLine("Hardness", ref editingColor.metallic, ref mStr, true, 255, 1))
                {
                    updated = true;
                }
            }
            else
            {
                if (drawColorInputLine("Metallic", ref editingColor.metallic, ref mStr, false, 255, 1))
                {
                    updated = true;
                }
            }
            if (GUILayout.Button("<", GUILayout.Width(20)))
            {
                groupIndex--;
                List <RecoloringDataPresetGroup> gs = PresetColor.getGroupList();
                if (groupIndex < 0)
                {
                    groupIndex = gs.Count - 1;
                }
                groupName = gs[groupIndex].name;
            }
            GUILayout.Label("Palette", GUILayout.Width(70));
            if (GUILayout.Button(">", GUILayout.Width(20)))
            {
                groupIndex++;
                List <RecoloringDataPresetGroup> gs = PresetColor.getGroupList();
                if (groupIndex >= gs.Count)
                {
                    groupIndex = 0;
                }
                groupName = gs[groupIndex].name;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (drawColorInputLine("Detail %", ref editingColor.detail, ref dStr, true, 100, 5))
            {
                updated = true;
            }
            GUILayout.Label(groupName, GUILayout.Width(120));
            GUILayout.EndHorizontal();

            if (updated)
            {
                sectionData.colors[colorIndex] = editingColor;
                sectionData.updateColors();
            }
        }