Example #1
0
 // Print out the celestial bodies
 public static void PSystemBodyWalk(PSystemBody b, String prefix = "")
 {
     Logger.Active.Log(prefix + b.celestialBody.bodyName + ":" + b.flightGlobalsIndex);
     foreach (PSystemBody c in b.children)
     {
         PSystemBodyWalk(c, prefix + "    ");
     }
 }
Example #2
0
        public static void GrabPSystemBodies(PSystemBody PSB)
        {
            StarSystem.PSBDict[PSB.celestialBody.bodyName] = PSB;
            Debug.Log(PSB.celestialBody.bodyName);

            foreach (var ChildPSB in PSB.children)
            {
                GrabPSystemBodies(ChildPSB);
            }
        }
 private static List<PSystemBody> GetBodiesRecursive(PSystemBody body)
 {
     List<PSystemBody> bodies = new List<PSystemBody> ();
     bodies.Add (body);
     foreach (var child in body.children)
     {
         bodies.AddRange(GetBodiesRecursive (child));
     }
     return bodies;
 }
        public static void GrabPSystemBodies(PSystemBody PSB)
        {
            StarSystem.PSBDict[PSB.celestialBody.bodyName] = PSB;
            Debug.Log(PSB.celestialBody.bodyName);

            foreach (var ChildPSB in PSB.children)
            {
                GrabPSystemBodies(ChildPSB);
            }
        }
Example #5
0
        // Initialisation
        static Templates()
        {
            // We need to get the body for Jool (to steal it's mesh)
            PSystemBody Jool = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Jool");

            // Return it's mesh
            ReferenceGeosphere = Jool.scaledVersion.GetComponent <MeshFilter>().sharedMesh;

            // Main Menu body
            menuBody = "Kerbin";
        }
Example #6
0
 // Patch the FlightGlobalsIndex of bodies
 public static void PatchFGI(ref List <int> numbers, ref int index, PSystemBody rootBody)
 {
     foreach (PSystemBody body in rootBody.children)
     {
         if (numbers.Contains(body.flightGlobalsIndex))
         {
             body.flightGlobalsIndex = index++;
         }
         numbers.Add(body.flightGlobalsIndex);
         PatchFGI(ref numbers, ref index, body);
     }
 }
Example #7
0
 internal MonoBehaviour MaterialBasedOnGraphicsSetting(PSystemBody generatedBody)
 {
     MonoBehaviour[] components = generatedBody.scaledVersion.GetComponents <MonoBehaviour>();
     if ((Versioning.version_minor == 10) || (Versioning.version_minor == 11))
     {
         MonoBehaviour component = components[2]; //strict index, likely to break
         if (component.name.Equals(generatedBody.scaledVersion.name))
         {
             return(component);
         }
     }
     throw new Exception();
 }
Example #8
0
            /// <summary>
            /// Create colliders for the scatter
            /// </summary>
            void Start()
            {
                // Register us as the parental object for the scatter
                PQSLandControl landControl = transform.parent.GetComponentInChildren <PQSLandControl>();

                PQSLandControl.LandClassScatter scatter = landControl.scatters.First(s => s.scatterName == name.Split(' ').Last());
                scatter.GetType().GetField("scatterParent", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(scatter, gameObject);

                // The ConfigNode is lost, so find it again!
                PSystemBody body = PSystemManager.Instance.systemPrefab.GetComponentsInChildren <PSystemBody>(true).First(b => b.name == transform.parent.name);

                experiment = body.pqsVersion.gameObject.GetChild(name).GetComponent <Scatter>().experiment;
            }
Example #9
0
            // Default constructor
            public CoronaLoader()
            {
                // We need to get the body for the Sun (to steal it's corona mesh)
                PSystemBody sun = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Sun");

                // Clone a default Corona
                corona = UnityEngine.Object.Instantiate(sun.scaledVersion.GetComponentsInChildren <SunCoronas>(true).First().gameObject) as GameObject;
                corona.transform.parent = Utility.Deactivator;
                coronaComponent         = corona.GetComponent <SunCoronas> ();

                // Setup the material loader
                material      = new ParticleAddSmoothLoader(corona.GetComponent <Renderer>().material);
                material.name = Guid.NewGuid().ToString();
            }
Example #10
0
        // Initialisation
        static Templates()
        {
            // We need to get the body for Jool (to steal it's mesh)
            PSystemBody Jool = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Jool");

            // Return it's mesh
            ReferenceGeosphere = Jool.scaledVersion.GetComponent <MeshFilter>().sharedMesh;

            // Main Menu body
            menuBody = "Kerbin";

            // Random Main Menu bodies
            randomMainMenuBodies = new List <String>();
        }
Example #11
0
 CelestialBody RecurseFindHomeworld(PSystemBody b)
 {
     if (b.celestialBody != null && b.celestialBody.isHomeWorld)
     {
         return(b.celestialBody);
     }
     foreach (PSystemBody c in b.children)
     {
         CelestialBody h = RecurseFindHomeworld(c);
         if (h != null)
         {
             return(h);
         }
     }
     return(null);
 }
Example #12
0
        // Create the mod
        public override void Create(PQS pqsVersion)
        {
            // Call base
            base.Create(pqsVersion);

            // Create the base mod (I need to instance this one, because some parameters aren't loadable. :( )
            PSystemBody body = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe");

            foreach (PQS ocean in body.pqsVersion.GetComponentsInChildren <PQS>(true))
            {
                if (ocean.name == "LaytheOcean")
                {
                    Utility.CopyObjectFields(ocean.GetComponentsInChildren <PQSMod_OceanFX>(true)[0], Mod);
                }
            }
        }
Example #13
0
 // Patch the FlightGlobalsIndex of bodies
 public static void PatchFGI(ref List <Int32> numbers, ref Int32 index, PSystemBody rootBody)
 {
     foreach (PSystemBody body in rootBody.children)
     {
         if (numbers.Contains(body.flightGlobalsIndex))
         {
             body.flightGlobalsIndex = index++;
         }
         if (body.celestialBody.isHomeWorld)
         {
             body.flightGlobalsIndex = 1; // Kerbin
         }
         numbers.Add(body.flightGlobalsIndex);
         PatchFGI(ref numbers, ref index, body);
     }
 }
                public static void AddCometTail(PSystemBody body, Tail tail)
                {
                    Transform scaledVersion = body.scaledVersion.transform;

                    GameObject obj = new GameObject("CometTail");

                    obj.layer            = GameLayers.ScaledSpace;
                    obj.transform.parent = Kopernicus.Utility.Deactivator;

                    MeshRenderer mr = obj.AddComponent <MeshRenderer>();
                    MeshFilter   mf = obj.AddComponent <MeshFilter>();

                    Teardrop teardrop = new Teardrop(1f, (tail.length / tail.radius), 60, 90);

                    mf.mesh = teardrop;

                    mr.sharedMaterial = new Material(ShaderLoader.GetShader("KopernicusExpansion/CometTail"));

                    //set default material values
                    mr.sharedMaterial.SetColor("_TintColor", new Color(tail.color.r, tail.color.g, tail.color.b, 0.5f));

                    mr.sharedMaterial.SetFloat("_RimPower", tail.rimPower);
                    mr.sharedMaterial.SetFloat("_Distortion", tail.distortion);
                    mr.sharedMaterial.SetFloat("_AlphaDistortion", tail.alphaDistortion);
                    mr.sharedMaterial.SetFloat("_ZDistortion", tail.zDistortion);
                    mr.sharedMaterial.SetFloat("_VertexDistortion", 0f);
                    mr.sharedMaterial.SetFloat("_Frequency", tail.frequency);
                    mr.sharedMaterial.SetFloat("_Lacunarity", tail.lacunarity);
                    mr.sharedMaterial.SetFloat("_Gain", tail.gain);

                    mr.shadowCastingMode = ShadowCastingMode.Off;
                    mr.receiveShadows    = false;

                    CometTailController cometController = obj.AddComponent <CometTailController>();

                    cometController.type            = tail.type;
                    cometController.color           = tail.color;
                    cometController.orbit           = body.celestialBody.orbit;
                    cometController.opacityCurve    = tail.opacityCurve;
                    cometController.brightnessCurve = tail.brightnessCurve;

                    obj.transform.parent        = scaledVersion;
                    obj.transform.localPosition = Vector3.zero;
                    obj.transform.localScale    = (Vector3.one * tail.length);
                    obj.SetActive(true);
                    obj.layer = GameLayers.ScaledSpace;
                }
Example #15
0
        /// <summary>
        /// Changes the parameters of the body
        /// </summary>
        public override Boolean Tweak(CelestialBody body)
        {
            // Does this body have an atmosphere?
            if (!body.atmosphere)
            {
                return(false);
            }

            //Report::Report.fetch.SetPrefix("PlanetaryBody: " + body.bodyDisplayName);
            // Prefab
            PSystemBody pSystemBody = Resources.FindObjectsOfTypeAll <PSystemBody>().FirstOrDefault(b => b.celestialBody.bodyName == body.transform.name);

            // Get a multiplier
            Single mult = (Single)GetRandomDouble(HighLogic.CurrentGame.Seed, 0.9, 1.1);

            // Apply it to both curves
            if (body.atmosphereUsePressureCurve)
            {
                //Report::Report.fetch.ReportLine("Original atmospheric pressure curve: " + body.atmospherePressureCurve.ToString());
                //Report::Report.fetch.ReportLine("Original atmospheric pressure sea level: " + body.atmospherePressureSeaLevel.ToString());
                body.atmospherePressureCurve     = new FloatCurve(pSystemBody.celestialBody.atmospherePressureCurve.Curve.keys.Select(k => new Keyframe(k.time, k.value * mult, k.inTangent, k.outTangent)).ToArray());
                body.atmospherePressureSeaLevel *= mult;

                //Report::Report.fetch.ReportLine("New atmospheric pressure curve: " + body.atmospherePressureCurve.ToString());
                //Report::Report.fetch.ReportLine("New atmospheric pressure sea level: " + body.atmospherePressureSeaLevel.ToString());
            }
            if (body.atmosphereUseTemperatureCurve)
            {
                //Report::Report.fetch.ReportLine("Original atmospheric temperature curve: " + body.atmosphereTemperatureCurve.ToString());
                //Report::Report.fetch.ReportLine("Original atmospheric temperature sea level: " + body.atmosphereTemperatureSeaLevel.ToString());

                body.atmosphereTemperatureCurve     = new FloatCurve(pSystemBody.celestialBody.atmosphereTemperatureCurve.Curve.keys.Select(k => new Keyframe(k.time, k.value * mult, k.inTangent, k.outTangent)).ToArray());
                body.atmosphereTemperatureSeaLevel *= mult;

                //Report::Report.fetch.ReportLine("New atmospheric temperature curve: " + body.atmosphereTemperatureCurve.ToString());
                //Report::Report.fetch.ReportLine("New atmospheric temperature sea level: " + body.atmosphereTemperatureSeaLevel.ToString());
            }
            if (body.atmosphereUsePressureCurve || body.atmosphereUseTemperatureCurve)
            {
                //Report::Report.fetch.ReportSection();
            }
            //Report::Report.fetch.ClearPrefix();

            // Did we tweak something?
            return(body.atmosphereUsePressureCurve || body.atmosphereUseTemperatureCurve);
        }
Example #16
0
                // Create the mod
                public override void Create(PQSMod_OceanFX _mod, PQS pqsVersion)
                {
                    // Call base
                    base.Create(_mod, pqsVersion);

                    // Create the base mod if needed
                    if (mod.reflection == null)
                    {
                        PSystemBody Body = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe");
                        foreach (PQS ocean in Body.pqsVersion.GetComponentsInChildren <PQS>(true))
                        {
                            if (ocean.name == "LaytheOcean")
                            {
                                Utility.CopyObjectFields(ocean.GetComponentsInChildren <PQSMod_OceanFX>(true)[0], mod);
                            }
                        }
                    }
                }
Example #17
0
        /// <summary>
        /// Changes the parameters of the body
        /// </summary>
        public override Boolean Tweak(CelestialBody body)
        {
            // Does the body have an orbit?
            if (body.orbit == null)
            {
                return(false);
            }

            // Prefab
            PSystemBody pSystemBody = Resources.FindObjectsOfTypeAll <PSystemBody>().FirstOrDefault(b => b.celestialBody.bodyName == body.transform.name);

            if (pSystemBody == null)
            {
                return(false);
            }

            // Inclination
            if (GetRandom(HighLogic.CurrentGame.Seed, 0, 100) < 20)
            {
                body.orbitDriver.orbit.inclination = GetRandomDouble(HighLogic.CurrentGame.Seed, -3, 3);
            }

            // SMA
            body.orbitDriver.orbit.semiMajorAxis = pSystemBody.orbitDriver.orbit.semiMajorAxis * GetRandomDouble(HighLogic.CurrentGame.Seed, 0.8, 1.2);

            // LAN
            body.orbitDriver.orbit.LAN = GetRandom(HighLogic.CurrentGame.Seed, 0, 361);

            // MeanAnomalyAtEpoch
            body.orbitDriver.orbit.meanAnomalyAtEpoch = GetRandom(HighLogic.CurrentGame.Seed, 0, 361) * Math.PI / 180d;

            // argumentOfPeriapsis
            body.orbitDriver.orbit.argumentOfPeriapsis = GetRandom(HighLogic.CurrentGame.Seed, 0, 361);

            // Eccentricy
            body.orbitDriver.orbit.eccentricity = pSystemBody.orbitDriver.orbit.eccentricity * GetRandomDouble(HighLogic.CurrentGame.Seed, 0.8, 1.2);

            // Update
            body.orbitDriver.UpdateOrbit();
            body.CBUpdate();

            // Done
            return(true);
        }
Example #18
0
        private static PSystemBody GetBody(string name, PSystemBody root)
        {
            if (root.celestialBody.bodyName == name)
            {
                return(root);
            }

            for (int i = 0; i < root.children.Count; i++)
            {
                PSystemBody pBody = GetBody(name, root.children[i]);

                if (pBody != null)
                {
                    return(pBody);
                }
            }

            return(null);
        }
        void Start()
        {
            PSystemBody parent = PSystemManager.Instance.systemPrefab.GetComponentsInChildren <PSystemBody>(true).First(b => b.name == "M-Kel");

            parent.children.Clear();

            foreach (string star in new[] { "M-Kel A", "M-Kel B", "M-Kel C" })
            {
                parent.children.Add(PSystemManager.Instance.systemPrefab.GetComponentsInChildren <PSystemBody>(true).First(b => b.name == star));
            }

            FieldInfo  list = typeof(RDArchivesController).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Skip(7).First();
            MethodInfo add  = typeof(RDArchivesController).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).Skip(27).First();
            var        RDAC = Resources.FindObjectsOfTypeAll <RDArchivesController>().First();

            list.SetValue(RDAC, new Dictionary <string, List <RDArchivesController.Filter> >());

            add.Invoke(RDAC, null);
        }
        public static PSystemBody GenerateSystemBody(PSystem system, PSystemBody parent, string templateName, string name, Orbit orbit)
        {
            // Look up the template body
            PSystemBody template = Utility.FindBody(system.rootBody, templateName);

            // Create a new celestial body as a clone of this template
            PSystemBody clone = system.AddBody(parent);

            clone.name = name;

            // Set up the celestial body of the clone (back up the orbit driver)
            Utility.CopyObjectFields <CelestialBody> (template.celestialBody, clone.celestialBody);
            clone.celestialBody.bodyName       = name;
            clone.celestialBody.orbitingBodies = null;
            clone.celestialBody.orbitDriver    = clone.orbitDriver;
            clone.flightGlobalsIndex           = 100 + template.flightGlobalsIndex;

            // Setup the orbit driver
            clone.orbitRenderer.orbitColor  = template.orbitRenderer.orbitColor;
            clone.orbitDriver.orbit         = orbit;
            clone.orbitDriver.celestialBody = clone.celestialBody;
            clone.orbitDriver.updateMode    = OrbitDriver.UpdateMode.UPDATE;

            // Setup the deactivator object
            GameObject deactivator = new GameObject("Deactivator");

            deactivator.SetActive(false);
            UnityEngine.Object.DontDestroyOnLoad(deactivator);

            // Clone the template's PQS
            clone.pqsVersion = UnityEngine.Object.Instantiate(template.pqsVersion) as PQS;
            clone.pqsVersion.transform.parent = deactivator.transform;
            clone.pqsVersion.name             = name;

            // Clone the scaled space
            clone.scaledVersion = UnityEngine.Object.Instantiate(template.scaledVersion) as GameObject;
            clone.scaledVersion.transform.parent = deactivator.transform;
            clone.scaledVersion.name             = name;

            return(clone);
        }
        void Start()
        {
            // If Kopernicus is loaded, we have to use it's ReferenceGeosphere, because we have no chance to get the unmodified version before it might get changed by Kopernicus
            Types = AssemblyLoader.loadedAssemblies.SelectMany(s => s.assembly.GetTypes()).ToArray();
            Type templates = Types.FirstOrDefault(t => t.Name == "Templates" && t.Namespace == "Kopernicus");

            if (templates != null)
            {
                ReferenceGeosphere    = templates.GetProperty("ReferenceGeosphere")?.GetValue(null, null) as Mesh;
                IsKopernicusInstalled = true;
            }
            else
            {
                // We need to get the body for Jool (to steal it's mesh)
                PSystemBody Jool = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Jool");

                // Return it's mesh
                ReferenceGeosphere = Jool.scaledVersion.GetComponent <MeshFilter>().sharedMesh;
            }
            Destroy(this);
        }
Example #22
0
        public Star(StarSystemDefintion star, PSystemBody InternalStarPSB,PSystemBody InternalSunPSB)
        {
            defintion = star;
            var InternalStarCB = InternalStarPSB.celestialBody;

            //Set Star CB and PSB Parameters
            InternalStarPSB.name = star.Name;
            InternalStarPSB.flightGlobalsIndex = star.FlightGlobalsIndex;
            InternalStarPSB.children.Clear();

            InternalStarPSB.enabled = false;

            InternalStarCB.bodyName = star.Name;

            InternalStarCB.Radius = star.Radius;

            InternalStarCB.CBUpdate();

            //Add Star to Sun children
            InternalSunPSB.children.Add(InternalStarPSB);
        }
Example #23
0
        // Copy of above, but finds homeworld
        public static PSystemBody FindHomeBody(PSystemBody body)
        {
            // Is this the body wer are looking for?
            if (body.celestialBody.isHomeWorld)
            {
                return(body);
            }

            // Otherwise search children
            foreach (PSystemBody child in body.children)
            {
                PSystemBody b = FindHomeBody(child);
                if (b != null)
                {
                    return(b);
                }
            }

            // Return null because we didn't find shit
            return(null);
        }
Example #24
0
        /// <summary>
        /// Recursively searches for a named PSystemBody
        /// </summary>
        /// <param name="body">Parent body to begin search in</param>
        /// <param name="name">Name of body to find</param>
        /// <returns>Desired body or null if not found</returns>
        public static PSystemBody FindBody(PSystemBody body, String name)
        {
            // Is this the body wer are looking for?
            if (body.celestialBody.bodyName == name)
            {
                return(body);
            }

            // Otherwise search children
            foreach (PSystemBody child in body.children)
            {
                PSystemBody b = FindBody(child, name);
                if (b != null)
                {
                    return(b);
                }
            }

            // Return null because we didn't find shit
            return(null);
        }
Example #25
0
        public Star(StarSystemDefintion star, PSystemBody InternalStarPSB, PSystemBody InternalSunPSB)
        {
            defintion = star;
            var InternalStarCB = InternalStarPSB.celestialBody;

            //Set Star CB and PSB Parameters
            InternalStarPSB.name = star.Name;
            InternalStarPSB.flightGlobalsIndex = star.FlightGlobalsIndex;
            InternalStarPSB.children.Clear();

            InternalStarPSB.enabled = false;

            InternalStarCB.bodyName = star.Name;

            InternalStarCB.Radius = star.Radius;

            InternalStarCB.CBUpdate();

            //Add Star to Sun children
            InternalSunPSB.children.Add(InternalStarPSB);
        }
Example #26
0
        public SigmaOrbitLoader(PSystemBody body)
        {
            // Is this the parser context?
            if (!Injector.IsInPrefab)
            {
                throw new InvalidOperationException("Must be executed in Injector context.");
            }

            // If this body needs orbit controllers, create them
            if (body.orbitDriver == null)
            {
                body.orbitDriver   = body.celestialBody.gameObject.AddComponent <OrbitDriver>();
                body.orbitRenderer = body.celestialBody.gameObject.AddComponent <OrbitRenderer>();
            }
            body.celestialBody.gameObject.AddOrGetComponent <OrbitRendererUpdater>();
            body.orbitDriver.updateMode = OrbitDriver.UpdateMode.UPDATE;

            // Store values
            Value                   = body.celestialBody;
            Value.orbitDriver       = body.orbitDriver;
            Value.orbitDriver.orbit = body.orbitDriver.orbit ?? new Orbit();
        }
Example #27
0
        // Initialisation
        static Templates()
        {
            // We need to get the body for Jool (to steal it's mesh)
            PSystemBody Jool = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Jool");

            // Return it's mesh
            ReferenceGeosphere = Jool.scaledVersion.GetComponent <MeshFilter>().sharedMesh;

            // Create Dictionaries
            sphereOfInfluence = new Dictionary <string, double>();
            hillSphere        = new Dictionary <string, double>();
            drawIcons         = new Dictionary <string, OrbitRenderer.DrawIcons>();
            drawMode          = new Dictionary <string, OrbitRenderer.DrawMode>();

            // Create lists
            barycenters    = new List <string>();
            notSelectable  = new List <string>();
            finalizeBodies = new List <string>();

            // Main Menu body
            menuBody = "Kerbin";
        }
        /// <summary>
        /// Changes the name of a body as if it would be created with the new name
        /// </summary>
        public static void RenameBody(PSystemBody generatedBody, String name)
        {
            // Patch the game object names in the template
            String oldName = generatedBody.name;

            generatedBody.name = name;
            generatedBody.celestialBody.bodyName           = name;
            generatedBody.celestialBody.transform.name     = name;
            generatedBody.celestialBody.bodyTransform.name = name;
            generatedBody.scaledVersion.name = name;
            if (generatedBody.pqsVersion != null)
            {
                generatedBody.pqsVersion.name            = name;
                generatedBody.pqsVersion.gameObject.name = name;
                generatedBody.pqsVersion.transform.name  = name;
                foreach (PQS p in generatedBody.pqsVersion.GetComponentsInChildren <PQS>(true))
                {
                    p.name = p.name.Replace(oldName, name);
                }
                generatedBody.celestialBody.pqsController = generatedBody.pqsVersion;
            }
        }
Example #29
0
        // Initialisation
        static Templates()
        {
            // We need to get the body for Jool (to steal it's mesh)
            PSystemBody Jool = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Jool");

            // Return it's mesh
            ReferenceGeosphere = Jool.scaledVersion.GetComponent <MeshFilter>().sharedMesh;

            // Main Menu body
            menuBody = "Kerbin";

            // Random Main Menu bodies
            randomMainMenuBodies = new List <String>();

            // Presets
            PresetDisplayNames = new List <String>
            {
                Localizer.Format("#autoLOC_6001506"),
                Localizer.Format("#autoLOC_6001507"),
                Localizer.Format("#autoLOC_6001508")
            };
        }
Example #30
0
            // Apply event
            void IParserEventSubscriber.Apply(ConfigNode node)
            {
                // Waaaah
                SpaceCenter.Instance = null;

                // Instantiate (clone) the template body
                GameObject bodyGameObject = UnityEngine.Object.Instantiate(originalBody.gameObject) as GameObject;

                bodyGameObject.name             = originalBody.name;
                bodyGameObject.transform.parent = Utility.Deactivator;
                body          = bodyGameObject.GetComponent <PSystemBody>();
                body.children = new List <PSystemBody>();

                // Clone the scaled version
                body.scaledVersion = UnityEngine.Object.Instantiate(originalBody.scaledVersion) as GameObject;
                body.scaledVersion.transform.parent = Utility.Deactivator;
                body.scaledVersion.name             = originalBody.scaledVersion.name;

                // Clone the PQS version (if it has one) and we want the PQS
                if (body.pqsVersion != null && removePQS.Value != true)
                {
                    body.pqsVersion = UnityEngine.Object.Instantiate(originalBody.pqsVersion) as PQS;
                    body.pqsVersion.transform.parent = Utility.Deactivator;
                    body.pqsVersion.name             = originalBody.pqsVersion.name;
                }
                else
                {
                    // Make sure we have no ties to the PQS, as we wanted to remove it or it didn't exist
                    body.pqsVersion          = null;
                    body.celestialBody.ocean = false;
                }

                // Store the initial radius (so scaled version can be computed)
                radius = body.celestialBody.Radius;

                // Event
                Events.OnTemplateLoaderApply.Fire(this, node);
            }
Example #31
0
        // Post spawn fixups (ewwwww........)
        public void PostSpawnFixups()
        {
            // Fix the flight globals index of each body
            int counter = 0;

            foreach (CelestialBody body in FlightGlobals.Bodies)
            {
                body.flightGlobalsIndex = counter++;
                Logger.Active.Log("Found Body: " + body.bodyName + ":" + body.flightGlobalsIndex + " -> SOI = " + body.sphereOfInfluence + ", Hill Sphere = " + body.hillSphere);
            }

            // Fix the maximum viewing distance of the map view camera (get the farthest away something can be from the root object)
            PSystemBody rootBody        = PSystemManager.Instance.systemPrefab.rootBody;
            double      maximumDistance = rootBody.children.Max(b => (b.orbitDriver != null) ? b.orbitDriver.orbit.semiMajorAxis * (1 + b.orbitDriver.orbit.eccentricity) : 0);

            PlanetariumCamera.fetch.maxDistance = ((float)maximumDistance * 3.0f) / ScaledSpace.Instance.scaleFactor;

            // Select the closest star to home
            StarLightSwitcher.HomeStar().SetAsActive();

            // Fixups complete, time to surrender to fate
            Destroy(this);
        }
Example #32
0
        public CoronaLoader(CelestialBody body)
        {
            // Is this a spawned body?
            if (body.scaledBody == null || Injector.IsInPrefab)
            {
                throw new InvalidOperationException("The body must be already spawned by the PSystemManager.");
            }

            // We need to get the body for the Sun (to steal it's corona mesh)
            PSystemBody sun = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Sun");

            // Clone a default Corona
            GameObject corona =
                UnityEngine.Object.Instantiate(sun.scaledVersion.GetComponentsInChildren <SunCoronas>(true).First()
                                               .gameObject);

            // Backup local transform parameters
            Vector3    localPosition = corona.transform.localPosition;
            Vector3    localScale    = corona.transform.localScale;
            Quaternion localRotation = corona.transform.rotation;

            // Parent the new corona
            corona.transform.parent = body.scaledBody.transform;

            // Restore the local transform settings
            corona.transform.localPosition = localPosition;
            corona.transform.localScale    = localScale;
            corona.transform.localRotation = localRotation;

            Value = corona.GetComponent <SunCoronas>();

            // Setup the material loader
            Material = new ParticleAddSmoothLoader(corona.GetComponent <Renderer>().sharedMaterial)
            {
                name = Guid.NewGuid().ToString()
            };
        }
Example #33
0
        public PQSLoader(CelestialBody body)
        {
            // Is this a spawned body?
            if (body.scaledBody == null || Injector.IsInPrefab)
            {
                throw new InvalidOperationException("The body must be already spawned by the PSystemManager.");
            }

            if (body.pqsController != null)
            {
                // Save the PQSVersion
                Value = body.pqsController;

                // Get the required PQS information
                _transform = Value.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true)
                             .FirstOrDefault(mod => mod.transform.parent == Value.transform);
                _collider = Value.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true)
                            .FirstOrDefault(mod => mod.transform.parent == Value.transform);

                // Clone the surface material of the PQS
                if (MaterialType == SurfaceMaterialType.AtmosphericOptimized)
                {
                    SurfaceMaterial = new PQSMainOptimisedLoader(SurfaceMaterial);
                }
                else if (MaterialType == SurfaceMaterialType.AtmosphericMain)
                {
                    SurfaceMaterial = new PQSMainShaderLoader(SurfaceMaterial);
                }
                else if (MaterialType == SurfaceMaterialType.AtmosphericBasic)
                {
                    SurfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(SurfaceMaterial);
                }
                else if (MaterialType == SurfaceMaterialType.Vacuum)
                {
                    SurfaceMaterial = new PQSProjectionSurfaceQuadLoader(SurfaceMaterial);
                }
                else if (MaterialType == SurfaceMaterialType.AtmosphericExtra)
                {
                    SurfaceMaterial = new PQSMainExtrasLoader(SurfaceMaterial);
                }

                SurfaceMaterial.name = Guid.NewGuid().ToString();

                // Clone the fallback material of the PQS
                FallbackMaterial = new PQSProjectionFallbackLoader(FallbackMaterial)
                {
                    name = Guid.NewGuid().ToString()
                };
            }
            else
            {
                // Create a new PQS
                GameObject controllerRoot = new GameObject();
                controllerRoot.transform.parent = body.transform;
                Value = controllerRoot.AddComponent <PQS>();

                // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work...
                // And I (Thomas) am at this time just too lazy to do it differently...
                PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe");
                Utility.CopyObjectFields(laythe.pqsVersion, Value);
                Value.surfaceMaterial = laythe.pqsVersion.surfaceMaterial;

                // Create the fallback material (always the same shader)
                FallbackMaterial       = new PQSProjectionFallbackLoader();
                Value.fallbackMaterial = FallbackMaterial;
                FallbackMaterial.name  = Guid.NewGuid().ToString();

                // Create the celestial body transform
                GameObject mod = new GameObject("_CelestialBody");
                mod.transform.parent                  = controllerRoot.transform;
                _transform                            = mod.AddComponent <PQSMod_CelestialBodyTransform>();
                _transform.sphere                     = Value;
                _transform.forceActivate              = false;
                _transform.deactivateAltitude         = 115000;
                _transform.forceRebuildOnTargetChange = false;
                _transform.planetFade                 = new PQSMod_CelestialBodyTransform.AltitudeFade
                {
                    fadeFloatName      = "_PlanetOpacity",
                    fadeStart          = 100000.0f,
                    fadeEnd            = 110000.0f,
                    valueStart         = 0.0f,
                    valueEnd           = 1.0f,
                    secondaryRenderers = new List <GameObject>()
                };
                _transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0];
                _transform.requirements   = PQS.ModiferRequirements.Default;
                _transform.modEnabled     = true;
                _transform.order          = 10;

                // Create the material direction
                // ReSharper disable Unity.InefficientPropertyAccess
                mod = new GameObject("_Material_SunLight");
                mod.transform.parent = controllerRoot.gameObject.transform;
                PQSMod_MaterialSetDirection lightDirection = mod.AddComponent <PQSMod_MaterialSetDirection>();
                lightDirection.sphere       = Value;
                lightDirection.valueName    = "_sunLightDirection";
                lightDirection.requirements = PQS.ModiferRequirements.Default;
                lightDirection.modEnabled   = true;
                lightDirection.order        = 100;

                // Create the UV planet relative position
                mod = new GameObject("_Material_SurfaceQuads");
                mod.transform.parent = controllerRoot.transform;
                PQSMod_UVPlanetRelativePosition uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>();
                uvs.sphere       = Value;
                uvs.requirements = PQS.ModiferRequirements.Default;
                uvs.modEnabled   = true;
                uvs.order        = 999999;

                // Crete the quad mesh colliders
                mod = new GameObject("QuadMeshColliders");
                mod.transform.parent     = controllerRoot.gameObject.transform;
                _collider                = mod.AddComponent <PQSMod_QuadMeshColliders>();
                _collider.sphere         = Value;
                _collider.maxLevelOffset = 0;
                _collider.requirements   = PQS.ModiferRequirements.Default;
                _collider.modEnabled     = true;
                _collider.order          = 100;
                // ReSharper restore Unity.InefficientPropertyAccess
            }

            // Assigning the new PQS
            body.pqsController = Value;
            Transform transform = body.transform;

            body.pqsController.name            = transform.name;
            body.pqsController.transform.name  = transform.name;
            body.pqsController.gameObject.name = transform.name;
            body.pqsController.radius          = body.Radius;

            // Add an OnDemand Handler
            if (Value.GetComponentsInChildren <PQSMod_OnDemandHandler>(true).Length == 0)
            {
                OnDemandStorage.AddHandler(Value);
            }

            // Load existing mods
            foreach (PQSMod mod in Value.GetComponentsInChildren <PQSMod>(true).Where(m => m.sphere == Value))
            {
                Type modType       = mod.GetType();
                Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType);
                foreach (Type loaderType in Parser.ModTypes)
                {
                    if (!modLoaderType.IsAssignableFrom(loaderType))
                    {
                        continue;
                    }

                    // We found our loader type
                    IModLoader loader = (IModLoader)Activator.CreateInstance(loaderType);
                    loader.Create(mod, Value);
                    Mods.Add(loader);
                }
            }
        }
 public void ListPlanetsRecursive(PSystemBody body)
 {
     Templates.Add( body );
     foreach (PSystemBody current in body.children)
     {
         ListPlanetsRecursive(current);
     }
 }
		public static void AddCometTail(PSystemBody body, CometTail tail)
		{
			Transform scaledVersion = body.scaledVersion.transform;

			GameObject obj = new GameObject ("CometTail");
			obj.layer = GameLayers.ScaledSpace;
			obj.transform.parent = Kopernicus.Utility.Deactivator;

			var mr = obj.AddComponent<MeshRenderer> ();
			var mf = obj.AddComponent<MeshFilter> ();

			var teardrop = new Teardrop (1f, (tail.length / tail.radius), 60, 90);
			mf.mesh = teardrop;

			if (Settings.AllowAdvancedCometShader)
			{
				mr.sharedMaterial = new Material (Shaders.CometTail);

				//set default material values
				mr.sharedMaterial.SetColor ("_TintColor", new Color(tail.color.r, tail.color.g, tail.color.b, 0.5f));

				mr.sharedMaterial.SetFloat ("_RimPower", tail.rimPower);
				mr.sharedMaterial.SetFloat ("_Distortion", tail.distortion);
				mr.sharedMaterial.SetFloat ("_AlphaDistortion", tail.alphaDistortion);
				mr.sharedMaterial.SetFloat ("_ZDistortion", tail.zDistortion);
				mr.sharedMaterial.SetFloat ("_VertexDistortion", 0f);
				mr.sharedMaterial.SetFloat ("_Frequency", tail.frequency);
				mr.sharedMaterial.SetFloat ("_Lacunarity", tail.lacunarity);
				mr.sharedMaterial.SetFloat ("_Gain", tail.gain);
			}
			else
			{
				mr.sharedMaterial = new Material (Shader.Find(FallbackShader));

				//set default material values
				mr.sharedMaterial.SetColor ("_TintColor", new Color(tail.color.r, tail.color.g, tail.color.b, 0.3f));
			}

			mr.castShadows = false;
			mr.receiveShadows = false;

			var cometController = obj.AddComponent<CometTailController> ();
			cometController.targetBodyName = "Sun";
			cometController.usingAdvancedShader = Settings.AllowAdvancedCometShader;
			cometController.type = tail.type;
			cometController.color = tail.color;
			cometController.orbit = body.celestialBody.orbit;
			cometController.opacityCurve = tail.opacityCurve;
			cometController.brightnessCurve = tail.brightnessCurve;

			obj.transform.parent = scaledVersion;
			obj.transform.localPosition = Vector3.zero;
			obj.transform.localScale = (Vector3.one * tail.length);
			obj.SetActive (true);
			obj.layer = GameLayers.ScaledSpace;

			//initialize comet
			cometController.Init ();
		}
Example #36
0
 // Populate the PSystemBody with the results of the orbit loader
 public void Apply(PSystemBody body)
 {
     if (!double.IsNaN(Templates.instance.epoch))
     {
         if (hasEpoch)
             orbit.epoch += Templates.instance.epoch;
         else
             orbit.epoch = Templates.instance.epoch;
     }
     body.orbitDriver.orbit = orbit;
     body.orbitRenderer.orbitColor = color.value;
     body.orbitRenderer.lowerCamVsSmaRatio = cameraSmaRatioBounds.value[0];
     body.orbitRenderer.upperCamVsSmaRatio = cameraSmaRatioBounds.value[1];
 }
Example #37
0
 // Sort bodies by distance from parent body
 private void RecursivelySortBodies(PSystemBody body)
 {
     body.children = body.children.OrderBy(b => b.orbitDriver.orbit.semiMajorAxis * (1 + b.orbitDriver.orbit.eccentricity)).ToList();
     foreach (PSystemBody child in body.children)
     {
         RecursivelySortBodies (child);
     }
 }
Example #38
0
 // Patch the FlightGlobalsIndex of bodies
 private void PatchFGI(ref List<int> numbers, ref int index, PSystemBody rootBody)
 {
     foreach (PSystemBody body in rootBody.children)
     {
         if (numbers.Contains(body.flightGlobalsIndex))
             body.flightGlobalsIndex = index++;
         numbers.Add(body.flightGlobalsIndex);
         PatchFGI(ref numbers, ref index, body);
     }
 }
 public void findPrefabBodies(PSystemBody body)
 {
     prefabBodies[body.celestialBody.name] = body;
     foreach (var c in body.children)
     {
         findPrefabBodies(c);
     }
 }
Example #40
0
            // Apply event
            void IParserEventSubscriber.Apply(ConfigNode node)
            {
                // Instantiate (clone) the template body
                GameObject bodyGameObject = UnityEngine.Object.Instantiate (originalBody.gameObject) as GameObject;
                bodyGameObject.name = originalBody.name;
                bodyGameObject.transform.parent = Utility.Deactivator;
                body = bodyGameObject.GetComponent<PSystemBody> ();
                body.children = new List<PSystemBody> ();

                // Clone the scaled version
                body.scaledVersion = UnityEngine.Object.Instantiate (originalBody.scaledVersion) as GameObject;
                body.scaledVersion.transform.parent = Utility.Deactivator;
                body.scaledVersion.name = originalBody.scaledVersion.name;

                // Clone the PQS version (if it has one) and we want the PQS
                if (body.pqsVersion != null && removePQS.value != true)
                {
                    body.pqsVersion = UnityEngine.Object.Instantiate (originalBody.pqsVersion) as PQS;
                    body.pqsVersion.transform.parent = Utility.Deactivator;
                    body.pqsVersion.name = originalBody.pqsVersion.name;
                }
                else
                {
                    // Make sure we have no ties to the PQS, as we wanted to remove it or it didn't exist
                    body.pqsVersion = null;
                    body.celestialBody.ocean = false;
                }

                // Store the initial radius (so scaled version can be computed)
                radius = body.celestialBody.Radius;
            }
Example #41
0
            // Copy orbit provided
            public OrbitLoader(PSystemBody body)
            {
                this.orbit = body.orbitDriver.orbit;
                this.color.value = body.orbitRenderer.orbitColor;

                float[] bounds = new float[] {body.orbitRenderer.lowerCamVsSmaRatio, body.orbitRenderer.upperCamVsSmaRatio};
                this.cameraSmaRatioBounds.value = new List<float>(bounds);
            }
Example #42
0
        public static void GetUsedLists(List<MapSO> mapList, List<Texture> texList, PSystemBody body)
        {
            // get the biome map
            if (body.celestialBody.BiomeMap != null)
                mapList.Add(body.celestialBody.BiomeMap);

            // get any MapSOs in PQSs
            if (body.pqsVersion != null)
            {
                AddMapSOs(mapList, body.pqsVersion); // main PQS

                // get other PQSs (like ocean)
                PQS[] pqss = body.pqsVersion.GetComponentsInChildren<PQS>(true);
                foreach(PQS p in pqss)
                    if(p != body.pqsVersion)
                        AddMapSOs(mapList, p);

            }
            if (body.scaledVersion != null)
                AddTexes(texList, body.scaledVersion);

            // Recurse
            foreach (PSystemBody child in body.children)
                GetUsedLists(mapList, texList, child);
        }
        public static PSystemBody GenerateSystemBody(PSystem system, PSystemBody parent, String name, Orbit orbit = null)
        {
            PSystemBody Jool = Utility.FindBody (system.rootBody, "Jool");  // Need the geosphere for scaled version
            PSystemBody Laythe = Utility.FindBody (system.rootBody, "Laythe"); // Need pqs and ocean definitions

            //Utility.DumpObject (Laythe.celestialBody, " Laythe Celestial Body ");
            //Utility.DumpObject (Laythe.pqsVersion, " Laythe PQS ");
            //Transform laytheOcean = Utility.FindInChildren (Laythe.pqsVersion.transform, "LaytheOcean");
            //Utility.DumpObject (laytheOcean.GetComponent<PQS> (), " Laythe Ocean PQS ");

            // AddBody makes the GameObject and stuff. It also attaches it to the system and parent.
            PSystemBody body = system.AddBody (parent);

            // set up the various parameters
            body.name = name;
            body.flightGlobalsIndex = 100;

            // Some parameters of the celestialBody, which represents the actual planet...
            // PSystemBody is more of a container that associates the planet with its orbit
            // and position in the planetary system, etc.
            body.celestialBody.bodyName               = name;
            body.celestialBody.bodyDescription        = "Merciful Kod, this thing just APPEARED! And unlike last time, it wasn't bird droppings on the telescope.";
            body.celestialBody.Radius                 = 320000;
            //body.celestialBody.Radius                 = 3380100;
            body.celestialBody.GeeASL                 = 0.3;
            //body.celestialBody.Mass                   = 6.4185E+23;
            body.celestialBody.Mass                   = 4.5154812E+21;
            body.celestialBody.timeWarpAltitudeLimits = (float[])Laythe.celestialBody.timeWarpAltitudeLimits.Clone();
            body.celestialBody.rotationPeriod         = 88642.6848;
            body.celestialBody.rotates                = true;
            body.celestialBody.BiomeMap               = GenerateCBAttributeMapSO(name);//Dres.celestialBody.BiomeMap;//
            body.celestialBody.scienceValues          = Laythe.celestialBody.scienceValues;
            body.celestialBody.ocean                  = false;

            // Presumably true of Kerbin. I do not know what the consequences are of messing with this exactly.
            // I think this just affects where the Planetarium/Tracking station starts.
            body.celestialBody.isHomeWorld            = false;

            // Setup the orbit of "Kopernicus."  The "Orbit" class actually is built to support serialization straight
            // from Squad, so storing these to files (and loading them) will be pretty easy.
            body.orbitRenderer.orbitColor             = Color.magenta;
            body.orbitDriver.celestialBody            = body.celestialBody;
            body.orbitDriver.updateMode               = OrbitDriver.UpdateMode.UPDATE;
            if (orbit == null)
                body.orbitDriver.orbit = new Orbit (0.0, 0.0, 47500000000, 0, 0, 0, 0, system.rootBody.celestialBody);
            else
                body.orbitDriver.orbit = orbit;

            #region PSystemBody.pqsVersion generation

            // Create the PQS controller game object for Kopernicus
            GameObject controllerRoot       = new GameObject(name);
            controllerRoot.layer            = Constants.GameLayers.LocalSpace;
            controllerRoot.transform.parent = Utility.Deactivator;

            // Create the PQS object and pull all the values from Dres (has some future proofing i guess? adapts to PQS changes)
            body.pqsVersion = controllerRoot.AddComponent<PQS>();
            Utility.CopyObjectFields(Laythe.pqsVersion, body.pqsVersion);
            //body.pqsVersion.surfaceMaterial = new PQSProjectionSurfaceQuad();
            //body.pqsVersion.fallbackMaterial = new PQSProjectionFallback();
            body.pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelative(Laythe.pqsVersion.surfaceMaterial); // use until we determine all the functions of the shader textures
            body.pqsVersion.fallbackMaterial = new PQSProjectionFallback(Laythe.pqsVersion.fallbackMaterial);
            body.pqsVersion.radius = body.celestialBody.Radius;
            body.pqsVersion.mapOcean = false;

            // Debug
            Utility.DumpObjectProperties(body.pqsVersion.surfaceMaterial, " Surface Material ");
            Utility.DumpObjectProperties(body.pqsVersion.fallbackMaterial, " Fallback Material ");

            // Detail defaults
            body.pqsVersion.maxQuadLenghtsPerFrame = 0.03f;
            body.pqsVersion.minLevel = 1;
            body.pqsVersion.maxLevel = 10;
            body.pqsVersion.minDetailDistance = 8;

            // Create the celestial body transform
            GameObject mod = new GameObject("_CelestialBody");
            mod.transform.parent = controllerRoot.transform;
            PQSMod_CelestialBodyTransform celestialBodyTransform = mod.AddComponent<PQSMod_CelestialBodyTransform>();
            celestialBodyTransform.sphere = body.pqsVersion;
            celestialBodyTransform.forceActivate = false;
            celestialBodyTransform.deactivateAltitude = 115000;
            celestialBodyTransform.forceRebuildOnTargetChange = false;
            celestialBodyTransform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade();
            celestialBodyTransform.planetFade.fadeFloatName = "_PlanetOpacity";
            celestialBodyTransform.planetFade.fadeStart = 100000.0f;
            celestialBodyTransform.planetFade.fadeEnd = 110000.0f;
            celestialBodyTransform.planetFade.valueStart = 0.0f;
            celestialBodyTransform.planetFade.valueEnd = 1.0f;
            celestialBodyTransform.planetFade.secondaryRenderers = new List<GameObject>();
            celestialBodyTransform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0];
            celestialBodyTransform.requirements = PQS.ModiferRequirements.Default;
            celestialBodyTransform.modEnabled = true;
            celestialBodyTransform.order = 10;

            // Create the color PQS mods
            mod = new GameObject("_Color");
            mod.transform.parent = controllerRoot.transform;
            PQSMod_VertexSimplexNoiseColor vertexSimplexNoiseColor = mod.AddComponent<PQSMod_VertexSimplexNoiseColor>();
            vertexSimplexNoiseColor.sphere = body.pqsVersion;
            vertexSimplexNoiseColor.seed = 45;
            vertexSimplexNoiseColor.blend = 1.0f;
            vertexSimplexNoiseColor.colorStart = new Color(0.768656731f, 0.6996614f, 0.653089464f, 1);
            vertexSimplexNoiseColor.colorEnd = new Color(0.0f, 0.0f, 0.0f, 1.0f);
            vertexSimplexNoiseColor.octaves = 12.0;
            vertexSimplexNoiseColor.persistence = 0.5;
            vertexSimplexNoiseColor.frequency = 2.0;
            vertexSimplexNoiseColor.requirements = PQS.ModiferRequirements.MeshColorChannel;
            vertexSimplexNoiseColor.modEnabled = true;
            vertexSimplexNoiseColor.order = 200;

            PQSMod_HeightColorMap heightColorMap = mod.AddComponent<PQSMod_HeightColorMap>();
            heightColorMap.sphere = body.pqsVersion;
            List<PQSMod_HeightColorMap.LandClass> landClasses = new List<PQSMod_HeightColorMap.LandClass>();

            PQSMod_HeightColorMap.LandClass landClass = new PQSMod_HeightColorMap.LandClass("AbyPl", 0.0, 0.5, new Color(0.0f, 0.0f, 0.0f, 1.0f), Color.white, double.NaN);
            landClass.lerpToNext = true;
            landClasses.Add(landClass);

            landClass = new PQSMod_HeightColorMap.LandClass("Beach", 0.5, 0.550000011920929, new Color(0.164179087f, 0.164179087f, 0.164179087f, 1.0f), Color.white, double.NaN);
            landClass.lerpToNext = true;
            landClasses.Add(landClass);

            landClass = new PQSMod_HeightColorMap.LandClass("Beach", 0.550000011920929, 1.0, new Color(0.373134315f, 0.373134315f, 0.373134315f, 1.0f), Color.white, double.NaN);
            landClass.lerpToNext = false;
            landClasses.Add(landClass);

            // Generate an array from the land classes list
            heightColorMap.landClasses = landClasses.ToArray();
            heightColorMap.blend = 0.7f;
            heightColorMap.lcCount = 3;
            heightColorMap.requirements = PQS.ModiferRequirements.MeshColorChannel;
            heightColorMap.modEnabled = true;
            heightColorMap.order = 201;

            // Create the alititude alpha mods
            mod = new GameObject("_Material_ModProjection");
            mod.transform.parent = controllerRoot.transform;
            PQSMod_AltitudeAlpha altitudeAlpha = mod.AddComponent<PQSMod_AltitudeAlpha>();
            altitudeAlpha.sphere = body.pqsVersion;
            altitudeAlpha.atmosphereDepth = 4000.0;
            altitudeAlpha.invert = false;
            altitudeAlpha.requirements = PQS.ModiferRequirements.Default;
            altitudeAlpha.modEnabled = false;
            altitudeAlpha.order = 999999999;

            // Create the aerial perspective material
            mod = new GameObject("_Material_AerialPerspective");
            mod.transform.parent = controllerRoot.transform;
            PQSMod_AerialPerspectiveMaterial aerialPerspectiveMaterial = mod.AddComponent<PQSMod_AerialPerspectiveMaterial>();
            aerialPerspectiveMaterial.sphere = body.pqsVersion;
            aerialPerspectiveMaterial.globalDensity = -0.00001f;
            aerialPerspectiveMaterial.heightFalloff = 6.75f;
            aerialPerspectiveMaterial.atmosphereDepth = 150000;
            aerialPerspectiveMaterial.DEBUG_SetEveryFrame = true;
            aerialPerspectiveMaterial.cameraAlt = 0;
            aerialPerspectiveMaterial.cameraAtmosAlt = 0;
            aerialPerspectiveMaterial.heightDensAtViewer = 0;
            aerialPerspectiveMaterial.requirements = PQS.ModiferRequirements.Default;
            aerialPerspectiveMaterial.modEnabled = true;
            aerialPerspectiveMaterial.order = 100;

            // Create the UV planet relative position
            mod = new GameObject("_Material_SurfaceQuads");
            mod.transform.parent = controllerRoot.transform;
            PQSMod_UVPlanetRelativePosition planetRelativePosition = mod.AddComponent<PQSMod_UVPlanetRelativePosition>();
            planetRelativePosition.sphere = body.pqsVersion;
            planetRelativePosition.requirements = PQS.ModiferRequirements.Default;
            planetRelativePosition.modEnabled = true;
            planetRelativePosition.order = 999999;

            // Create the height noise module
            mod = new GameObject("_HeightNoise");
            mod.transform.parent = controllerRoot.transform;
            PQSMod_VertexHeightMap vertexHeightMap = mod.gameObject.AddComponent<PQSMod_VertexHeightMap>();
            vertexHeightMap.sphere = body.pqsVersion;
            //vertexHeightMap.heightMapDeformity = 29457.0;
            vertexHeightMap.heightMapDeformity = 10000.0;
            vertexHeightMap.heightMapOffset = -1000.0;
            vertexHeightMap.scaleDeformityByRadius = false;
            vertexHeightMap.requirements = PQS.ModiferRequirements.MeshCustomNormals | PQS.ModiferRequirements.VertexMapCoords;
            vertexHeightMap.modEnabled = true;
            vertexHeightMap.order = 20;

            // Load the heightmap for this planet
            Texture2D map = new Texture2D(4, 4, TextureFormat.Alpha8, false);
            map.LoadImage(System.IO.File.ReadAllBytes(KSPUtil.ApplicationRootPath + PluginDirectory + "/Planets/" + name + "/Height.png"));
            vertexHeightMap.heightMap = ScriptableObject.CreateInstance<MapSO>();
            vertexHeightMap.heightMap.CreateMap(MapSO.MapDepth.Greyscale, map);
            UnityEngine.Object.DestroyImmediate(map);

            // Create the simplex height module
            PQSMod_VertexSimplexHeight vertexSimplexHeight = mod.AddComponent<PQSMod_VertexSimplexHeight>();
            vertexSimplexHeight.sphere = body.pqsVersion;
            vertexSimplexHeight.seed = 670000;
            vertexSimplexHeight.deformity = 1700.0;
            vertexSimplexHeight.octaves = 12.0;
            vertexSimplexHeight.persistence = 0.5;
            vertexSimplexHeight.frequency = 4.0;
            vertexSimplexHeight.requirements = PQS.ModiferRequirements.MeshCustomNormals;
            vertexSimplexHeight.modEnabled = true;
            vertexSimplexHeight.order = 21;

            // SERIOUSLY RECOMMENDED FOR NO OCEAN WORLDS
            // Create the flatten ocean module
            PQSMod_FlattenOcean flattenOcean = mod.AddComponent<PQSMod_FlattenOcean>();
            flattenOcean.sphere = body.pqsVersion;
            flattenOcean.oceanRadius = 1.0;
            flattenOcean.requirements = PQS.ModiferRequirements.MeshCustomNormals;
            flattenOcean.modEnabled = true;
            flattenOcean.order = 25;

            // Creat the vertex height noise module
            PQSMod_VertexHeightNoise vertexHeightNoise = mod.AddComponent<PQSMod_VertexHeightNoise>();
            vertexHeightNoise.sphere = body.pqsVersion;
            vertexHeightNoise.noiseType = PQSMod_VertexHeightNoise.NoiseType.RiggedMultifractal;
            vertexHeightNoise.deformity = 1000.0f;
            vertexHeightNoise.seed = 5906;
            vertexHeightNoise.frequency = 2.0f;
            vertexHeightNoise.lacunarity = 2.5f;
            vertexHeightNoise.persistance = 0.5f;
            vertexHeightNoise.octaves = 4;
            vertexHeightNoise.mode = LibNoise.Unity.QualityMode.Low;
            vertexHeightNoise.requirements = PQS.ModiferRequirements.MeshColorChannel;
            vertexHeightNoise.modEnabled = true;
            vertexHeightNoise.order = 22;

            // Create the material direction
            mod = new GameObject("_Material_SunLight");
            mod.transform.parent = controllerRoot.gameObject.transform;
            PQSMod_MaterialSetDirection materialSetDirection = mod.AddComponent<PQSMod_MaterialSetDirection>();
            materialSetDirection.sphere = body.pqsVersion;
            materialSetDirection.valueName = "_sunLightDirection";
            materialSetDirection.requirements = PQS.ModiferRequirements.Default;
            materialSetDirection.modEnabled = true;
            materialSetDirection.order = 100;

            // Crete the quad mesh colliders
            mod = new GameObject("QuadMeshColliders");
            mod.transform.parent = controllerRoot.gameObject.transform;
            PQSMod_QuadMeshColliders quadMeshColliders = mod.AddComponent<PQSMod_QuadMeshColliders>();
            quadMeshColliders.sphere = body.pqsVersion;
            quadMeshColliders.maxLevelOffset = 0;
            quadMeshColliders.physicsMaterial = new PhysicMaterial();
            quadMeshColliders.physicsMaterial.name = "Ground";
            quadMeshColliders.physicsMaterial.dynamicFriction = 0.6f;
            quadMeshColliders.physicsMaterial.staticFriction = 0.8f;
            quadMeshColliders.physicsMaterial.bounciness = 0.0f;
            quadMeshColliders.physicsMaterial.frictionDirection2 = Vector3.zero;
            quadMeshColliders.physicsMaterial.dynamicFriction2 = 0.0f;
            quadMeshColliders.physicsMaterial.staticFriction2 = 0.0f;
            quadMeshColliders.physicsMaterial.frictionCombine = PhysicMaterialCombine.Maximum;
            quadMeshColliders.physicsMaterial.bounceCombine = PhysicMaterialCombine.Average;
            quadMeshColliders.requirements = PQS.ModiferRequirements.Default;
            quadMeshColliders.modEnabled = true;
            quadMeshColliders.order = 100;

            // Create the simplex height absolute
            mod = new GameObject("_FineDetail");
            mod.transform.parent = controllerRoot.gameObject.transform;
            PQSMod_VertexSimplexHeightAbsolute vertexSimplexHeightAbsolute = mod.AddComponent<PQSMod_VertexSimplexHeightAbsolute>();
            vertexSimplexHeightAbsolute.sphere = body.pqsVersion;
            vertexSimplexHeightAbsolute.seed = 4234;
            vertexSimplexHeightAbsolute.deformity = 400.0;
            vertexSimplexHeightAbsolute.octaves = 6.0;
            vertexSimplexHeightAbsolute.persistence = 0.5;
            vertexSimplexHeightAbsolute.frequency = 18.0;
            vertexSimplexHeightAbsolute.requirements = PQS.ModiferRequirements.Default;
            vertexSimplexHeightAbsolute.modEnabled = true;
            vertexSimplexHeightAbsolute.order = 30;

            // Surface color map
            mod = new GameObject("_LandClass");
            mod.transform.parent = body.pqsVersion.gameObject.transform;
            PQSMod_VertexColorMap colorMap = mod.AddComponent<PQSMod_VertexColorMap>();
            colorMap.sphere = body.pqsVersion;
            colorMap.order = 500;
            colorMap.modEnabled = true;

            // Decompress and load the color
            map = new Texture2D(4, 4, TextureFormat.RGB24, false);
            map.LoadImage(System.IO.File.ReadAllBytes(KSPUtil.ApplicationRootPath + PluginDirectory + "/Planets/" + name + "/Color.png"));
            colorMap.vertexColorMap = ScriptableObject.CreateInstance<MapSO>();
            colorMap.vertexColorMap.CreateMap(MapSO.MapDepth.RGB, map);
            UnityEngine.Object.DestroyImmediate(map);

            #endregion

            #region PSystemBody.scaledVersion generation

            // Create the scaled version of the planet for use in map view
            body.scaledVersion = new GameObject(name);
            body.scaledVersion.layer = Constants.GameLayers.ScaledSpace;
            body.scaledVersion.transform.parent = Utility.Deactivator;

            // DEPRECATED - USE PQSMeshWrapper
            // Make sure the scaled version cooresponds to the size of the body
            // Turns out that the localScale is directly related to the planet size.
            // Jool's local scale is {1,1,1}, Kerbin's is {0.1,0.1,0.1}.  Jool's
            // radius is 6000 km, Kerbin's is 600 km.  Notice the relation?
            float scale = (float) body.celestialBody.Radius / 6000000.0f;
            body.scaledVersion.transform.localScale = new Vector3(scale, scale, scale);

            // Generate a mesh to fit the PQS we generated (it would be cool to generate this FROM the PQS)
            Mesh mesh = new Mesh();
            Utility.CopyMesh(Jool.scaledVersion.GetComponent<MeshFilter>().sharedMesh, mesh);

            // Iterate though the UVs
            // Geosphere with a radius of 1000, cooresponds to an object 6000km in radius
            Vector3[] vertices = mesh.vertices;
            for(int i = 0; i < mesh.vertexCount; i++)
            {
                // Get the height offset from the height map
                Vector2 uv = mesh.uv[i];
                float displacement = vertexHeightMap.heightMap.GetPixelFloat(uv.x, uv.y);

                // Since this is a geosphere, normalizing the vertex gives the vector to translate on
                Vector3 v = vertices[i];
                v.Normalize();

                // Calculate the real height displacement (in meters), normalized vector "v" scale (1 unit = 6 km)
                displacement = (float) vertexHeightMap.heightMapOffset + (displacement * (float) vertexHeightMap.heightMapDeformity);
                Vector3 offset = v * ((displacement / 6000.0f) / scale);

                // Adjust the displacement
                vertices[i] += offset;
            }
            mesh.vertices = vertices;
            mesh.RecalculateNormals();

            // Create the mesh filter
            MeshFilter meshFilter = body.scaledVersion.AddComponent<MeshFilter> ();
            meshFilter.mesh = mesh;

            // Load and compress the color texture for the custom planet
            Texture2D colorTexture = new Texture2D(4, 4, TextureFormat.RGBA32, true);
            colorTexture.LoadImage(System.IO.File.ReadAllBytes(KSPUtil.ApplicationRootPath + PluginDirectory + "/Planets/" + name + "/Color.png"));
            colorTexture.Compress(true);
            colorTexture.Apply(true, true);

            // Load and compress the color texture for the custom planet
            Texture2D normalTexture = new Texture2D(4, 4, TextureFormat.RGB24, true);
            normalTexture.LoadImage(System.IO.File.ReadAllBytes(KSPUtil.ApplicationRootPath + PluginDirectory + "/Planets/" + name + "/Normals.png"));
            //normalTexture = GameDatabase.BitmapToUnityNormalMap(normalTexture);
            normalTexture.Compress(true);
            normalTexture.Apply(true, true);

            // Create the renderer and material for the scaled version
            MeshRenderer renderer = body.scaledVersion.AddComponent<MeshRenderer>();
            //ScaledPlanetSimple material = new ScaledPlanetSimple();   // for atmosphereless planets
            ScaledPlanetRimAerial material = new ScaledPlanetRimAerial();
            material.color       = Color.white;
            material.specColor   = Color.black;
            material.mainTexture = colorTexture;
            material.bumpMap     = normalTexture;
            renderer.material    = material;

            // Create the sphere collider
            SphereCollider collider = body.scaledVersion.AddComponent<SphereCollider> ();
            collider.center         = Vector3.zero;
            collider.radius         = 1000.0f;

            // Create the ScaledSpaceFader to fade the orbit out where we view it (maybe?)
            ScaledSpaceFader fader = body.scaledVersion.AddComponent<ScaledSpaceFader> ();
            fader.celestialBody    = body.celestialBody;
            fader.fadeStart        = 95000.0f;
            fader.fadeEnd          = 100000.0f;
            fader.floatName        = "_Opacity";

            #endregion

            #region Atmosphere
            //--------------------- PROPERTIES EXCLUSIVE TO BODIES WITH ATMOSPHERE

            // Load the atmosphere gradient (compress it, does not need to be high quality)
            Texture2D atmosphereGradient = new Texture2D(4, 4, TextureFormat.RGB24, true);
            atmosphereGradient.LoadImage(System.IO.File.ReadAllBytes(KSPUtil.ApplicationRootPath + PluginDirectory + "/Planets/" + name + "/AtmosphereGradient.png"));
            atmosphereGradient.Compress(true);
            atmosphereGradient.wrapMode = TextureWrapMode.Clamp;
            atmosphereGradient.mipMapBias = 0.0f;
            atmosphereGradient.Apply(true, true);

            // Set the additional settings in the scaledVersion body's shader
            material.rimPower = 2.06f;
            material.rimBlend = 0.3f;
            material.rimColorRamp = atmosphereGradient;

            // Atmosphere specific properties (for scaled version root) (copied from duna)
            MaterialSetDirection materialLightDirection = body.scaledVersion.AddComponent<MaterialSetDirection>();
            materialLightDirection.valueName            = "_localLightDirection";

            // Create the atmosphere shell itself
            GameObject scaledAtmosphere               = new GameObject("atmosphere");
            scaledAtmosphere.transform.parent         = body.scaledVersion.transform;
            scaledAtmosphere.layer                    = Constants.GameLayers.ScaledSpaceAtmosphere;
            meshFilter                                = scaledAtmosphere.AddComponent<MeshFilter>();
            meshFilter.sharedMesh                     = Jool.scaledVersion.GetComponent<MeshFilter>().sharedMesh;
            renderer                                  = scaledAtmosphere.AddComponent<MeshRenderer>();
            renderer.material                         = new Kopernicus.MaterialWrapper.AtmosphereFromGround();
            AtmosphereFromGround atmosphereRenderInfo = scaledAtmosphere.AddComponent<AtmosphereFromGround>();
            atmosphereRenderInfo.waveLength           = new Color(0.509f, 0.588f, 0.643f, 0.000f);

            // Technical info for atmosphere
            body.celestialBody.atmosphere = true;
            body.celestialBody.atmosphereContainsOxygen = true;
            body.celestialBody.staticPressureASL = 1.0; // can't find anything that references this, especially with the equation in mind - where is this used?
            body.celestialBody.altitudeMultiplier = 1.4285f; // ditto
            body.celestialBody.atmosphereScaleHeight = 4.0;   // pressure (in atm) = atmosphereMultipler * e ^ -(altitude / (atmosphereScaleHeight * 1000))
            body.celestialBody.atmosphereMultiplier = 0.8f;
            body.celestialBody.atmoshpereTemperatureMultiplier = 1.0f; // how does this coorespond?
            body.celestialBody.maxAtmosphereAltitude = 55000.0f;  // i guess this is so the math doesn't drag out?
            body.celestialBody.useLegacyAtmosphere = true;
            body.celestialBody.atmosphericAmbientColor = new Color(0.306f, 0.187f, 0.235f, 1.000f);
            #endregion

            #region Ocean
            // ---------------- FOR BODIES WITH OCEANS ----------
            /*body.celestialBody.ocean = true;

            // Setup the laythe ocean info in master pqs
            body.pqsVersion.mapOcean = true;
            body.pqsVersion.mapOceanColor = new Color(0.117f, 0.126f, 0.157f, 1.000f);
            body.pqsVersion.mapOceanHeight = 0.0f;

            // Generate the PQS object
            GameObject oceanRoot       = new GameObject(name + "Ocean");
            oceanRoot.transform.parent = body.pqsVersion.transform;
            oceanRoot.layer            = Constants.GameLayers.LocalSpace;
            PQS oceanPQS               = oceanRoot.AddComponent<PQS>();

            // Add this new PQS to the secondary renderers of the altitude fade controller
            celestialBodyTransform.planetFade.secondaryRenderers.Add(oceanRoot);

            // Setup the PQS object data
            Utility.CopyObjectFields<PQS>(laytheOcean.GetComponent<PQS>(), oceanPQS);
            oceanPQS.radius            = body.pqsVersion.radius;
            oceanPQS.surfaceMaterial   = new PQSOceanSurfaceQuad(laytheOcean.GetComponent<PQS>().surfaceMaterial);
            oceanPQS.fallbackMaterial  = new PQSOceanSurfaceQuadFallback(laytheOcean.GetComponent<PQS>().fallbackMaterial);
            Utility.DumpObjectProperties(oceanPQS.surfaceMaterial, oceanPQS.surfaceMaterial.ToString());
            Utility.DumpObjectProperties(oceanPQS.fallbackMaterial, oceanPQS.fallbackMaterial.ToString());

            // Create the aerial perspective material
            mod = new GameObject("_Material_AerialPerspective");
            mod.transform.parent = oceanRoot.transform;
            aerialPerspectiveMaterial = mod.AddComponent<PQSMod_AerialPerspectiveMaterial>();
            aerialPerspectiveMaterial.sphere = body.pqsVersion;
            aerialPerspectiveMaterial.globalDensity = -0.00001f;
            aerialPerspectiveMaterial.heightFalloff = 6.75f;
            aerialPerspectiveMaterial.atmosphereDepth = 150000;
            aerialPerspectiveMaterial.DEBUG_SetEveryFrame = true;
            aerialPerspectiveMaterial.cameraAlt = 0;
            aerialPerspectiveMaterial.cameraAtmosAlt = 0;
            aerialPerspectiveMaterial.heightDensAtViewer = 0;
            aerialPerspectiveMaterial.requirements = PQS.ModiferRequirements.Default;
            aerialPerspectiveMaterial.modEnabled = true;
            aerialPerspectiveMaterial.order = 100;

            // Create the UV planet relative position
            mod = new GameObject("_Material_SurfaceQuads");
            mod.transform.parent = oceanRoot.transform;
            planetRelativePosition = mod.AddComponent<PQSMod_UVPlanetRelativePosition>();
            planetRelativePosition.sphere = body.pqsVersion;
            planetRelativePosition.requirements = PQS.ModiferRequirements.Default;
            planetRelativePosition.modEnabled = true;
            planetRelativePosition.order = 100;

            // Create the quad map remover (da f**k?)
            mod = new GameObject("QuadRemoveMap");
            mod.transform.parent = oceanRoot.transform;
            PQSMod_RemoveQuadMap removeQuadMap = mod.AddComponent<PQSMod_RemoveQuadMap>();
            removeQuadMap.mapDeformity = 0.0f;
            removeQuadMap.minHeight = 0.0f;
            removeQuadMap.maxHeight = 0.5f;
            removeQuadMap.requirements = PQS.ModiferRequirements.Default;
            removeQuadMap.modEnabled = true;
            removeQuadMap.order = 1000;

            // Load the heightmap into whatever the hell this is
            map = new Texture2D(4, 4, TextureFormat.Alpha8, false);
            map.LoadImage(System.IO.File.ReadAllBytes(KSPUtil.ApplicationRootPath + PluginDirectory + "/Planets/" + name + "/Height.png"));
            removeQuadMap.map = ScriptableObject.CreateInstance<MapSO>();
            removeQuadMap.map.CreateMap(MapSO.MapDepth.Greyscale, map);
            UnityEngine.Object.DestroyImmediate(map);

            // Setup the ocean effects
            mod = new GameObject("OceanFX");
            mod.transform.parent = oceanRoot.transform;
            PQSMod_OceanFX oceanFX = mod.AddComponent<PQSMod_OceanFX>();
            oceanFX.watermain = Utility.RecursivelyGetComponent<PQSMod_OceanFX>(laytheOcean).watermain.Clone() as Texture2D[];
            oceanFX.requirements = PQS.ModiferRequirements.Default;
            oceanFX.modEnabled = true;
            oceanFX.order = 100;*/

            #endregion

            // Return the new body
            return body;
        }
        public static PSystemBody GenerateSystemBody(PSystem system, PSystemBody parent, string templateName, string name, Orbit orbit)
        {
            // Look up the template body
            PSystemBody template = Utility.FindBody (system.rootBody, templateName);

            // Create a new celestial body as a clone of this template
            PSystemBody clone = system.AddBody (parent);
            clone.name = name;

            // Set up the celestial body of the clone (back up the orbit driver)
            Utility.CopyObjectFields<CelestialBody> (template.celestialBody, clone.celestialBody);
            clone.celestialBody.bodyName = name;
            clone.celestialBody.orbitingBodies = null;
            clone.celestialBody.orbitDriver = clone.orbitDriver;
            clone.flightGlobalsIndex = 100 + template.flightGlobalsIndex;

            // Setup the orbit driver
            clone.orbitRenderer.orbitColor = template.orbitRenderer.orbitColor;
            clone.orbitDriver.orbit = orbit;
            clone.orbitDriver.celestialBody = clone.celestialBody;
            clone.orbitDriver.updateMode = OrbitDriver.UpdateMode.UPDATE;

            // Setup the deactivator object
            GameObject deactivator = new GameObject ("Deactivator");
            deactivator.SetActive (false);
            UnityEngine.Object.DontDestroyOnLoad (deactivator);

            // Clone the template's PQS
            clone.pqsVersion = UnityEngine.Object.Instantiate (template.pqsVersion) as PQS;
            clone.pqsVersion.transform.parent = deactivator.transform;
            clone.pqsVersion.name = name;

            // Clone the scaled space
            clone.scaledVersion = UnityEngine.Object.Instantiate (template.scaledVersion) as GameObject;
            clone.scaledVersion.transform.parent = deactivator.transform;
            clone.scaledVersion.name = name;

            return clone;
        }
 public extern PSystemBody AddBody(PSystemBody parent);