Beispiel #1
0
        public static void LoadTextureSets()
        {
            if (loadedTextureSets != null)
            {
                return;
            }

            loadedTextureSets = new List <TextureSet>();
            //print("*ST* Loading texture sets");
            foreach (ConfigNode texInfo in GameDatabase.Instance.GetConfigNodes("STRETCHYTANKTEXTURES"))
            {
                for (int i = 0; i < texInfo.nodes.Count; i++)
                {
                    TextureSet textureSet = LoadTextureSet(texInfo.nodes[i]);

                    if (textureSet != null)
                    {
                        loadedTextureSets.Add(textureSet);
                    }
                }
            }

            if (loadedTextureSets.Count == 0)
            {
                Debug.LogError("*ST* No Texturesets found!");
            }

            loadedTextureSets.Sort(TextureSetNameComparison);

            loadedTextureSetNames = new string[loadedTextureSets.Count];
            for (int i = 0; i < loadedTextureSets.Count; ++i)
            {
                loadedTextureSetNames[i] = loadedTextureSets[i].name;
            }
        }
Beispiel #2
0
        private static int TextureSetNameComparison(TextureSet s1, TextureSet s2)
        {
            bool s1Start = s1.sidesName.StartsWith("ProceduralParts");

            if (s1Start != s2.sidesName.StartsWith("ProceduralParts"))
            {
                return(s1Start ? -1 : 1);
            }
            return(s1.name.CompareTo(s2.name));
        }
Beispiel #3
0
        private static int TextureSetNameComparison(TextureSet s1, TextureSet s2)
        {
            bool s1Start = s1.sidesName.StartsWith("ProceduralParts");

            if (s1Start != s2.sidesName.StartsWith("ProceduralParts"))
            {
                return(s1Start ? -1 : 1);
            }
            return(string.Compare(s1.name, s2.name, StringComparison.Ordinal));
        }
Beispiel #4
0
        public static void StaticInit()
        {
            if (staticallyInitialized)
            {
                return;
            }

            if (AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name == "TestFlight") is AssemblyLoader.LoadedAssembly tfAssembly)
            {
                tfInterface = Type.GetType("TestFlightCore.TestFlightInterface, TestFlightCore", false);
            }
            installedFAR = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "FerramAerospaceResearch");
            TextureSet.LoadTextureSets(LegacyTextureHandler.textureSets);
            staticallyInitialized = true;
        }
Beispiel #5
0
        public static void StaticInit()
        {
            // "All Part Upgrades Applied In Sandbox" required for this mod to be usable in sandbox
            if (!staticallyResetPartUpgrades && HighLogic.CurrentGame != null)
            {
                staticallyResetPartUpgrades = HighLogic.CurrentGame.Parameters.CustomParams <GameParameters.AdvancedParams>().PartUpgradesInSandbox = true;
            }

            if (staticallyInitialized)
            {
                return;
            }

            if (AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name == "TestFlight") is AssemblyLoader.LoadedAssembly tfAssembly)
            {
                tfInterface = Type.GetType("TestFlightCore.TestFlightInterface, TestFlightCore", false);
            }
            installedFAR = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "FerramAerospaceResearch");
            installedTU  = AssemblyLoader.loadedAssemblies.Any(a => a.assembly.GetName().Name == "TexturesUnlimited");
            TextureSet.LoadTextureSets(LegacyTextureHandler.textureSets);
            staticallyInitialized = true;
        }
Beispiel #6
0
        public static TextureSet LoadTextureSet(ConfigNode node)
        {
            if (!(node.GetNode("sides") is ConfigNode sidesNode && node.GetNode("ends") is ConfigNode endsNode &&
                  sidesNode.HasValue("texture") && endsNode.HasValue("texture")))
            {
                Debug.LogError($"{ModTag} LoadTextureSet found invalid Textureset {node.name}");
                return(null);
            }

            TextureSet tex = new TextureSet
            {
                name          = node.name,
                sidesName     = sidesNode.GetValue("texture"),
                endsName      = endsNode.GetValue("texture"),
                sidesBumpName = sidesNode.HasValue("bump") ? sidesNode.GetValue("bump") : string.Empty,
                endsBumpName  = endsNode.HasValue("bump") ? endsNode.GetValue("bump") : string.Empty
            };

            if (sidesNode.HasValue("uScale"))
            {
                float.TryParse(sidesNode.GetValue("uScale"), out tex.scale.x);
            }
            if (sidesNode.HasValue("vScale"))
            {
                float.TryParse(sidesNode.GetValue("vScale"), out tex.scale.y);
            }

            if (sidesNode.HasValue("autoScale"))
            {
                bool.TryParse(sidesNode.GetValue("autoScale"), out tex.autoScale);
            }
            if (sidesNode.HasValue("autoScaleU"))
            {
                bool.TryParse(sidesNode.GetValue("autoScaleU"), out tex.autoScaleU);
            }
            if (sidesNode.HasValue("autoScaleV"))
            {
                bool.TryParse(sidesNode.GetValue("autoScaleV"), out tex.autoScaleV);
            }
            tex.autoScaleU |= tex.autoScale;
            tex.autoScaleV |= tex.autoScale;

            if (endsNode.HasValue("autoScale"))
            {
                bool.TryParse(endsNode.GetValue("autoScale"), out tex.endsAutoScale);
            }
            if (sidesNode.HasValue("autoWidthDivide"))
            {
                bool.TryParse(sidesNode.GetValue("autoWidthDivide"), out tex.autoWidthDivide);
            }
            if (sidesNode.HasValue("autoHeightSteps"))
            {
                float.TryParse(sidesNode.GetValue("autoHeightSteps"), out tex.autoHeightSteps);
            }

            if (sidesNode.HasValue("specular"))
            {
                tex.sidesSpecular = ConfigNode.ParseColor(sidesNode.GetValue("specular"));
            }
            if (sidesNode.HasValue("shininess"))
            {
                float.TryParse(sidesNode.GetValue("shininess"), out tex.sidesShininess);
            }
            if (endsNode.HasValue("specular"))
            {
                tex.endsSpecular = ConfigNode.ParseColor(endsNode.GetValue("specular"));
            }
            if (endsNode.HasValue("shininess"))
            {
                float.TryParse(endsNode.GetValue("shininess"), out tex.endsShininess);
            }

            Texture[] textures = Resources.FindObjectsOfTypeAll(typeof(Texture)) as Texture[];

            if (!TryFindTexture(textures, ref tex.sidesName, out tex.sides))
            {
                Debug.LogError($"{ModTag} LoadTextureSet Sides textures not found for {node.name}");
                return(null);
            }

            if (!TryFindTexture(textures, ref tex.endsName, out tex.ends))
            {
                Debug.LogError($"{ModTag} LoadTextureSet Ends textures not found for {node.name}");
                return(null);
            }

            if (!string.IsNullOrEmpty(tex.sidesBumpName) && !TryFindTexture(textures, ref tex.sidesBumpName, out tex.sidesBump))
            {
                Debug.LogError($"{ModTag} LoadTextureSet Side Bump textures not found for {node.name}");
                return(null);
            }

            if (!string.IsNullOrEmpty(tex.endsBumpName) && !TryFindTexture(textures, ref tex.endsBumpName, out tex.endsBump))
            {
                Debug.LogError($"{ModTag} LoadTextureSet Cap bump textures not found for {node.name}");
                return(null);
            }

            return(tex);
        }
Beispiel #7
0
        private void UpdateTexture()
        {
            if (textureSet == oldTextureSet)
            {
                return;
            }

            int newIdx = loadedTextureSets.FindIndex(set => set.name == textureSet);

            if (newIdx < 0)
            {
                Debug.LogError("*ST* Unable to find texture set: " + textureSet);
                textureSet = oldTextureSet;
                return;
            }
            oldTextureSet = textureSet;

            TextureSet tex = loadedTextureSets[newIdx];

            // Set shaders
            if (!part.Modules.Contains("ModulePaintable"))
            {
                if (tex.sidesBump != null)
                {
                    sidesMaterial.shader = Shader.Find("KSP/Bumped");
                }
                else
                {
                    sidesMaterial.shader = Shader.Find("KSP/Diffuse");
                }

                // pt is no longer specular ever, just diffuse.
                if (endsMaterial != null)
                {
                    endsMaterial.shader = Shader.Find("KSP/Diffuse");
                }
            }

            // TODO: shove into config file.
            if (endsMaterial != null)
            {
                float scale  = 0.93f;
                float offset = (1f / scale - 1f) / 2f;
                endsMaterial.mainTextureScale  = new Vector2(scale, scale);
                endsMaterial.mainTextureOffset = new Vector2(offset, offset);
            }

            // set up UVs
            Vector2 scaleUV = tex.scale;

            if (tex.autoScale)
            {
                scaleUV.x = (float)Math.Round(scaleUV.x * sideTextureScale.x / 8f);
                if (scaleUV.x < 1)
                {
                    scaleUV.x = 1;
                }
                if (tex.autoWidthDivide)
                {
                    if (tex.autoHeightSteps > 0)
                    {
                        scaleUV.y = (float)Math.Ceiling(scaleUV.y * sideTextureScale.y / scaleUV.x * (1f / tex.autoHeightSteps)) * tex.autoHeightSteps;
                    }
                    else
                    {
                        scaleUV.y *= sideTextureScale.y / scaleUV.x;
                    }
                }
                else
                {
                    scaleUV.y *= sideTextureScale.y;
                }
            }

            // apply
            sidesMaterial.mainTextureScale = scaleUV;
            sidesMaterial.SetTexture("_MainTex", tex.sides);
            if (tex.sidesBump != null)
            {
                sidesMaterial.SetTextureScale("_BumpMap", scaleUV);
                sidesMaterial.SetTexture("_BumpMap", tex.sidesBump);
            }
            if (endsMaterial != null)
            {
                endsMaterial.SetTexture("_MainTex", tex.ends);
            }
        }
Beispiel #8
0
        private static TextureSet LoadTextureSet(ConfigNode node)
        {
            string textureSet = node.name;

            // Sanity check
            if (node.GetNode("sides") == null || node.GetNode("ends") == null)
            {
                Debug.LogError("*ST* Invalid Textureset " + textureSet);
                return(null);
            }
            if (!node.GetNode("sides").HasValue("texture") || !node.GetNode("ends").HasValue("texture"))
            {
                Debug.LogError("*ST* Invalid Textureset " + textureSet);
                return(null);
            }


            // get settings
            TextureSet tex = new TextureSet();

            tex.name          = textureSet;
            tex.sidesName     = node.GetNode("sides").GetValue("texture");
            tex.endsName      = node.GetNode("ends").GetValue("texture");
            tex.sidesBumpName = "";
            if (node.GetNode("sides").HasValue("bump"))
            {
                tex.sidesBumpName = node.GetNode("sides").GetValue("bump");
            }

            if (node.GetNode("sides").HasValue("uScale"))
            {
                float.TryParse(node.GetNode("sides").GetValue("uScale"), out tex.scale.x);
            }
            if (node.GetNode("sides").HasValue("vScale"))
            {
                float.TryParse(node.GetNode("sides").GetValue("vScale"), out tex.scale.y);
            }


            if (node.GetNode("sides").HasValue("autoScale"))
            {
                bool.TryParse(node.GetNode("sides").GetValue("autoScale"), out tex.autoScale);
            }
            if (node.GetNode("sides").HasValue("autoWidthDivide"))
            {
                bool.TryParse(node.GetNode("sides").GetValue("autoWidthDivide"), out tex.autoWidthDivide);
            }
            if (node.GetNode("sides").HasValue("autoHeightSteps"))
            {
                float.TryParse(node.GetNode("sides").GetValue("autoHeightSteps"), out tex.autoHeightSteps);
            }

            Texture[] textures = Resources.FindObjectsOfTypeAll(typeof(Texture)) as Texture[];

            if (!TryFindTexture(textures, ref tex.sidesName, out tex.sides))
            {
                Debug.LogError("*ST* Sides textures not found for " + textureSet);
                return(null);
            }

            if (!TryFindTexture(textures, ref tex.endsName, out tex.ends))
            {
                Debug.LogError("*ST* Ends textures not found for " + textureSet);
                return(null);
            }

            if (string.IsNullOrEmpty(tex.sidesBumpName))
            {
                tex.sidesBump = null;
            }
            else if (!TryFindTexture(textures, ref tex.sidesBumpName, out tex.sidesBump))
            {
                Debug.LogError("*ST* Side bump textures not found for " + textureSet);
                return(null);
            }


            return(tex);
        }