Example #1
0
        internal void AlterTexture(GameObject gameObject)
        {
            //Log.Normal("called");

            foreach (TextureSet set in textureSets)
            {
                //Log.Normal("Apply TextureSet");
                foreach (MeshRenderer renderer in gameObject.GetComponentsInChildren <MeshRenderer>(true))
                {
                    if (!set.targetTransforms.Contains("Any") && !set.targetTransforms.Contains(renderer.transform.name))
                    {
                        continue;
                    }

                    if (!String.IsNullOrEmpty(set.newTexture))
                    {
                        renderer.material.mainTexture = KKGraphics.GetTexture(set.newTexture);
                    }

                    if (!String.IsNullOrEmpty(set.newColor))
                    {
                        Color color = ConfigNode.ParseColor(set.newColor);

                        renderer.material.color = color;
                    }
                }
            }
        }
Example #2
0
        internal static void LoadAllMapDecalMaps()
        {
            UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("KK_DecalsMap");

            foreach (UrlDir.UrlConfig conf in configs)
            {
                //create new Instance and Register in Database
                MapDecalsMap newMapDecalInstance = ScriptableObject.CreateInstance <MapDecalsMap>();
                // Load Settings into instance
                ParseDecalsMapConfig(newMapDecalInstance, conf.config);

                newMapDecalInstance.path       = Path.GetDirectoryName(Path.GetDirectoryName(conf.url));
                newMapDecalInstance.mapTexture = KKGraphics.GetTexture(newMapDecalInstance.path + "/" + newMapDecalInstance.Image, false);

                if (newMapDecalInstance.mapTexture == null)
                {
                    Log.UserError("Image File " + newMapDecalInstance.path + "/" + newMapDecalInstance.Image + " could not be loaded");
                    continue;
                }

                if (newMapDecalInstance.UseAsHeighMap)
                {
                    newMapDecalInstance.CreateMap(MapSO.MapDepth.Greyscale, newMapDecalInstance.mapTexture);
                    newMapDecalInstance.isHeightMap = true;
                }
                else
                {
                    newMapDecalInstance.CreateMap(MapSO.MapDepth.RGBA, newMapDecalInstance.mapTexture);
                }
                //Log.Normal("DecalsMap " + newMapDecalInstance.Name + " imported: " + (newMapDecalInstance.isHeightMap? "as HeighMap" : "as ColorMap"));

                newMapDecalInstance.map = newMapDecalInstance as MapSO;
                DecalsDatabase.RegisterMap(newMapDecalInstance);
            }
        }
        internal static Color GetAverageColor(string textureName)
        {
            Texture2D texture = KKGraphics.GetTexture(textureName).BlitTexture(64);

            if (texture == null)
            {
                return(Color.grey);
            }
            return(AverageColor(texture.GetPixels()));
        }
Example #4
0
        internal void UpdateCallBack(Color newColor, string newTexture)
        {
            selectedInstance.GrasColor = newColor;

            if (KKGraphics.GetTexture(newTexture) != null)
            {
                //Log.Normal("Updating Texture to: " + newTexture);
                selectedInstance.GrasTexture = newTexture;
                grasTextureName = newTexture;
            }
            else
            {
                Log.UserWarning("GrasColorUI: Texture not found: " + newTexture);
                MiscUtils.HUDMessage("GrasColorUI: Texture not found: " + newTexture);
            }
            selectedInstance.Update();
            SetupFields();
        }
Example #5
0
        private void ApplySettings()
        {
            selectedInstance.GrasColor.r = float.Parse(grasColorRStr);
            selectedInstance.GrasColor.g = float.Parse(grasColorGStr);
            selectedInstance.GrasColor.b = float.Parse(grasColorBStr);
            selectedInstance.GrasColor.a = float.Parse(grasColorAStr);

            if (KKGraphics.GetTexture(grasTextureName) != null)
            {
                //Log.Normal("Try to Set Texture to: " + grasTextureName);
                selectedInstance.GrasTexture = grasTextureName;
            }
            else
            {
                Log.UserWarning("GrasColorUI: Texture not found: " + grasTextureName);
                MiscUtils.HUDMessage("GrasColorUI: Texture not found: " + grasTextureName);
            }
            //Log.Normal("found Texture: " + selectedInstance.GrasTexture);
            selectedInstance.Update();
        }
        internal static Color ManualCalcNewColor(Color oldColor, string oldTextrueName, string newTextureName)
        {
            if (String.IsNullOrEmpty(oldTextrueName) || oldTextrueName == "BUILTIN:/terrain_grass00_new")
            {
                oldTextrueName = "KerbalKonstructs/Assets/Colors/legacyGrassColors";
            }

            if (String.IsNullOrEmpty(newTextureName))
            {
                newTextureName = "BUILTIN:/terrain_grass00_new_detail";
            }


            Texture2D oldTexture = KKGraphics.GetTexture(oldTextrueName).BlitTexture(64);
            Texture2D newTexture = KKGraphics.GetTexture(newTextureName).BlitTexture(64);

            Color oldAvgTexColor = AverageColor(oldTexture.GetPixels());
            Color newAvgTexColor = AverageColor(newTexture.GetPixels());

            //Log.Normal("oldAvgTexColor: " + oldAvgTexColor.ToString());
            //Log.Normal("newAvgTexColor: " + newAvgTexColor.ToString());

            Color legacyColor = Color.Lerp(oldColor, oldAvgTexColor, oldColor.a);

            legacyColor.a = 1;

            //Color firstNewColor = newAvgTexColor * legacyColor;
            //Log.Normal("firstNewColor : " + firstNewColor.ToString());


            Color finalColor = legacyColor.DivideWith(newAvgTexColor).LimitTo(6f);

            finalColor.a = 1;
            Log.Normal("final Color: " + finalColor.ToString());

            return(finalColor);
        }
Example #7
0
 internal static void ReloadBlendMask()
 {
     KKGraphics.RemoveCache(selectedMod.blendMaskTextureName);
     selectedMod.ApplySettings();
 }