internal void Apply(String body, AtmosphereVolume atmosphere, float altitude)
        {
            this.body       = body;
            this.atmosphere = atmosphere;
            this.altitude   = altitude;

            celestialBody            = Tools.GetCelestialBody(body);
            scaledCelestialTransform = Tools.GetScaledTransform(body);
            PQS pqs = null;

            if (celestialBody != null && celestialBody.pqsController != null)
            {
                pqs = celestialBody.pqsController;
            }
            else
            {
                AtmosphereManager.Log("No PQS! Instanciating one.");
                pqs = PQSManagerClass.GetPQS(body);
            }
            AtmosphereManager.Log("PQS Applied");
            if (pqs != null)
            {
                this.sphere           = pqs;
                this.transform.parent = pqs.transform;
                this.requirements     = PQS.ModiferRequirements.Default;
                this.modEnabled       = true;
                this.order           += 10;

                this.transform.localPosition = Vector3.zero;
                this.transform.localRotation = Quaternion.identity;
                this.transform.localScale    = Vector3.one;
                this.radius = (float)(altitude + celestialBody.Radius);


                if (atmosphere != null)
                {
                    this.atmosphere.Apply(celestialBody, scaledCelestialTransform, radius);
                }

                if (!pqs.isActive || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
                {
                    this.OnSphereInactive();
                }
                else
                {
                    this.OnSphereActive();
                }
                this.OnSetup();
                pqs.EnableSphere();
            }
            else
            {
                AtmosphereManager.Log("PQS is null somehow!?");
            }
            onExitMapView          = new Callback(OnExitMapView);
            MapView.OnExitMapView += onExitMapView;
            GameEvents.onGameSceneLoadRequested.Add(GameSceneLoaded);
        }
예제 #2
0
        internal void Apply(String body, CloudsMaterial cloudsMaterial, Clouds2D layer2D, CloudsVolume layerVolume, float altitude, Vector3d speed, Vector3d detailSpeed, Vector3 offset, Matrix4x4 rotationAxis, bool killBodyRotation)
        {
            this.body             = body;
            this.cloudsMaterial   = cloudsMaterial;
            this.layer2D          = layer2D;
            this.layerVolume      = layerVolume;
            this.altitude         = altitude;
            this.offset           = -offset;
            this.rotationAxis     = rotationAxis;
            this.killBodyRotation = killBodyRotation;

            celestialBody            = Tools.GetCelestialBody(body);
            scaledCelestialTransform = Tools.GetScaledTransform(body);
            PQS pqs = null;

            if (celestialBody != null && celestialBody.pqsController != null)
            {
                pqs = celestialBody.pqsController;
            }
            else
            {
                CloudsManager.Log("No PQS! Instanciating one.");
                pqs = PQSManagerClass.GetPQS(body);
            }
            CloudsManager.Log("PQS Applied");
            if (pqs != null)
            {
                this.sphere           = pqs;
                this.transform.parent = pqs.transform;
                this.requirements     = PQS.ModiferRequirements.Default;
                this.modEnabled       = true;
                this.order           += 10;

                this.transform.localPosition = Vector3.zero;
                this.transform.localRotation = Quaternion.identity;
                this.transform.localScale    = Vector3.one;
                this.radius = (altitude + celestialBody.Radius);


                double circumference = 2f * Mathf.PI * radius;
                mainPeriod   = -(speed) / circumference;
                detailPeriod = -(detailSpeed) / circumference;

                if (layer2D != null)
                {
                    this.layer2D.Apply(celestialBody, scaledCelestialTransform, cloudsMaterial, this.name, (float)radius);
                }

                if (!pqs.isActive || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
                {
                    this.OnSphereInactive();
                }
                else
                {
                    this.OnSphereActive();
                }
                this.OnSetup();
                pqs.EnableSphere();
            }
            else
            {
                CloudsManager.Log("PQS is null somehow!?");
            }

            GameEvents.OnMapExited.Add(ExitMapView);
            GameEvents.onGameSceneLoadRequested.Add(SceneLoaded);

            if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                ApplyToMainMenu();
            }
        }
예제 #3
0
        internal void Apply(string body, TerrainMaterial terrainMaterial, OceanMaterial oceanMaterial)
        {
            celestialBody = Tools.GetCelestialBody(body);
            PQS pqs = null;

            if (celestialBody != null && celestialBody.pqsController != null)
            {
                pqs = celestialBody.pqsController;
                pqsSurfaceMaterial = GetPQSSurfaceMaterial(pqs);
            }
            else
            {
                pqs = PQSManagerClass.GetPQS(body);
            }

            Transform transform = Tools.GetScaledTransform(body);

            if (pqs != null)
            {
                this.sphere           = pqs;
                this.transform.parent = pqs.transform;
                this.requirements     = PQS.ModiferRequirements.Default;
                this.modEnabled       = true;
                this.order           += 10;

                this.transform.localPosition = Vector3.zero;
                this.transform.localRotation = Quaternion.identity;
                this.transform.localScale    = Vector3.one;

                //Scaled space
                Renderer r = (Renderer)transform.GetComponent(typeof(Renderer));
                if (r != null)
                {
                    terrainMaterial.SaveTextures(r.material);
                    originalPlanetShader = r.material.shader;

                    TerrainManager.Log("planet shader: " + r.material.shader);
                    r.sharedMaterial.shader = TerrainManager.PlanetShader;
                    terrainMaterial.ApplyMaterialProperties(r.sharedMaterial);
                    // terrainMaterial doesn't work anyway [1/3]
                    if (pqs.ChildSpheres.Length != 0)
                    {
                        r.sharedMaterial.EnableKeyword("OCEAN_ON");
                    }
                    else
                    {
                        r.sharedMaterial.DisableKeyword("OCEAN_ON");
                    }
                }

                // terrainMaterial doesn't work anyway [2/3]
                //terrainMaterial = null;
                //originalTerrainShader = null;

                terrainMaterial.SaveTextures(pqsSurfaceMaterial);
                originalTerrainShader = pqsSurfaceMaterial.shader;
                TerrainManager.Log("Terrain Shader Name: " + originalTerrainShader.name);
                String[] keywords = pqsSurfaceMaterial.shaderKeywords;
                pqsSurfaceMaterial.shader = TerrainManager.TerrainShader;
                //    foreach (String keyword in keywords)
                //    {
                //        pqs.surfaceMaterial.EnableKeyword(keyword);
                //    }
                terrainMaterial.ApplyMaterialProperties(pqsSurfaceMaterial);

                if (oceanMaterial != null && pqs.ChildSpheres.Length > 0)
                {
                    PQS ocean = pqs.ChildSpheres[0];
                    OceanSurfaceMaterial = GetPQSSurfaceMaterial(ocean);

                    pqsSurfaceMaterial.EnableKeyword("OCEAN_ON");
                    r.sharedMaterial.EnableKeyword("OCEAN_ON");

                    keywords            = OceanSurfaceMaterial.shaderKeywords;
                    originalOceanShader = OceanSurfaceMaterial.shader;
                    TerrainManager.Log("Ocean Shader Name: " + originalOceanShader.name);
                    OceanSurfaceMaterial.shader = TerrainManager.OceanShader;
                    //    foreach (String keyword in keywords)
                    //    {
                    //        OceanSurfaceMaterial.EnableKeyword(keyword);
                    //    }

                    terrainMaterial.ApplyMaterialProperties(OceanSurfaceMaterial);
                    oceanMaterial.ApplyMaterialProperties(OceanSurfaceMaterial);

                    PQSLandControl landControl = (PQSLandControl)pqs.transform.GetComponentInChildren(typeof(PQSLandControl));
                    if (landControl != null)
                    {
                        PQSLandControl.LandClass[] landClasses = landControl.landClasses;
                        if (landClasses != null)
                        {
                            PQSLandControl.LandClass lcBeach = landClasses.FirstOrDefault(lc => lc.landClassName == "BaseBeach");
                            PQSLandControl.LandClass lcOcean = landClasses.FirstOrDefault(lc => lc.landClassName == "Ocean Bottom");
                            if (lcBeach != null || lcOcean != null)
                            {
                                lcOcean.color = lcBeach.color;
                            }
                        }


                        //    PQS ocean =
                        //    sphere.ChildSpheres[0];
                        //    GameObject go = new GameObject();
                        //    FakeOceanPQS fakeOcean = go.AddComponent<FakeOceanPQS>();
                        //    fakeOcean.Apply(ocean);
                    }

                    SimpleCube hp = new SimpleCube(2000, ref OceanBackingMaterial, TerrainManager.OceanBackingShader);
                    OceanBacking = hp.GameObject;

                    OceanBacking.transform.parent        = FlightCamera.fetch.transform;
                    OceanBacking.transform.localPosition = Vector3.zero;
                    OceanBacking.transform.localScale    = Vector3.one;
                    OceanBacking.layer = (int)Tools.Layer.Local;
                    OceanBackingMaterial.SetFloat("_OceanRadius", (float)celestialBody.Radius);
                    terrainMaterial.ApplyMaterialProperties(OceanBackingMaterial);
                }
                else
                {
                    pqsSurfaceMaterial.DisableKeyword("OCEAN_ON");
                    //r.sharedMaterial.DisableKeyword("OCEAN_ON"); // terrainMaterial doesn't work anyway [3/3]
                }


                PQSMod_CelestialBodyTransform cbt = (PQSMod_CelestialBodyTransform)pqs.transform.GetComponentInChildren(typeof(PQSMod_CelestialBodyTransform));
                if (cbt != null)
                {
                    pqsSurfaceMaterial.SetFloat("_MainTexHandoverDist", (float)(1f / cbt.deactivateAltitude));
                    if (oceanMaterial != null && pqs.ChildSpheres.Length > 0)
                    {
                        PQS ocean = pqs.ChildSpheres[0];
                        OceanSurfaceMaterial.SetFloat("_MainTexHandoverDist", (float)(1f / cbt.deactivateAltitude));
                    }
                    pqsSurfaceMaterial.SetFloat("_OceanRadius", (float)celestialBody.Radius);
                }
            }


            this.OnSetup();
            pqs.EnableSphere();
        }