Exemplo n.º 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;
     }
 }
Exemplo n.º 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;
                    }
                }
            }
        }
        /// <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));
        }