public void Update() { if (!isCompatible) { return; } if (counter < 5) { counter += TimeWarp.fixedDeltaTime; return; } if (cams == null) { cams = new List <CameraWrapper>(); Camera[] cameras = Camera.allCameras; foreach (Camera cam in cameras) { try { CameraWrapper thisCam = new CameraWrapper(); thisCam.camName = cam.name.ToString(); thisCam.depth = cam.depth.ToString(); thisCam.farClipPlane += cam.farClipPlane.ToString(); thisCam.nearClipPlane += cam.nearClipPlane.ToString(); // layer cull appears unused by relevant cameras. /*for (int i = 0; i < cam.layerCullDistances.Length; i++) * thisCam.layerCullDistances.Add("" + cam.layerCullDistances[i]);*/ cams.Add(thisCam); } catch (Exception e) { Debug.Log("*RSSGUI* Exception getting camera " + cam.name + "\n" + e); } } } if (Input.GetKeyDown(KeyCode.G) && Input.GetKey(KeyCode.LeftAlt)) { GUIOpen = !GUIOpen; if (GUIOpen) { afg = findAFG(); if (afg != null) { rt = afg.waveLength.r.ToString(); gt = afg.waveLength.g.ToString(); bt = afg.waveLength.b.ToString(); at = afg.waveLength.a.ToString(); ESunt = afg.ESun.ToString(); Krt = afg.Kr.ToString(); Kmt = afg.Km.ToString(); innert = (afg.innerRadius * ScaledSpace.ScaleFactor).ToString(); outert = (afg.outerRadius * ScaledSpace.ScaleFactor).ToString(); } } } }
public static void UpdateAFG(CelestialBody body, AtmosphereFromGround afg, ConfigNode modNode = null) { // the defaults -- don't support the full RSS panoply afg.outerRadius = (float)body.Radius * 1.025f * ScaledSpace.InverseScaleFactor; afg.innerRadius = afg.outerRadius * 0.975f; // the stuff Start and UpdateAtmosphere(true) does afg.KrESun = afg.Kr * afg.ESun; afg.KmESun = afg.Km * afg.ESun; afg.Kr4PI = afg.Kr * 4f * (float)Math.PI; afg.Km4PI = afg.Km * 4f * (float)Math.PI; afg.g2 = afg.g * afg.g; afg.outerRadius2 = afg.outerRadius * afg.outerRadius; afg.innerRadius2 = afg.innerRadius * afg.innerRadius; afg.scale = 1f / (afg.outerRadius - afg.innerRadius); afg.scaleDepth = -0.25f; afg.scaleOverScaleDepth = afg.scale / afg.scaleDepth; try { afgSetMaterial.Invoke(afg, new object[] { true }); } catch (Exception e) { print("**ERROR setting AtmosphereFromGround " + afg.name + " for body " + body.name + ": " + e); } }
public static void RecursiveFixAtmo(CelestialBody Planet, string SunName) { if (Planet.name != SunName) { //Scaledspace //Utils.FindScaled( input.celestialBody.name ).layer = 1024; //Stuff MaterialSetDirection msd = Utils.FindScaled(Planet.name).GetComponentInChildren <MaterialSetDirection>(); if (msd != null) { msd.target = GameObject.Find(SunName + "Sun").transform; } var atmo = Utils.FindScaled(Planet.name).transform.FindChild("Atmosphere"); if (atmo != null) { AtmosphereFromGround afg = atmo.GetComponent <AtmosphereFromGround>(); afg.sunLight = GameObject.Find(SunName + "Sun"); } var atmoL = Utils.FindLocal(Planet.name).transform.FindChild("Atmosphere"); if (atmoL != null) { AtmosphereFromGround afgL = atmo.GetComponent <AtmosphereFromGround>(); afgL.sunLight = GameObject.Find(SunName + "Sun"); } } foreach (CelestialBody child in Planet.orbitingBodies) { RecursiveFixAtmo(child, SunName); } }
public static void UpdateAFG(CelestialBody body, AtmosphereFromGround afg, ConfigNode modNode = null) { // the defaults -- don't support the full RSS panoply afg.outerRadius = (float)body.Radius * 1.025f * ScaledSpace.InverseScaleFactor; afg.innerRadius = afg.outerRadius * 0.975f; // the stuff Start and UpdateAtmosphere(true) does afg.KrESun = afg.Kr * afg.ESun; afg.KmESun = afg.Km * afg.ESun; afg.Kr4PI = afg.Kr * 4f * (float)Math.PI; afg.Km4PI = afg.Km * 4f * (float)Math.PI; afg.g2 = afg.g * afg.g; afg.outerRadius2 = afg.outerRadius * afg.outerRadius; afg.innerRadius2 = afg.innerRadius * afg.innerRadius; afg.scale = 1f / (afg.outerRadius - afg.innerRadius); afg.scaleDepth = -0.25f; afg.scaleOverScaleDepth = afg.scale / afg.scaleDepth; try { afgSetMaterial.Invoke(afg, new object[] { true }); } catch (Exception e) { print("**ERROR setting AtmosphereFromGround " + afg.name + " for body " + body.name + ": " + e); } }
public void Start() { if (afg == null) afg = findAFG(); //print("[AFGEditor] Start()"); windowStyle = new GUIStyle(HighLogic.Skin.window); windowStyle.stretchHeight = true; }
public static void StoreAfg(AtmosphereFromGround afg) { if (afg.planet == null) { Debug.Log("[Kopernicus] Trying to store AFG, but planet null!"); return; } Atmospheres[afg.planet.transform.name] = new AtmosphereInfo(afg); }
public void Start() { if (afg == null) { afg = findAFG(); } //print("[AFGEditor] Start()"); windowStyle = new GUIStyle(HighLogic.Skin.window); windowStyle.stretchHeight = true; }
public static bool StoreAFG(AtmosphereFromGround afg) { if (afg.planet == null) { Debug.Log("[Kopernicus] Trying to store AFG, but planet null!"); return(false); } atmospheres[afg.planet.bodyName] = new AFGInfo(afg); return(true); }
public static bool StoreAFG(AtmosphereFromGround afg) { if (afg.planet == null) { Debug.Log("[Kopernicus]: Trying to store AFG, but planet null!"); return false; } atmospheres[afg.planet.bodyName] = new AFGInfo(afg); return true; }
void CheckAtmosphere() { targetAtmoColour = new Color32( (byte)AtmoRedColour, (byte)AtmoGreenColour, (byte)AtmoBlueColour, 255); AtmosphereFromGround atmo = Utils.FindScaled( vessel.mainBody.name ).GetComponentInChildren<AtmosphereFromGround>(); if( atmo == null ) { PlanetUtils.AddAtmoFX( vessel.mainBody.name, 1, new Color( 1, 1, 1, 0 ), 0 ); atmo = Utils.FindScaled( vessel.mainBody.name ).GetComponentInChildren<AtmosphereFromGround>(); } targetAtmo = atmo; }
void CheckAtmosphere() { targetAtmoColour = new Color32((byte)AtmoRedColour, (byte)AtmoGreenColour, (byte)AtmoBlueColour, 255); AtmosphereFromGround atmo = Utils.FindScaled(vessel.mainBody.name).GetComponentInChildren <AtmosphereFromGround>(); if (atmo == null) { PlanetUtils.AddAtmoFX(vessel.mainBody.name, 1, new Color(1, 1, 1, 0), 0); atmo = Utils.FindScaled(vessel.mainBody.name).GetComponentInChildren <AtmosphereFromGround>(); } targetAtmo = atmo; }
public void Start() { if (!CompatibilityChecker.IsCompatible()) { isCompatible = false; return; } if (afg == null) afg = findAFG(); //print("[AFGEditor] Start()"); windowStyle = new GUIStyle(HighLogic.Skin.window); windowStyle.stretchHeight = true; }
// Post apply event void IParserEventSubscriber.PostApply(ConfigNode node) { // Should we remove the atmosphere if (body.celestialBody.atmosphere && removeAtmosphere.value) { // Find atmosphere from ground and destroy the game object AtmosphereFromGround atmosphere = body.scaledVersion.GetComponentsInChildren <AtmosphereFromGround>(true)[0]; atmosphere.transform.parent = null; UnityEngine.Object.Destroy(atmosphere.gameObject); // Destroy the light controller MaterialSetDirection light = body.scaledVersion.GetComponentsInChildren <MaterialSetDirection>(true)[0]; UnityEngine.Object.Destroy(light); // No more atmosphere :( body.celestialBody.atmosphere = false; } // Should we remove the ocean? if (body.celestialBody.ocean && removeOcean.value) { // Find atmosphere the ocean PQS PQS ocean = body.pqsVersion.GetComponentsInChildren <PQS>(true).Where(pqs => pqs != body.pqsVersion).First(); PQSMod_CelestialBodyTransform cbt = body.pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).First(); // Destroy the ocean PQS (this could be bad - destroying the secondary fades...) cbt.planetFade.secondaryRenderers.Remove(ocean.gameObject); cbt.secondaryFades = null; ocean.transform.parent = null; UnityEngine.Object.Destroy(ocean); // No more ocean :( body.celestialBody.ocean = false; } // Figure out what kind of body we are if (body.scaledVersion.GetComponentsInChildren(typeof(ScaledSun), true).Length > 0) { type = BodyType.Star; } else if (body.celestialBody.atmosphere) { type = BodyType.Atmospheric; } else { type = BodyType.Vacuum; } Debug.Log("[Kopernicus]: Configuration.Template: Using Template \"" + body.celestialBody.bodyName + "\""); }
public AtmosphereFromGround findAFG() { CelestialBody mainBody = FlightGlobals.getMainBody(); //AtmosphereFromGround afg = null; foreach (AtmosphereFromGround afgt in Resources.FindObjectsOfTypeAll(typeof(AtmosphereFromGround))) { if (afgt.planet == mainBody) { afg = afgt; //print("[AFG Editor] Found Atmosphere"); } } return afg; }
public void Start() { if (!CompatibilityChecker.IsCompatible()) { isCompatible = false; return; } if (afg == null) { afg = findAFG(); } //print("[AFGEditor] Start()"); windowStyle = new GUIStyle(HighLogic.Skin.window); windowStyle.stretchHeight = true; }
public AtmosphereFromGround findAFG() { CelestialBody mainBody = FlightGlobals.getMainBody(); //AtmosphereFromGround afg = null; foreach (AtmosphereFromGround afgt in Resources.FindObjectsOfTypeAll(typeof(AtmosphereFromGround))) { if (afgt.planet == mainBody) { afg = afgt; //print("[AFG Editor] Found Atmosphere"); } } return(afg); }
public static void UpdateAFG(CelestialBody body, AtmosphereFromGround afg) { afg.outerRadius = (float)body.Radius * 1.025f; afg.innerRadius = afg.outerRadius * 0.975f; afg.KrESun = afg.Kr * afg.ESun; afg.KmESun = afg.Km * afg.ESun; afg.Kr4PI = afg.Kr * 4f * (float)Math.PI; afg.Km4PI = afg.Km * 4f * (float)Math.PI; afg.g2 = afg.g * afg.g; afg.outerRadius2 = afg.outerRadius * afg.outerRadius; afg.innerRadius2 = afg.innerRadius * afg.innerRadius; afg.scale = 1f / (afg.outerRadius - afg.innerRadius); afg.scaleDepth = -0.25f; afg.scaleOverScaleDepth = afg.scale / afg.scaleDepth; }
public AFGInfo(AtmosphereFromGround afg) { DEBUG_alwaysUpdateAll = afg.DEBUG_alwaysUpdateAll; doScale = afg.doScale; ESun = afg.ESun; Kr = afg.Kr; Km = afg.Km; transformScale = afg.transform.localScale; scaleDepth = afg.scaleDepth; samples = afg.samples; g = afg.g; waveLength = afg.waveLength; invWaveLength = afg.invWaveLength; outerRadius = afg.outerRadius; innerRadius = afg.innerRadius; }
public static Boolean PatchAfg(AtmosphereFromGround afg) { if (!Atmospheres.TryGetValue(afg.planet.transform.name, out AtmosphereInfo info)) { return(false); } try { info.Apply(afg); } catch { return(false); } return(true); }
private AFGInfo(AtmosphereFromGround afg) { DEBUG_alwaysUpdateAll = afg.DEBUG_alwaysUpdateAll; doScale = afg.doScale; ESun = afg.ESun; Kr = afg.Kr; Km = afg.Km; transformScale = afg.transform.localScale; scaleDepth = afg.scaleDepth; samples = afg.samples; g = afg.g; waveLength = afg.waveLength; invWaveLength = afg.invWaveLength; outerRadius = afg.outerRadius; Debug.Log(outerRadius); innerRadius = afg.innerRadius; Debug.Log(innerRadius); }
private AtmosphereInfo(AtmosphereFromGround afg) { _debugAlwaysUpdateAll = afg.DEBUG_alwaysUpdateAll; _doScale = afg.doScale; _eSun = afg.ESun; _kr = afg.Kr; _km = afg.Km; _transformScale = afg.transform.localScale; _scaleDepth = afg.scaleDepth; _samples = afg.samples; _g = afg.g; _waveLength = afg.waveLength; _invWaveLength = afg.invWaveLength; _outerRadius = afg.outerRadius; _innerRadius = afg.innerRadius; }
public static bool PatchAFG(AtmosphereFromGround afg) { AFGInfo info = null; if (atmospheres.TryGetValue(afg.planet.bodyName, out info)) { try { info.Apply(afg); } catch { return false; } return true; } return false; }
// Calculates the default members for the AFG public static void CalculatedMembers(AtmosphereFromGround atmo) { atmo.g2 = atmo.g * atmo.g; atmo.KrESun = atmo.Kr * atmo.ESun; atmo.KmESun = atmo.Km * atmo.ESun; atmo.Kr4PI = atmo.Kr * 4f * Mathf.PI; atmo.Km4PI = atmo.Km * 4f * Mathf.PI; atmo.outerRadius2 = atmo.outerRadius * atmo.outerRadius; atmo.innerRadius2 = atmo.innerRadius * atmo.innerRadius; atmo.scale = 1f / (atmo.outerRadius - atmo.innerRadius); atmo.scaleOverScaleDepth = atmo.scale / atmo.scaleDepth; if (atmo.doScale) { atmo.transform.localScale = Vector3.one * 1.025f; } }
public static bool PatchAFG(AtmosphereFromGround afg) { AFGInfo info = null; if (atmospheres.TryGetValue(afg.planet.bodyName, out info)) { try { info.Apply(afg); } catch { return(false); } return(true); } return(false); }
public void Apply(AtmosphereFromGround afg) { afg.DEBUG_alwaysUpdateAll = DEBUG_alwaysUpdateAll; afg.doScale = doScale; afg.ESun = ESun; afg.Kr = Kr; afg.Km = Km; afg.transform.localScale = transformScale; afg.scaleDepth = scaleDepth; afg.samples = samples; afg.g = g; afg.waveLength = waveLength; afg.invWaveLength = invWaveLength; afg.outerRadius = outerRadius; afg.innerRadius = innerRadius; afg.transform.localPosition = Vector3.zero; Configuration.AtmosphereFromGroundLoader.CalculatedMembers(afg); afg.SetMaterial(true); }
public void UpdateAFG(AtmosphereFromGround ag) { Log("Updating atmosphere visuals"); var body = Target; ag.outerRadius = ((float)body.Radius * 1.025f) * ScaledSpace.InverseScaleFactor; ag.innerRadius = ag.outerRadius * 0.975f; ag.outerRadius2 = ag.outerRadius * ag.outerRadius; ag.innerRadius2 = ag.innerRadius * ag.innerRadius; ag.scale = 1f / (ag.outerRadius - ag.innerRadius); ag.scaleDepth = -0.25f; ag.scaleOverScaleDepth = ag.scale / ag.scaleDepth; ag.invWaveLength = new Color(1f / Mathf.Pow(ag.waveLength[0], 4), 1f / Mathf.Pow(ag.waveLength[1], 4), 1f / Mathf.Pow(ag.waveLength[2], 4), 0.5f); ag.transform.localScale = Vector3.one * ((float)(body.Radius + body.maxAtmosphereAltitude) / (float)body.Radius); ag.doScale = false; //stupid private methods MethodInfo start = ag.GetType().GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance); start.Invoke(ag, new object[] {}); Log("Atmosphere visual update complete!"); }
// Default Constructor public AtmosphereFromGroundLoader() { body = generatedBody.celestialBody; afg = generatedBody.scaledVersion.GetComponentsInChildren <AtmosphereFromGround>(true)[0]; // Set Defaults afg.planet = body; afg.ESun = 30f; afg.Kr = 0.00125f; afg.Km = 0.00015f; afg.samples = 4f; afg.g = -0.85f; if (afg.waveLength == new Color(0f, 0f, 0f, 0f)) { afg.waveLength = new Color(0.65f, 0.57f, 0.475f, 0.5f); } afg.outerRadius = (((float)body.Radius) * 1.025f) * INVSCALEFACTOR; afg.innerRadius = afg.outerRadius * 0.975f; afg.scaleDepth = -0.25f; afg.invWaveLength = new Color((float)(1d / Math.Pow(afg.waveLength[0], 4)), (float)(1d / Math.Pow(afg.waveLength[1], 4)), (float)(1d / Math.Pow(afg.waveLength[2], 4)), 0.5f); CalculatedMembers(afg); }
// Runtime constructor public AtmosphereFromGroundLoader(CelestialBody body) { this.body = body; afg = body.afg; // Set Defaults afg.planet = body; afg.ESun = 30f; afg.Kr = 0.00125f; afg.Km = 0.00015f; afg.samples = 4f; afg.g = -0.85f; if (afg.waveLength == new Color(0f, 0f, 0f, 0f)) { afg.waveLength = new Color(0.65f, 0.57f, 0.475f, 0.5f); } afg.outerRadius = (((float)body.Radius) * 1.025f) * INVSCALEFACTOR; afg.innerRadius = afg.outerRadius * 0.975f; afg.scaleDepth = -0.25f; afg.invWaveLength = new Color((float)(1d / Math.Pow(afg.waveLength[0], 4)), (float)(1d / Math.Pow(afg.waveLength[1], 4)), (float)(1d / Math.Pow(afg.waveLength[2], 4)), 0.5f); CalculatedMembers(afg); }
private void Apply(AtmosphereFromGround afg) { Transform transform = afg.transform; afg.DEBUG_alwaysUpdateAll = _debugAlwaysUpdateAll; afg.doScale = _doScale; afg.ESun = _eSun; afg.Kr = _kr; afg.Km = _km; transform.localScale = _transformScale; afg.scaleDepth = _scaleDepth; afg.samples = _samples; afg.g = _g; afg.waveLength = _waveLength; afg.invWaveLength = _invWaveLength; afg.outerRadius = _outerRadius; afg.innerRadius = _innerRadius; transform.localPosition = Vector3.zero; AtmosphereFromGroundLoader.CalculatedMembers(afg); afg.SetMaterial(true); Events.OnRuntimeUtilityPatchAFG.Fire(afg); }
// Default Constructor public AtmosphereFromGroundLoader() { body = generatedBody.celestialBody; afg = generatedBody.scaledVersion.GetComponentsInChildren<AtmosphereFromGround>(true)[0]; // Set Defaults afg.planet = body; afg.ESun = 30f; afg.Kr = 0.00125f; afg.Km = 0.00015f; afg.samples = 4f; afg.g = -0.85f; if (afg.waveLength == new Color(0f, 0f, 0f, 0f)) { afg.waveLength = new Color(0.65f, 0.57f, 0.475f, 0.5f); } afg.outerRadius = (((float)body.Radius) * 1.025f) * INVSCALEFACTOR; afg.innerRadius = afg.outerRadius * 0.975f; afg.scaleDepth = -0.25f; afg.invWaveLength = new Color((float)(1d / Math.Pow(afg.waveLength[0], 4)), (float)(1d / Math.Pow(afg.waveLength[1], 4)), (float)(1d / Math.Pow(afg.waveLength[2], 4)), 0.5f); CalculatedMembers(afg); }
// Calculates the default members for the AFG public static void CalculatedMembers(AtmosphereFromGround atmo) { atmo.g2 = atmo.g * atmo.g; atmo.KrESun = atmo.Kr * atmo.ESun; atmo.KmESun = atmo.Km * atmo.ESun; atmo.Kr4PI = atmo.Kr * 4f * Mathf.PI; atmo.Km4PI = atmo.Km * 4f * Mathf.PI; atmo.outerRadius2 = atmo.outerRadius * atmo.outerRadius; atmo.innerRadius2 = atmo.innerRadius * atmo.innerRadius; atmo.scale = 1f / (atmo.outerRadius - atmo.innerRadius); atmo.scaleOverScaleDepth = atmo.scale / atmo.scaleDepth; if (atmo.doScale) atmo.transform.localScale = Vector3.one * 1.025f; }
// Runtime constructor public AtmosphereFromGroundLoader(CelestialBody body) { this.body = body; afg = body.scaledBody.GetComponentInChildren<AtmosphereFromGround>(); }
// Runtime constructor public AtmosphereFromGroundLoader(CelestialBody body) : this() { this.body = body; afg = body.scaledBody.GetComponentInChildren <AtmosphereFromGround>(); }
public void Apply(AtmosphereFromGround afg) { afg.DEBUG_alwaysUpdateAll = DEBUG_alwaysUpdateAll; afg.doScale = doScale; afg.ESun = ESun; afg.Kr = Kr; afg.Km = Km; afg.transform.localScale = transformScale; afg.scaleDepth = scaleDepth; afg.samples = samples; afg.g = g; afg.waveLength = waveLength; afg.invWaveLength = invWaveLength; afg.outerRadius = outerRadius; afg.innerRadius = innerRadius; afg.transform.localPosition = Vector3.zero; Configuration.AtmosphereFromGroundLoader.CalculatedMembers(afg); afg.SetMaterial(true); }
/// <summary> /// Disables an existing atmosphere, or adds a new one if there is none /// </summary> private void ToggleAtmosphere(CelestialBody body) { // Disable an existing atmosphere if (body.atmosphere) { // Disable the Atmosphere from Ground AtmosphereFromGround[] afgs = body.GetComponentsInChildren <AtmosphereFromGround>(); foreach (AtmosphereFromGround afg in afgs) { afg.gameObject.SetActive(false); } // Disable the Light controller MaterialSetDirection[] msds = body.GetComponentsInChildren <MaterialSetDirection>(); foreach (MaterialSetDirection msd in msds) { msd.gameObject.SetActive(false); } // No Atmosphere :( body.atmosphere = false; // Get the material Renderer renderer = body.scaledBody.GetComponent <Renderer>(); Material material = renderer.sharedMaterial; Texture2D diffuseMap = (Texture2D)material.GetTexture("_MainTex"); Texture2D bumpMap = (Texture2D)material.GetTexture("_BumpMap"); // Create a new scaled material Material newMaterial = new Material(Shader.Find("Terrain/Scaled Planet (Simple)")); newMaterial.SetTexture("_MainTex", diffuseMap); newMaterial.SetTexture("_BumpMap", bumpMap); newMaterial.SetFloat("_Shininess", material.GetFloat("_Shininess")); // TODO: Investigate newMaterial.SetColor("_SpecColor", material.GetColor("_SpecColor")); // TODO: Investigate // Apply the material renderer.sharedMaterial = newMaterial; // Backup the old material GameObject backupGameObject = new GameObject("Backup"); backupGameObject.SetActive(false); backupGameObject.AddComponent <MeshRenderer>().material = material; backupGameObject.transform.parent = body.scaledBody.transform; // Update state toRestore.Add(body); } else { // Add a new atmosphere, this could get funny // We will just copy Laythe for the most parts body.atmosphere = true; body.atmosphereContainsOxygen = GetRandom(HighLogic.CurrentGame.Seed, 0, 99) < 10; // Oxygen is rare body.atmosphereDepth = (body.pqsController.radiusMax / 10) * GetRandomDouble(HighLogic.CurrentGame.Seed, 0.8, 1.2); body.atmosphereAdiabaticIndex = 1.39999997615814 * GetRandomDouble(HighLogic.CurrentGame.Seed, 0.8, 1.2); body.atmosphereGasMassLapseRate = 4.84741125702493 * GetRandomDouble(HighLogic.CurrentGame.Seed, 0.8, 1.2); body.atmosphereMolarMass = 0.0289644002914429 * GetRandomDouble(HighLogic.CurrentGame.Seed, 0.8, 1.2); Double multiplier = GetRandomDouble(HighLogic.CurrentGame.Seed, 0, 1); body.atmospherePressureSeaLevel = (595 * multiplier) + 5; body.atmosphereTemperatureSeaLevel = (270 * multiplier) + 240; body.atmDensityASL = (6.9 * multiplier) + 0.1; body.atmosphereTemperatureLapseRate = GetRandomDouble(HighLogic.CurrentGame.Seed, 0.004, 0.005); body.atmospherePressureCurveIsNormalized = true; body.atmosphereTemperatureCurveIsNormalized = true; body.atmosphereUsePressureCurve = true; body.atmosphereUseTemperatureCurve = true; // Select a curve template KeyValuePair <FloatCurve, FloatCurve> template = GetRandomElement(HighLogic.CurrentGame.Seed, CurveTemplates.Atmospheres); body.atmospherePressureCurve = template.Key; body.atmosphereTemperatureCurve = template.Value; // Now add the visuals GameObject scaledVersion = body.scaledBody; // Add the material light direction behavior MaterialSetDirection materialLightDirection = scaledVersion.AddComponent <MaterialSetDirection>(); materialLightDirection.valueName = "_localLightDirection"; // Create the atmosphere shell game object GameObject scaledAtmosphere = new GameObject("Atmosphere"); scaledAtmosphere.transform.parent = scaledVersion.transform; scaledAtmosphere.transform.position = scaledVersion.transform.position; scaledAtmosphere.transform.localPosition = Vector3.zero; scaledAtmosphere.layer = 9; MeshRenderer mrenderer = scaledAtmosphere.AddComponent <MeshRenderer>(); mrenderer.sharedMaterial = new Material(Shader.Find("AtmosphereFromGround")); MeshFilter meshFilter = scaledAtmosphere.AddComponent <MeshFilter>(); meshFilter.sharedMesh = Templates.ReferenceGeosphere; AtmosphereFromGround atmosphereFromGround = scaledAtmosphere.AddComponent <AtmosphereFromGround>(); // Get the average color of the current texture Renderer renderer = body.scaledBody.GetComponent <Renderer>(); Material material = renderer.sharedMaterial; Texture2D diffuseMap = Utility.CreateReadable((Texture2D)material.GetTexture("_MainTex")); Texture2D bumpMap = (Texture2D)material.GetTexture("_BumpMap"); Color average = Utility.GetAverageColor(diffuseMap); Color altered = AlterColor(average); Color darkAltered = Utility.Dark(altered); body.afg = atmosphereFromGround; atmosphereFromGround.planet = body; atmosphereFromGround.sunLight = Planetarium.fetch.Sun.gameObject; atmosphereFromGround.mainCamera = PlanetariumCamera.fetch.transform; atmosphereFromGround.waveLength = new Color(1 - darkAltered.r, 1 - darkAltered.g, 1 - darkAltered.b, 0.5f); // Ambient Light body.atmosphericAmbientColor = altered; // Scaled Material Material newMaterial = new Material(Shader.Find("Terrain/Scaled Planet (RimAerial)")); newMaterial.SetTexture("_MainTex", diffuseMap); newMaterial.SetTexture("_BumpMap", bumpMap); newMaterial.SetFloat("_Shininess", material.GetFloat("_Shininess")); // TODO: Investigate newMaterial.SetColor("_SpecColor", material.GetColor("_SpecColor")); // TODO: Investigate newMaterial.SetFloat("_rimPower", (Single)GetRandomDouble(HighLogic.CurrentGame.Seed, 3.8, 5)); newMaterial.SetFloat("_rimBlend", 1f); // Generate the atmosphere rim texture Gradient gradient = new Gradient(); gradient.Add(0f, altered); gradient.Add(0.2f, new Color(0.0549f, 0.0784f, 0.141f, 1f)); gradient.Add(1f, new Color(0.0196f, 0.0196f, 0.0196f, 1f)); // Generate the ramp from a gradient Texture2D ramp = new Texture2D(512, 1); Color[] colors = ramp.GetPixels(0); for (Int32 i = 0; i < colors.Length; i++) { // Compute the position in the gradient Single k = (Single)i / colors.Length; colors[i] = gradient.ColorAt(k); } ramp.SetPixels(colors, 0); ramp.Apply(true, false); ramp.wrapMode = TextureWrapMode.Clamp; ramp.mipMapBias = 0.0f; // Set the color ramp newMaterial.SetTexture("_rimColorRamp", ramp); // Apply the material renderer.sharedMaterial = newMaterial; // Backup the old material GameObject backupGameObject = new GameObject("Backup"); backupGameObject.SetActive(false); backupGameObject.AddComponent <MeshRenderer>().material = material; backupGameObject.transform.parent = scaledVersion.transform; // Update state toDelete.Add(body); } }
public void Update() { if (counter < 5) { counter += TimeWarp.fixedDeltaTime; return; } if (cams == null) { cams = new List<CameraWrapper>(); Camera[] cameras = Camera.allCameras; foreach (Camera cam in cameras) { try { CameraWrapper thisCam = new CameraWrapper(); thisCam.camName = cam.name.ToString(); thisCam.depth = cam.depth.ToString(); thisCam.farClipPlane += cam.farClipPlane.ToString(); thisCam.nearClipPlane += cam.nearClipPlane.ToString(); // layer cull appears unused by relevant cameras. /*for (int i = 0; i < cam.layerCullDistances.Length; i++) thisCam.layerCullDistances.Add("" + cam.layerCullDistances[i]);*/ cams.Add(thisCam); } catch (Exception e) { Debug.Log("*RSSGUI* Exception getting camera " + cam.name + "\n" + e); } } } if (Input.GetKeyDown(KeyCode.G) && Input.GetKey(KeyCode.LeftAlt)) { GUIOpen = !GUIOpen; if (GUIOpen) { afg = findAFG(); if (afg != null) { rt = afg.waveLength.r.ToString(); gt = afg.waveLength.g.ToString(); bt = afg.waveLength.b.ToString(); at = afg.waveLength.a.ToString(); ESunt = afg.ESun.ToString(); Krt = afg.Kr.ToString(); Kmt = afg.Km.ToString(); innert = (afg.innerRadius * ScaledSpace.ScaleFactor).ToString(); outert = (afg.outerRadius * ScaledSpace.ScaleFactor).ToString(); } } } }
private void Apply(AtmosphereFromGround afg) { afg.DEBUG_alwaysUpdateAll = DEBUG_alwaysUpdateAll; afg.doScale = doScale; afg.ESun = ESun; afg.Kr = Kr; afg.Km = Km; afg.transform.localScale = transformScale; afg.scaleDepth = scaleDepth; afg.samples = samples; afg.g = g; afg.waveLength = waveLength; afg.invWaveLength = invWaveLength; afg.outerRadius = outerRadius; afg.innerRadius = innerRadius; Configuration.AtmosphereFromGroundParser.CalculatedMembers(afg); try { MethodInfo afgSetMaterial = typeof(AtmosphereFromGround).GetMethod("SetMaterial", BindingFlags.NonPublic | BindingFlags.Instance); afgSetMaterial.Invoke(afg, new object[] { true }); } catch { Debug.Log("[Kopernicus]: ERROR AtmosphereFixer => Material-resetting for AtmosphereFromGround on " + afg.planet.bodyName + " failed!"); } }
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); }
void Start() { //Load up all the settings crap #region settings ConfigNode AKsettings = null; foreach(ConfigNode node in GameDatabase.Instance.GetConfigNodes("AlternisSettings")) AKsettings = node; bool btmp; if(AKsettings.HasValue("Enabled")) if(bool.TryParse(AKsettings.GetValue("Enabled"), out btmp)) alternisEnabled = btmp; //Don't bother continuing, mod is disabled... if(!alternisEnabled) return; float[] wltmp = newWarpLimits; if(AKsettings.HasValue("HyperWarp")) if(bool.TryParse(AKsettings.GetValue("HyperWarp"), out btmp)) if(btmp && TimeWarp.fetch != null) { TimeWarp.fetch.warpRates = newWarps; wltmp = newWarpLimitsHyper; } if(AKsettings.HasValue("EnableKerbinMoon")) if(bool.TryParse(AKsettings.GetValue("EnableKerbinMoon"), out btmp)) enableKerbinMoon = btmp; float ftmp; if(AKsettings.HasValue("CometBrightness")) if(float.TryParse(AKsettings.GetValue("CometBrightness"), out ftmp)) globalCometBright = ftmp; #endregion //Solar system is instantiated at the main menu and transferred to other scenes (apparantly), so it doesn't have to be loaded each time. //An advantage to this, too, is that Alternis is configured as soon as the game starts, and doesn't need to keep reordering itself. if(HighLogic.LoadedScene == GameScenes.MAINMENU && !alternisDone) //make extra sure something hasn't goofed and tried to run this elsewhere { #region textures //Load scaled maps newJoolTexture = GameDatabase.Instance.GetTexture(path + "newjool_dif", false); if(newJoolTexture != null) print("New jool texture loaded"); newLaytheScaledBump = GameDatabase.Instance.GetTexture(path + "newlaythe_nrm", true); if(newLaytheScaledBump != null) print("New laythe bump loaded"); newLaytheScaledColor = GameDatabase.Instance.GetTexture(path + "newlaythe_dif", false); if(newLaytheScaledColor != null) print("New laythe texture loaded"); newTyloScaledBump = GameDatabase.Instance.GetTexture(path + "newtylo_nrm", true); if(newTyloScaledBump != null) print("New tylo bump loaded"); newTyloScaledColor = GameDatabase.Instance.GetTexture(path + "newtylo_dif", false); if(newTyloScaledColor != null) print("New tylo texture loaded"); newDunaScaledColor = GameDatabase.Instance.GetTexture(path + "newduna_dif", false); if(newDunaScaledColor != null) print("New duna texture loaded"); newDunaScaledBump = GameDatabase.Instance.GetTexture(path + "newduna_nrm", true); if(newDunaScaledBump != null) print("New duna bump loaded"); //load height maps, these are done directly since they are ignored by GameDatabase - that way they can easily be dumped from memory newTyloHeight = new Texture2D(tyloHeightTexWidth, tyloHeightTexWidth / 2); newTyloHeight.LoadImage(System.IO.File.ReadAllBytes(path3 + "tylo_newheight.png")); if(newTyloHeight != null) print("New tylo height loadeth"); newDunaHeight = new Texture2D(dunaHeightTexWidth, dunaHeightTexWidth / 2); newDunaHeight.LoadImage(System.IO.File.ReadAllBytes(path3 + "duna_newheight.png")); if(newDunaHeight != null) print("New duna height loadeth"); newLaytheHeight = new Texture2D(laytheHeightTexWidth, laytheHeightTexWidth / 2); newLaytheHeight.LoadImage(System.IO.File.ReadAllBytes(path3 + "laythe_newheight.png")); if(newLaytheHeight != null) print("New laythe height loadeth"); //load color maps, same method as above newTyloColor = new Texture2D(tyloColorTexWidth, tyloColorTexWidth / 2); newTyloColor.LoadImage(System.IO.File.ReadAllBytes(path3 + "tylo_newcolor.png")); if(newTyloColor != null) print("New tylo color loadeth"); newDunaColor = new Texture2D(dunaColorTexWidth, dunaColorTexWidth / 2); newDunaColor.LoadImage(System.IO.File.ReadAllBytes(path3 + "duna_newcolor.png")); if(newDunaColor != null) print("New duna color loadeth"); //Load atmo ramps rampBlue = GameDatabase.Instance.GetTexture(path + "ramp_blue", false); if(rampBlue != null) { rampBlue.wrapMode = TextureWrapMode.Clamp; print("Blue ramp loaded"); } rampRed = GameDatabase.Instance.GetTexture(path + "ramp_red", false); if(rampRed != null) { rampRed.wrapMode = TextureWrapMode.Clamp; print("Red ramp loaded"); } #endregion #region locator //declare cb_sun through cb_eeloo here foreach(CelestialBody cb in FlightGlobals.Bodies) switch(cb.gameObject.name) { case "Sun": cb_sun = cb; break; case "Moho": cb_moho = cb; break; case "Eve": cb_eve = cb; break; case "Gilly": cb_gilly = cb; break; case "Kerbin": cb_kerbin = cb; break; case "Duna": cb_duna = cb; break; case "Ike": cb_ike = cb; break; case "Mun": cb_mun = cb; break; case "Minmus": cb_minmus = cb; break; case "Jool": cb_jool = cb; break; case "Tylo": cb_tylo = cb; break; case "Laythe": cb_laythe = cb; break; case "Vall": cb_vall = cb; break; case "Bop": cb_bop = cb; break; case "Pol": cb_pol = cb; break; case "Dres": cb_dres = cb; break; case "Eeloo": cb_eeloo = cb; break; } // now do your stuff to each cb_ var. #endregion //Do things to planets, but make sure all of them are present and accounted for first... //This feels like a wrong way to do things but it's only done once, so... if(cb_sun != null && cb_moho != null && cb_eve != null && cb_gilly != null && cb_kerbin != null && cb_duna != null && cb_ike != null && cb_mun != null && cb_minmus != null && cb_jool != null && cb_tylo != null && cb_vall != null && cb_bop != null && cb_pol != null && cb_laythe != null && cb_dres != null && cb_eeloo != null) { //BEGIN THE MOVEMENT! #region sun //Rescale the sun print("PlanetShifter: Shifting Sun"); cb_sun.GeeASL = 21; //Let's give the sun a more realistic surface gravity... cb_sun.Radius = 75431100; //... and a smaller radius, so the density remains the same. #endregion #region moho //Do things to moho print("PlanetShifter: Shifting Moho..."); cb_moho.orbit.semiMajorAxis = 14124215; cb_moho.orbit.inclination = 0.2502; cb_moho.orbit.eccentricity = 0.00175; //cb_moho.rotationPeriod = 8930; #endregion #region eve //Do things to eve print("PlanetShifter: Shifting Eve..."); cb_eve.orbit.semiMajorAxis = 7985550300; cb_eve.orbit.inclination = 3.5; cb_eve.orbit.eccentricity = 0.008; cb_eve.atmosphericAmbientColor = new Color(0.07f, 0.055f, 0.085f); cb_eve.atmosphereScaleHeight = 8.2; cb_eve.atmosphereMultiplier = 3.303f; //cb_eve.Radius = 585800; //cb_eve.pqsController.radius = 585800; //cb_eve.GeeASL = 0.901; #endregion #region mun //Do things to the mun print("PlanetShifter: Shifting Mun"); cb_mun.orbit.semiMajorAxis = 43152000; cb_mun.orbit.eccentricity = 0.002; cb_mun.orbit.inclination = 0.109; cb_mun.orbit.LAN = 180; cb_mun.orbit.argumentOfPeriapsis = 0; cb_mun.orbit.meanAnomalyAtEpoch = 1; cb_mun.orbitDriver.orbitColor = new Color(0.12f, 0.12f, 0.12f); cb_mun.Radius = 253000; cb_mun.pqsController.radius = 253000; cb_mun.GeeASL = 0.233; cb_mun.scienceValues.LandedDataValue = 3; cb_mun.scienceValues.InSpaceLowDataValue = 1; cb_mun.scienceValues.InSpaceHighDataValue = 1.5f; cb_mun.scienceValues.RecoveryValue = 2; PQSMod_VoronoiCraters muncraters = cb_mun.transform.GetComponentInChildren<PQSMod_VoronoiCraters>(); if(muncraters != null) { print(muncraters.rFactor); print(muncraters.rOffset); } #endregion #region kerbin //Do things to kerbin print("PlanetShifter: Shifting Kerbin..."); cb_kerbin.orbit.semiMajorAxis = 68506000; cb_kerbin.orbit.eccentricity = 0.02; cb_kerbin.orbit.inclination = 0.4; cb_kerbin.orbit.LAN = 0; cb_kerbin.orbit.argumentOfPeriapsis = 0; cb_kerbin.orbit.meanAnomalyAtEpoch = 4.14; cb_kerbin.initialRotation = 208; cb_kerbin.atmosphericAmbientColor = new Color(0.175f, 0.18f, 0.195f); cb_kerbin.orbitDriver.orbitColor = cb_kerbin.pqsController.mapOceanColor; cb_kerbin.tidallyLocked = true; #endregion #region duna //Do things to duna print("PlanetShifter: Shifting Duna..."); cb_duna.orbit.semiMajorAxis = 34598850; cb_duna.orbit.eccentricity = 0.05; cb_duna.orbit.inclination = 0.7; cb_duna.atmosphereScaleHeight = 4.5; cb_duna.atmosphereMultiplier = 0.178f; cb_duna.atmosphericAmbientColor = new Color(0.136f, 0.135f, 0.13f); cb_duna.tidallyLocked = true; cb_duna.pqsController.surfaceMaterial = cb_tylo.pqsController.surfaceMaterial; print("PlanetShifter: Shifting Duna Terrain"); GameObject dunaOldHeight = cb_duna.pqsController.transform.FindChild("_Height").gameObject; if(dunaOldHeight != null) { foreach(PQSMod_VertexHeightNoiseVertHeightCurve2 c in dunaOldHeight.GetComponentsInChildren<PQSMod_VertexHeightNoiseVertHeightCurve2>()) { c.deformity = 700; } PQSMod_VertexHeightMap cb_duna_vhm = dunaOldHeight.GetComponent<PQSMod_VertexHeightMap>(); if(cb_duna_vhm != null && newDunaHeight != null) { Destroy(cb_duna_vhm.heightMap); //obliterate the old heightmap cb_duna_vhm.heightMap = ScriptableObject.CreateInstance<MapSO>(); //make a new one cb_duna_vhm.heightMap.CreateMap(MapSO.MapDepth.Greyscale, newDunaHeight); //turn it into something usable cb_duna_vhm.heightMapDeformity = 15900; //tweak deformity cb_duna_vhm.heightMapOffset = -200; Destroy(newDunaHeight); //and then nuke the texture } } //i sure am good at keeping my naming conventions PQSMod_VertexColorMapBlend oldDunaColor = cb_duna.transform.GetComponentInChildren<PQSMod_VertexColorMapBlend>(); if(oldDunaColor != null && newDunaColor != null) { Destroy(oldDunaColor.vertexColorMap); oldDunaColor.vertexColorMap = ScriptableObject.CreateInstance<MapSO>(); oldDunaColor.vertexColorMap.CreateMap(MapSO.MapDepth.RGB, newDunaColor); oldDunaColor.blend = 1.0f; Destroy(newDunaColor); } PQSMod_VertexSimplexNoiseColor oldDunaColorNoise = cb_duna.transform.GetComponentInChildren<PQSMod_VertexSimplexNoiseColor>(); if(oldDunaColorNoise != null) { oldDunaColorNoise.order = oldDunaColor.order + 1; oldDunaColorNoise.blend = 0.1f; } PQSLandControl cb_duna_lc = cb_duna.pqsController.gameObject.GetComponentInChildren<PQSLandControl>(); if(cb_duna_lc != null) { cb_duna_lc.modEnabled = false; } #endregion #region ike //Do things to ike print("PlanetShifter: Shifting Ike..."); cb_ike.orbit.semiMajorAxis = 167988084550; cb_ike.orbit.eccentricity = 0.9585; cb_ike.orbit.inclination = 28.45; cb_ike.orbit.meanAnomalyAtEpoch = -1; cb_ike.tidallyLocked = false; cb_ike.rotationPeriod = 6983; cb_ike.Radius = 17500; cb_ike.pqsController.radius = 17500; cb_ike.GeeASL = 0.007; cb_ike.orbitDriver.orbitColor = new Color(0.15f, 0.15f, 0.19f); cb_ike.scienceValues.LandedDataValue = 20; cb_ike.scienceValues.spaceAltitudeThreshold = 150000; cb_ike.scienceValues.InSpaceLowDataValue = 5; cb_ike.scienceValues.InSpaceHighDataValue = 3; cb_ike.scienceValues.RecoveryValue = 8; #endregion #region gilly //Do things to gilly print("PlanetShifter: Shifting Gilly..."); cb_gilly.orbit.semiMajorAxis = 58084734575; cb_gilly.orbit.eccentricity = 0.990504; cb_gilly.orbit.inclination = 225.05; cb_gilly.orbit.LAN = 25.3; cb_gilly.orbit.argumentOfPeriapsis = 79.08; cb_gilly.orbit.meanAnomalyAtEpoch = 4.603; cb_gilly.tidallyLocked = false; cb_gilly.rotationPeriod = 15034; cb_gilly.Radius = 8500; cb_gilly.pqsController.radius = 8500; cb_gilly.GeeASL = 0.003; cb_gilly.orbitDriver.orbitColor = new Color(0.15f, 0.15f, 0.19f); cb_gilly.scienceValues.LandedDataValue = 30; cb_gilly.scienceValues.spaceAltitudeThreshold = 50000; cb_gilly.scienceValues.InSpaceLowDataValue = 5; cb_gilly.scienceValues.InSpaceHighDataValue = 3; cb_gilly.scienceValues.RecoveryValue = 8; //string s = "Listing all components! \n"; //foreach (Component c in cb_gilly.gameObject.GetComponentsInChildren(typeof(Component))) //{ // s += (c + " \n"); //} //print(s); Transform cb_gilly_height = cb_gilly.pqsController.transform.FindChild("_Height"); if(cb_gilly_height.gameObject != null) { if(cb_gilly_height.gameObject.GetComponentInChildren<PQSMod_VoronoiCraters>() == null) { PQSMod_VoronoiCraters cb_gilly_craters = cb_gilly_height.gameObject.AddComponent<PQSMod_VoronoiCraters>(); if(cb_gilly_craters != null && muncraters != null) { print("...and giving it craters"); cb_gilly_craters.voronoiFrequency = 7; cb_gilly_craters.deformation = 800; cb_gilly_craters.craterCurve = new AnimationCurve(muncraters.craterCurve.keys); cb_gilly_craters.jitter = 0.1f; cb_gilly_craters.jitterCurve = new AnimationCurve(muncraters.jitterCurve.keys); cb_gilly_craters.jitterHeight = 3; cb_gilly_craters.rOffset = 1; cb_gilly_craters.rFactor = 0.5f; cb_gilly_craters.voronoiDisplacement = 0.1f; cb_gilly_craters.order = 50; } } } #endregion #region minmus //Do things to minmus print("PlanetShifter: Shifting Minmus"); cb_minmus.orbit.semiMajorAxis = 14740300; cb_minmus.orbit.inclination = 0.03; cb_minmus.orbit.meanAnomalyAtEpoch = 0.9f; cb_minmus.Radius = 29000; cb_minmus.pqsController.radius = 29000; cb_minmus.tidallyLocked = false; cb_minmus.GeeASL = 0.022; cb_minmus.scienceValues.LandedDataValue = 5; cb_minmus.scienceValues.InSpaceLowDataValue = 2; cb_minmus.scienceValues.InSpaceHighDataValue = 2; cb_minmus.scienceValues.RecoveryValue = 4; } } #endregion #region jool //Do things to jool print("PlanetShifter: Shifting Jool..."); cb_jool.orbit.semiMajorAxis = 13605008470; cb_jool.orbit.eccentricity = 0.017; cb_jool.orbit.inclination = 1.957; cb_jool.orbit.LAN = 35; cb_jool.orbitDriver.orbitColor = new Color(0.45f, 0.55f, 0.7f); cb_jool.atmosphereScaleHeight = 20.3; cb_jool.atmosphereMultiplier = 6.5f; cb_jool.atmosphericAmbientColor = new Color(0.075f, 0.08f, 0.095f); //foreach (Keyframe k in cb_jool.temperatureCurve.keys) //{ // print(k.time + " " + k.value); //} cb_jool.temperatureCurve = new AnimationCurve(); cb_jool.temperatureCurve.AddKey(-0.2385731f, 700f); //these values are based off the debug printout from earlier, just with a *slightly* increased lower value cb_jool.temperatureCurve.AddKey(99.73615f, -86.13164f); cb_jool.scienceValues.InSpaceLowDataValue = 1.5f; cb_jool.scienceValues.InSpaceHighDataValue = 1; cb_jool.scienceValues.FlyingLowDataValue = 4; cb_jool.scienceValues.FlyingHighDataValue = 3; cb_jool.scienceValues.RecoveryValue = 1.5f; #endregion #region tylo //Do things to ty-- oh you get the idea cb_tylo.orbit.semiMajorAxis = 24708887045; cb_tylo.Radius = 1103000; cb_tylo.pqsController.radius = 1103000; cb_tylo.GeeASL = 4.035; cb_tylo.orbit.eccentricity = 0.03; cb_tylo.orbit.inclination = 1.22; cb_tylo.tidallyLocked = false; cb_tylo.rotationPeriod = 122805; cb_tylo.atmosphere = true; cb_tylo.atmosphereScaleHeight = 6.9; cb_tylo.atmosphereMultiplier = 0.554f; cb_tylo.staticPressureASL = 1; cb_tylo.atmosphericAmbientColor = new Color(0.175f, 0.15f, 0.15f); cb_tylo.orbitDriver.orbitColor = new Color(0.4f, 0.25f, 0.15f); cb_tylo.maxAtmosphereAltitude = 80000; cb_tylo.useLegacyAtmosphere = true; cb_tylo.scienceValues.FlyingLowDataValue = 9; cb_tylo.scienceValues.FlyingHighDataValue = 8; cb_tylo.scienceValues.flyingAltitudeThreshold = 25000; cb_tylo.scienceValues.InSpaceLowDataValue = 5; cb_tylo.scienceValues.InSpaceHighDataValue = 4; cb_tylo.scienceValues.spaceAltitudeThreshold = 1000000; cb_tylo.scienceValues.LandedDataValue = 18; //tweak LOD parameters cb_tylo.pqsController.maxLevel = cb_kerbin.pqsController.maxLevel + 2; cb_tylo.pqsController.minLevel = cb_kerbin.pqsController.minLevel + 2; cb_tylo.pqsController.minDetailDistance = cb_kerbin.pqsController.minDetailDistance + 2; cb_tylo.pqsController.maxDetailDistance = cb_kerbin.pqsController.maxDetailDistance + 2; { PQSMod_VertexHeightMap cb_tylo_height = cb_tylo.transform.GetComponentInChildren<PQSMod_VertexHeightMap>(); if(cb_tylo_height != null) { print("PlanetShifter: Shifting Tylo Terrain"); { if(newTyloHeight != null) { Destroy(cb_tylo_height.heightMap); //obliterate the old heightmap cb_tylo_height.heightMap = ScriptableObject.CreateInstance<MapSO>(); //make a new one cb_tylo_height.heightMap.CreateMap(MapSO.MapDepth.Greyscale, newTyloHeight); //turn it into something usable cb_tylo_height.heightMapDeformity = 21500; //tweak deformity Destroy(newTyloHeight); //and then nuke the texture } Transform cb_tylo_height = cb_tylo.pqsController.transform.FindChild("_Height"); { if(cb_tylo_height.gameObject != null) { PQSMod_VoronoiCraters cb_tylo_craters = cb_tylo_height.gameObject.AddComponent<PQSMod_VoronoiCraters>(); if(cb_tylo_craters != null && muncraters != null) { print("...and giving it craters"); cb_tylo_craters.voronoiFrequency = 24; cb_tylo_craters.deformation = 900; cb_tylo_craters.craterCurve = new AnimationCurve(muncraters.craterCurve.keys); cb_tylo_craters.craterColourRamp = FetchSolidGradient(new Color(0.58f, 0.54f, 0.4f)); cb_tylo_craters.order = cb_tylo_height.order + 50; cb_tylo_craters.jitter = 0.1f; cb_tylo_craters.jitterCurve = new AnimationCurve(muncraters.jitterCurve.keys); cb_tylo_craters.jitterHeight = 3; cb_tylo_craters.rOffset = 1; cb_tylo_craters.rFactor = 1; cb_tylo_craters.voronoiDisplacement = muncraters.voronoiDisplacement; } } PQSMod_VertexColorMap cb_tylo_vcm = cb_tylo.pqsController.transform.GetComponentInChildren<PQSMod_VertexColorMap>(); if(cb_tylo_vcm != null && newTyloColor) { print("PlanetShifter: Shifting tylo color"); Destroy(cb_tylo_vcm.vertexColorMap); cb_tylo_vcm.vertexColorMap = ScriptableObject.CreateInstance<MapSO>(); cb_tylo_vcm.vertexColorMap.CreateMap(MapSO.MapDepth.RGB, newTyloColor); Destroy(newTyloColor); } PQSMod_VertexSimplexHeight cb_tylo_vsh = cb_tylo.pqsController.transform.GetComponentInChildren<PQSMod_VertexSimplexHeight>(); if(cb_tylo_vsh != null) { cb_tylo_vsh.deformity = 5500; cb_tylo_vsh.frequency = 5; } PQSMod_VertexSimplexHeightAbsolute cb_tylo_vsha = cb_tylo.pqsController.transform.GetComponentInChildren<PQSMod_VertexSimplexHeightAbsolute>(); if(cb_tylo_vsh != null) { cb_tylo_vsh.deformity = 3100; cb_tylo_vsh.frequency = 6; } #endregion #region vall print("Planetshifter: shifting vall"); cb_vall.orbit.semiMajorAxis = 4995040; cb_vall.orbit.eccentricity = 0.011; cb_vall.orbit.inclination = 2.337; cb_vall.GeeASL = 0.0772; cb_vall.Radius = 99800; cb_vall.pqsController.radius = 99800; PQSMod_VertexHeightMap cb_vall_hm = cb_vall.pqsController.gameObject.GetComponentInChildren<PQSMod_VertexHeightMap>(); if(cb_vall_hm != null) { cb_vall_hm.heightMapDeformity = 1800; } #endregion #region dres print("Planetshifter: shifting dres"); cb_dres.orbit.semiMajorAxis = 8000025; cb_dres.orbit.eccentricity = 0.002; cb_dres.orbit.inclination = 0.000; cb_dres.scienceValues.LandedDataValue = 6; cb_dres.scienceValues.InSpaceLowDataValue = 5; cb_dres.scienceValues.InSpaceHighDataValue = 4; cb_dres.scienceValues.RecoveryValue = 5; #endregion #region laythe //Laythe is just as important in the grand scheme of things as kerbin! //Let's remake it completely, it deserves better. cb_laythe.pqsController.surfaceMaterial = new Material(cb_kerbin.pqsController.surfaceMaterial); cb_laythe.pqsController.maxLevel = cb_kerbin.pqsController.maxLevel; cb_laythe.pqsController.minLevel = cb_kerbin.pqsController.minLevel; cb_laythe.pqsController.minDetailDistance = cb_kerbin.pqsController.minDetailDistance; cb_laythe.pqsController.maxDetailDistance = cb_kerbin.pqsController.maxDetailDistance; cb_laythe.atmosphericAmbientColor = new Color(0.075f, 0.08f, 0.095f); cb_laythe.orbitDriver.orbitColor = new Color(0.15f, 0.25f, 0.05f); cb_laythe.orbit.LAN = 0; cb_laythe.orbit.argumentOfPeriapsis = 0; cb_laythe.orbit.meanAnomalyAtEpoch = 1; cb_laythe.bodyDescription = "Long known as Kerbin's sister moon, Laythe was seeded with life hundreds of millions of years ago when a large asteroid struck Kerbin - catapulting boulders with various life forms into orbit around Jool. Given its proximity to Kerbin, some of this impact debris found its way to Laythe, depositing a precious cargo of microbes and, according to some theories, whole plant seeds. This life quickly spread across the moon, until it became the lush green world we know today.\n\n(There are, however, fringe theorists who believe that life started on Laythe and was brought to Kerbin, but that's just absurd)"; cb_laythe.scienceValues.LandedDataValue = 3; cb_laythe.scienceValues.SplashedDataValue = 3; cb_laythe.scienceValues.InSpaceLowDataValue = 1.5f; cb_laythe.scienceValues.InSpaceHighDataValue = 1; cb_laythe.scienceValues.FlyingLowDataValue = 2.5f; cb_laythe.scienceValues.FlyingHighDataValue = 2; cb_laythe.scienceValues.RecoveryValue = 3; print("PlanetShifter: Shifting Laythe terrain"); PQSLandControl cb_laythe_lc = cb_laythe.pqsController.gameObject.GetComponentInChildren<PQSLandControl>(); if(cb_laythe_lc != null) { print("Found LandControl, spewing land classes..."); foreach(PQSLandControl.LandClass lc in cb_laythe_lc.landClasses) { print(lc.landClassName); print(lc.color); if(lc.landClassName == "Mud") { lc.color = new Color(0.35f, 0.25f, 0.2f); lc.noiseColor = new Color(0.26f, 0.27f, 0.15f); lc.noiseBlend = 0.8f; lc.noiseFrequency = 20; } if(lc.landClassName == "BaseLand") { lc.color = new Color(0.16f, 0.185f, 0.15f); lc.noiseColor = new Color(0.14f, 0.15f, 0.02f); lc.noiseBlend = 0.2f; } if(lc.landClassName == "IceCaps") { lc.latitudeRange.endStart = 0.09; lc.latitudeRange.endEnd = 0.1; //print("IceCap latitude whatsit: ss-" + lc.latitudeRange.startStart + " se-" + lc.latitudeRange.startEnd + " es-" + lc.latitudeRange.endStart + " ee-" + lc.latitudeRange.endEnd); } } } PQSMod_VertexHeightMap cb_laythe_hm = cb_laythe.pqsController.gameObject.GetComponentInChildren<PQSMod_VertexHeightMap>(); if(cb_laythe_hm != null && newLaytheHeight != null) { Destroy(cb_laythe_hm.heightMap); //obliterate the old heightmap cb_laythe_hm.heightMap = ScriptableObject.CreateInstance<MapSO>(); cb_laythe_hm.heightMap.CreateMap(MapSO.MapDepth.Greyscale, newLaytheHeight); //turn it into something usable cb_laythe_hm.heightMapOffset = -400; cb_laythe_hm.heightMapDeformity = 7000; //tweak deformity Destroy(newLaytheHeight); //and then nuke the texture } PQSMod_VertexHeightNoise cb_laythe_vhn = cb_laythe.pqsController.gameObject.GetComponentInChildren<PQSMod_VertexHeightNoise>(); if(cb_laythe_vhn != null) { cb_laythe_vhn.deformity = 250; cb_laythe_vhn.frequency = 8; } #endregion #region bop print("pLaNeTsHiFtEr: sHiFtInG bOp"); if(enableKerbinMoon) { print("Turning bop into a COMPLETELY IMPOSSIBLE moon of a moon you should be ASHAMED"); cb_bop.orbit.eccentricity = 0.055; cb_bop.orbit.inclination = 0.12; cb_bop.orbit.semiMajorAxis = 3250900; cb_bop.Radius = 4900; cb_bop.pqsController.radius = 4900; cb_bop.GeeASL = 0.0253; cb_bop.bodyDescription = "A worthless lump of unusually-dense rock in a hopelessly unstable orbit. Despite the apparant instability, its orbit never seems to change. This merits further investigation..."; cb_bop.pqsController.surfaceMaterial = cb_gilly.pqsController.surfaceMaterial; cb_bop.scienceValues.LandedDataValue = 2; cb_bop.scienceValues.InSpaceLowDataValue = 1; cb_bop.scienceValues.InSpaceHighDataValue = 1f; cb_bop.scienceValues.RecoveryValue = 2; //This version of bop is a lot smaller, so reduce its LOD values accordingly cb_bop.pqsController.maxLevel = cb_gilly.pqsController.maxLevel; cb_bop.pqsController.minLevel = cb_gilly.pqsController.minLevel; PQSMod_VertexSimplexHeightAbsolute cb_bop_vsha = cb_bop.pqsController.transform.GetComponentInChildren<PQSMod_VertexSimplexHeightAbsolute>(); if(cb_bop_vsha != null) { cb_bop_vsha.seed = 348534534; cb_bop_vsha.deformity = 1700; cb_bop_vsha.frequency = 0.5; } PQSMod_VertexHeightNoise cb_bop_vhn = cb_bop.pqsController.transform.GetComponentInChildren<PQSMod_VertexHeightNoise>(); if(cb_bop_vhn != null) { cb_bop_vhn.seed = 994574854; cb_bop_vhn.deformity = 250; cb_bop_vhn.frequency = 3; } PQSCity kraken = cb_bop.pqsController.transform.FindChild("DeadKraken").GetComponent<PQSCity>(); if(kraken != null) { kraken.repositionRadiusOffset = 1000; //Temporary til I can find the damn thing again and set a proper altitude } } else { cb_bop.orbit.eccentricity = 0.0094; cb_bop.orbit.inclination = 0; cb_bop.orbit.semiMajorAxis = 14000543; cb_bop.pqsController.surfaceMaterial = cb_gilly.pqsController.surfaceMaterial; cb_bop.scienceValues.LandedDataValue = 3; cb_bop.scienceValues.InSpaceLowDataValue = 2; cb_bop.scienceValues.InSpaceHighDataValue = 1.5f; cb_bop.scienceValues.RecoveryValue = 3; } #endregion #region pol print("pLaNeTsHiFtEr: sHiFtInG pOl"); cb_pol.orbit.LAN = 120; cb_pol.orbit.eccentricity = 0.083; cb_pol.orbit.semiMajorAxis = 145500000; cb_pol.scienceValues.LandedDataValue = 3; cb_pol.scienceValues.InSpaceLowDataValue = 2; cb_pol.scienceValues.InSpaceHighDataValue = 1.5f; cb_pol.scienceValues.RecoveryValue = 3; #endregion #region eeloo print("PlanetShifter: Shifting Eeloo"); cb_eeloo.orbit.inclination = 1.15; cb_eeloo.orbit.eccentricity = 0.08; cb_eeloo.Radius = 478000; cb_eeloo.pqsController.radius = 478000; cb_eeloo.GeeASL = 0.687; #endregion #region relocator cb_kerbin.orbitingBodies.Remove(cb_mun); cb_kerbin.orbitingBodies.Remove(cb_minmus); cb_jool.orbitingBodies.Remove(cb_tylo); cb_jool.orbitingBodies.Remove(cb_vall); cb_duna.orbitingBodies.Remove(cb_ike); cb_eve.orbitingBodies.Remove(cb_gilly); cb_sun.orbitingBodies.Remove(cb_moho); //cb_sun.orbitingBodies.Remove(cb_kerbin); <- for some reason this really screws up everything... there don't seem to be any obvious adverse effects to commenting it out so, I guess it'll have to do. cb_sun.orbitingBodies.Remove(cb_duna); cb_eve.orbitingBodies.Add(cb_moho); cb_jool.orbitingBodies.Add(cb_kerbin); cb_vall.orbitingBodies.Add(cb_minmus); cb_jool.orbitingBodies.Add(cb_mun); cb_tylo.orbitingBodies.Add(cb_duna); cb_sun.orbitingBodies.Add(cb_vall); cb_sun.orbitingBodies.Add(cb_ike); cb_sun.orbitingBodies.Add(cb_tylo); cb_sun.orbitingBodies.Add(cb_gilly); if(enableKerbinMoon) { cb_jool.orbitingBodies.Remove(cb_bop); cb_kerbin.orbitingBodies.Add(cb_bop); } cb_mun.orbit.referenceBody = cb_jool; cb_kerbin.orbit.referenceBody = cb_jool; cb_duna.orbit.referenceBody = cb_tylo; cb_ike.orbit.referenceBody = cb_sun; cb_dres.orbit.referenceBody = cb_sun; cb_vall.orbit.referenceBody = cb_sun; cb_minmus.orbit.referenceBody = cb_vall; cb_gilly.orbit.referenceBody = cb_sun; cb_tylo.orbit.referenceBody = cb_sun; cb_moho.orbit.referenceBody = cb_eve; if(enableKerbinMoon) cb_bop.orbit.referenceBody = cb_kerbin; #endregion //finalize everything #region final tweaks foreach(CelestialBody cb2 in FlightGlobals.Bodies) { if(cb2.gameObject.name != "Sun") { cb2.sphereOfInfluence = GetNewSOI(cb2); cb2.hillSphere = GetNewHillSphere(cb2); //Kerbin, Laythe, and the Mun are in a Laplace resonance. To be absolutely sure that that remains the case, force the periods. if(cb2.gameObject.name == "Kerbin") cb2.orbit.period = 211926; //2 days 10 hours 52 minutes 6 seconds else if(cb2.gameObject.name == "Mun") cb2.orbit.period = 105963; //1 day 5 hours 26 minutes 3 seconds else if(cb2.gameObject.name == "Laythe") cb2.orbit.period = 52982; //14 hours 43 minutes 2 seconds else cb2.orbit.period = GetNewPeriod(cb2); //Just calculate the rest cb2.timeWarpAltitudeLimits = newWarpLimits; //Thank you, eggrobin & NathanKell cb2.orbit.meanAnomaly = cb2.orbit.meanAnomalyAtEpoch; // let KSP handle epoch cb2.orbit.orbitPercent = cb2.orbit.meanAnomalyAtEpoch / 6.2831853071795862; cb2.orbit.ObTAtEpoch = cb2.orbit.orbitPercent * cb2.orbit.period; cb2.CBUpdate(); } } #endregion //god, I need to rewrite this section sometimes. I mean, it WORKS but it just feels so WRONG #region scaled space also known as the galaxy of terror GameObject kerbinAtmo = null; GameObject tyloAtmo = null; Material kerbinMat = null; Mesh plainSphere = null; Transform sun = null; foreach(Transform t in ScaledSpace.Instance.scaledSpaceTransforms) { if(t.gameObject.name == "Kerbin") { print("PlanetShifter: HACKY HACK GRABBING KERBIN ATMOSPHERE FOR DUPLICATION"); //forgive me father for i have sinned kerbinAtmo = t.FindChild("Atmosphere").gameObject; kerbinMat = t.gameObject.renderer.material; plainSphere = t.gameObject.GetComponent<MeshFilter>().mesh; } if(t.gameObject.name == "Sun") { sun = t; } } if(kerbinAtmo != null) { AtmosphereFromGround atmk = kerbinAtmo.GetComponent<AtmosphereFromGround>(); if(atmk != null) { atmk.waveLength = new Color(0.750f, 0.670f, 0.575f); } foreach(Transform t in ScaledSpace.Instance.scaledSpaceTransforms) { //first do the stuff that needs new atmospheres if(t.gameObject.name == "Tylo" && kerbinMat != null) { print("PlanetShifter: Shifting Tylo scaled space"); t.localScale = new Vector3(0.1838f, 0.1838f, 0.1838f); tyloAtmo = Instantiate(kerbinAtmo, t.position, t.rotation) as GameObject; tyloAtmo.name = "Atmosphere"; tyloAtmo.transform.parent = t; tyloAtmo.transform.localScale = Vector3.one; Material m = new Material(kerbinMat); t.gameObject.renderer.material = m; t.gameObject.renderer.material.SetTexture("_MainTex", newTyloScaledColor); t.gameObject.renderer.material.SetTexture("_BumpMap", newTyloScaledBump); t.gameObject.renderer.material.SetTexture("_rimColorRamp", rampRed); t.gameObject.renderer.material.SetColor("_SpecColor", Color.black); t.gameObject.GetComponent<MeshFilter>().mesh = plainSphere; t.gameObject.renderer.material.SetColor("_Color", Color.grey); //Default is too bright. This matches better! AtmosphereFromGround atm = tyloAtmo.GetComponent<AtmosphereFromGround>(); if(atm != null) { atm.planet = cb_tylo; atm.waveLength = new Color(0.8f, 0.93f, 0.95f); } } //and now the tweaks //if (t.gameObject.name == "Eve") //{ //t.localScale = new Vector3(0.09751f, 0.09751f, 0.09751f); //} if(t.gameObject.name == "Laythe") { t.gameObject.renderer.material.SetTexture("_rimColorRamp", rampBlue); t.gameObject.renderer.material.SetTexture("_MainTex", newLaytheScaledColor); t.gameObject.renderer.material.SetTexture("_BumpMap", newLaytheScaledBump); t.gameObject.renderer.material.SetColor("_Color", new Color(0.75f, 0.75f, 0.75f)); AtmosphereFromGround atm = t.FindChild("Atmosphere").GetComponent<AtmosphereFromGround>(); if(atm != null) { atm.waveLength = new Color(0.730f, 0.70f, 0.640f); } } if(t.gameObject.name == "Kerbin") { t.gameObject.renderer.material.SetTexture("_rimColorRamp", rampBlue); AtmosphereFromGround atm = t.FindChild("Atmosphere").GetComponent<AtmosphereFromGround>(); if(atm != null) { atm.waveLength = new Color(0.725f, 0.670f, 0.620f); } } if(t.gameObject.name == "Duna") { t.gameObject.GetComponent<MeshFilter>().mesh = plainSphere; t.gameObject.renderer.material.SetTexture("_MainTex", newDunaScaledColor); t.gameObject.renderer.material.SetTexture("_BumpMap", newDunaScaledBump); AtmosphereFromGround atm = t.FindChild("Atmosphere").GetComponent<AtmosphereFromGround>(); if(atm != null) { atm.waveLength = new Color(0.525f, 0.570f, 0.620f); } } if(t.gameObject.name == "Ike") { t.localScale = new Vector3(0.002917f, 0.002917f, 0.002917f); SpawnCometTail(t, sun, "IonTail", false, null, 2.6f, 0.5f); SpawnCometTail(t, sun, "DustTail", true, cb_ike.orbit, 2.75f, 0.8f); } if(t.gameObject.name == "Gilly") { t.localScale = new Vector3(0.01415f, 0.01415f, 0.01415f); SpawnCometTail(t, sun, "IonTail", false, null, 0.6f, 1.5f); SpawnCometTail(t, sun, "DustTail", true, cb_gilly.orbit, 1.0f, 1.0f); } if(t.gameObject.name == "Bop" && enableKerbinMoon) { t.localScale = new Vector3(0.0090352f, 0.0090352f, 0.0090352f); } if(t.gameObject.name == "Jool") { AtmosphereFromGround atm = t.FindChild("Atmosphere").GetComponent<AtmosphereFromGround>(); if(atm != null) { atm.waveLength = new Color(0.750f, 0.720f, 0.680f); } if(kerbinMat != null) { Texture oldJoolNorm = t.gameObject.renderer.material.GetTexture("_BumpMap"); Material m = new Material(kerbinMat); t.gameObject.renderer.material = m; t.gameObject.renderer.material.SetTexture("_MainTex", newJoolTexture); t.gameObject.renderer.material.SetTexture("_BumpMap", oldJoolNorm); t.gameObject.renderer.material.SetTexture("_rimColorRamp", rampBlue); t.gameObject.renderer.material.SetColor("_SpecColor", Color.black); t.gameObject.renderer.material.SetTextureScale("_BumpMap", new Vector2(32, 16)); t.gameObject.renderer.material.SetColor("_Color", new Color(0.75f, 0.75f, 0.75f)); } } if(t.gameObject.name == "Eeloo") { t.localScale = new Vector3(0.07968f, 0.07968f, 0.07968f); } if(t.gameObject.name == "Vall") { t.localScale = new Vector3(0.1663f, 0.1663f, 0.1663f); } if(t.gameObject.name == "Mun") { t.localScale = new Vector3(0.0421751f, 0.0421751f, 0.0421751f); } if(t.gameObject.name == "Minmus") { t.localScale = new Vector3(0.004834f, 0.004834f, 0.004834f); t.gameObject.renderer.material.SetTexture("_MainTex", newMinmusTexture); t.gameObject.renderer.material.SetColor("_SpecColor", Color.black); t.gameObject.renderer.material.SetColor("_Color", Color.grey); } if(t.gameObject.name == "Sun") { t.localScale = new Vector3(11.82235f, 11.82235f, 11.82235f); } } alternisDone = true; } } #endregion #region comet tails void SpawnCometTail(Transform target, Transform sun, string tailname, bool dustTail, Orbit targetorbit, float scale, float brightness) { if(target != null && sun != null) { if(target.FindChild(tailname) == null) { print("Adding comet tail " + tailname + " to " + target.gameObject.name); GameObject tail = new GameObject(tailname, typeof(CometLogic)); if(tail != null) { tail.name = tailname; tail.SetActive(true); tail.transform.parent = target; tail.transform.localPosition = Vector3.zero; GameObject tailVisual = null; if(dustTail) { tailVisual = GameDatabase.Instance.GetModel(path2 + "comet_dusttail/comet_dusttail"); tailVisual.transform.localScale = new Vector3(250 * scale, 250 * scale, 250 * scale); } else { tailVisual = GameDatabase.Instance.GetModel(path2 + "comet_iontail/comet_iontail"); tailVisual.transform.localScale = new Vector3(220 * scale, 220 * scale, 220 * scale); } CometLogic cl = tail.GetComponent<CometLogic>(); if(cl != null && tailVisual != null) { tailVisual.transform.parent = tail.transform; tailVisual.transform.localPosition = Vector3.zero; tailVisual.transform.localEulerAngles = new Vector3(-90, 0, 0); tailVisual.SetActive(true); cl.target = target; cl.sun = sun; cl.dustTail = dustTail; cl.brightness = brightness * globalCometBright; if(dustTail) cl.cometOrbit = targetorbit; cl.visual = tailVisual.transform.GetChild(0).gameObject; print("Tail FX creation successful"); } else { print("ERROR: tail creator code SNAFU - code 2"); } } else { print("ERROR: tail creator code SNAFU - code 1"); } } else { print("Comet of this name already existed"); } } #endregion #region map building /*void BuildMaps() { if (mapBuildMode && cb_laythe.pqsController != null) { Texture2D[] maps = cb_laythe.pqsController.CreateMaps(2048, 12000, true, 0, cb_laythe.pqsController.mapOceanColor); int i = 0; foreach (Texture2D t in maps) { File.WriteAllBytes(Application.dataPath + "/newlaythe" + i + ".png", t.EncodeToPNG()); i++; } Application.Quit(); } }*/ #endregion } } }
// Post apply event void IParserEventSubscriber.PostApply(ConfigNode node) { // Should we remove the atmosphere if (body.celestialBody.atmosphere && removeAtmosphere.value) { // Find atmosphere from ground and destroy the game object AtmosphereFromGround atmosphere = body.scaledVersion.GetComponentsInChildren <AtmosphereFromGround>(true)[0]; atmosphere.transform.parent = null; UnityEngine.Object.Destroy(atmosphere.gameObject); // Destroy the light controller MaterialSetDirection light = body.scaledVersion.GetComponentsInChildren <MaterialSetDirection>(true)[0]; UnityEngine.Object.Destroy(light); // No more atmosphere :( body.celestialBody.atmosphere = false; } // If we have a PQS if (body.pqsVersion != null) { Logger.Active.Log("[Kopernicus]: Configuration.Template: Using Template \"" + body.celestialBody.bodyName + "\""); // Should we remove the ocean? if (body.celestialBody.ocean && removeOcean.value) { // Find atmosphere the ocean PQS PQS ocean = body.pqsVersion.GetComponentsInChildren <PQS> (true).Where(pqs => pqs != body.pqsVersion).First(); PQSMod_CelestialBodyTransform cbt = body.pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform> (true).First(); // Destroy the ocean PQS (this could be bad - destroying the secondary fades...) cbt.planetFade.secondaryRenderers.Remove(ocean.gameObject); cbt.secondaryFades = null; ocean.transform.parent = null; UnityEngine.Object.Destroy(ocean); // No more ocean :( body.celestialBody.ocean = false; body.pqsVersion.mapOcean = false; } // Selectively remove PQS Mods if (removePQSMods != null && removePQSMods.value.LongCount() > 0) { // Get a list of all the PQS mods (immediate children, don't f**k the ocean) List <PQSMod> mods = body.pqsVersion.transform.GetComponentsInChildren <PQSMod>(true).Where(mod => mod.transform.parent == body.pqsVersion.transform).ToList(); foreach (string mod in removePQSMods.value) { // Get the mods matching the string string modName = "PQSMod_" + mod; foreach (PQSMod m in mods.Where(m => m.GetType().ToString().EndsWith(modName))) { Logger.Active.Log("Removed PQSMod: " + m.name + " (" + m.GetType() + ")"); UnityEngine.Object.Destroy(m); } } } } // Should we remove the progress tree if (removeProgressTree.value) { body.celestialBody.progressTree = null; } // Figure out what kind of body we are if (body.scaledVersion.GetComponentsInChildren <SunShaderController>(true).Length > 0) { type = BodyType.Star; } else if (body.celestialBody.atmosphere) { type = BodyType.Atmospheric; } else { type = BodyType.Vacuum; } }
public AtmosphereFromGroundParser(AtmosphereFromGround afg, CelestialBody body) { this.afg = afg; this.body = body; }
// Runtime constructor public AtmosphereFromGroundLoader(CelestialBody body) { this.body = body; afg = body.afg; // Set Defaults afg.planet = body; afg.ESun = 30f; afg.Kr = 0.00125f; afg.Km = 0.00015f; afg.samples = 4f; afg.g = -0.85f; if (afg.waveLength == new Color(0f, 0f, 0f, 0f)) { afg.waveLength = new Color(0.65f, 0.57f, 0.475f, 0.5f); } afg.outerRadius = (((float)body.Radius) * 1.025f) * INVSCALEFACTOR; afg.innerRadius = afg.outerRadius * 0.975f; afg.scaleDepth = -0.25f; afg.invWaveLength = new Color((float)(1d / Math.Pow(afg.waveLength[0], 4)), (float)(1d / Math.Pow(afg.waveLength[1], 4)), (float)(1d / Math.Pow(afg.waveLength[2], 4)), 0.5f); CalculatedMembers(afg); }
// Default Constructor public AtmosphereFromGroundLoader() { body = generatedBody.celestialBody; afg = generatedBody.scaledVersion.GetComponentsInChildren<AtmosphereFromGround>(true)[0]; }
private IEnumerator <YieldInstruction> NovaCoroutine() { LoggingUtil.LogDebug(this, "Jool is going nova"); state = State.JOOL_SHRINK; joolScale = 1.0f; SetTransformed(false); // Get the AtmosphereFromGround object AtmosphereFromGround afg = Resources.FindObjectsOfTypeAll <AtmosphereFromGround>(). Where(a => a != null && a.planet != null && a.planet.name == "Jool").First(); // Capture original scaling info origScale = jool.scaledBody.transform.localScale; origInnerRadius = afg.innerRadius; origOuterRadius = afg.outerRadius; origAtmoScale = afg.transform.localScale; // Rescale over every iteration while (true) { // Check if this will be the last scaling operation bool lastIteration = joolScale <= SHRUNK_SCALE; if (lastIteration) { joolScale = SHRUNK_SCALE; } // Rescale Jool's ScaledVersion Transform jool.scaledBody.transform.localScale = origScale * joolScale; // Rescale atmosphere afg.innerRadius = origInnerRadius * joolScale; afg.outerRadius = origOuterRadius * joolScale; afg.transform.localScale = origAtmoScale * joolScale; afg.KrESun = afg.Kr * afg.ESun; afg.KmESun = afg.Km * afg.ESun; afg.Kr4PI = afg.Kr * 4f * (float)Math.PI; afg.Km4PI = afg.Km * 4f * (float)Math.PI; afg.g2 = afg.g * afg.g; afg.outerRadius2 = afg.outerRadius * afg.outerRadius; afg.innerRadius2 = afg.innerRadius * afg.innerRadius; afg.scale = 1f / (afg.outerRadius - afg.innerRadius); afg.scaleDepth = -0.25f; afg.scaleOverScaleDepth = afg.scale / afg.scaleDepth; afg.SetMaterial(true); yield return(null); if (lastIteration) { break; } } // Do the transformation SetTransformed(true); // Add our extra stuff GameObject explosion = new GameObject("Explosion"); explosion.transform.parent = jool.scaledBody.transform; explosion.layer = jool.scaledBody.layer; explosion.transform.localScale = Vector3.one * 1.01f; explosion.transform.localPosition = Vector3.zero; explosion.transform.localRotation = Quaternion.identity; MeshRenderer explosionRenderer = explosion.AddComponent <MeshRenderer>(); foreach (FieldInfo field in typeof(MeshRenderer).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { field.SetValue(explosionRenderer, field.GetValue(jool.scaledBody.GetComponent <MeshRenderer>())); } Texture2D explosionTex = TextureUtil.LoadTexture("ContractPacks/JoolianEncounter/Images/explosion.dds.noload"); explosionRenderer.material.shader = Shader.Find("KSP/Alpha/Translucent"); explosionRenderer.material.SetTexture(Shader.PropertyToID("_MainTex"), explosionTex); MeshFilter explosionMesh = explosion.AddComponent <MeshFilter>(); explosionMesh.sharedMesh = jool.scaledBody.GetComponent <MeshFilter>().sharedMesh; explosion.SetActive(true); // Rescale over every iteration joolScale = SHRUNK_SCALE; state = State.SUN_GROW; stateTime = Time.time; while (true) { // Check if this will be the last scaling operation bool lastIteration = joolScale >= FINAL_SCALE; if (lastIteration) { joolScale = FINAL_SCALE; } // Rescale Jool's scaled body Transform jool.scaledBody.transform.localScale = origScale * joolScale; // Fade the alpha out as the explosion grows float alpha = Mathf.Lerp(1.0f, 0.0f, (explosionScale / joolScale) / 10.0f); explosionRenderer.material.color = new Color(1.0f, 1.0f, 1.0f, alpha); // Rescale the explosion explosion.transform.localScale = Vector3.one * (explosionScale / joolScale); if (lastIteration) { break; } yield return(null); } // Continue with the outer part of the explosion state = State.EXPLOSION_GROW; explosionsDone = false; while (true) { // Rescale the explosion explosion.transform.localScale = Vector3.one * (explosionScale / joolScale); // Stop burninating 5000 km after it has passed if ((explosionScale / joolScale) * 1.01f * jool.Radius >= FlightGlobals.ActiveVessel.altitude + jool.Radius + 5000000) { burninating = false; } // There's a big delay before the atmospheric effects kick in, so start burninating pretty early (5000 km) else if (!burninating && (explosionScale / joolScale) * jool.Radius >= FlightGlobals.ActiveVessel.altitude + jool.Radius - 5000000) { burninating = true; StartCoroutine(Burninator()); } // Blow up the ship! (part of it) if (!explosionsDone && (explosionScale / joolScale) * jool.Radius >= FlightGlobals.ActiveVessel.altitude + jool.Radius) { ExplodeParts(); // Do a camera wobble LoggingUtil.LogDebug(this, "overheat event"); FlightCameraFX fcfx = UnityEngine.Object.FindObjectOfType <FlightCameraFX>(); MethodInfo eventMethod = typeof(FlightCameraFX).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic). Where(mi => mi.Name == "OnVesselEvent").First(); eventMethod.Invoke(fcfx, new object[] { new EventReport(FlightEvents.OVERHEAT, FlightGlobals.ActiveVessel.rootPart, FlightGlobals.ActiveVessel.name, "Jool") }); } // Fade the alpha out as the explosion grows float alpha = Mathf.Lerp(1.0f, 0.0f, (explosionScale / joolScale) / 10.0f); explosionRenderer.material.color = new Color(1.0f, 1.0f, 1.0f, alpha); if ((explosionScale / joolScale) >= 10.0f) { break; } yield return(null); } // Remove explodey part burninating = false; explosion.transform.parent = null; Destroy(explosion); Destroy(explosionTex); }
// Parser Post Apply Event public void PostApply(ConfigNode node) { // If an orbit is defined, we orbit something if (orbit != null) { // If this body needs orbit controllers, create them if (generatedBody.orbitDriver == null) { generatedBody.orbitDriver = generatedBody.celestialBody.gameObject.AddComponent <OrbitDriver> (); generatedBody.orbitRenderer = generatedBody.celestialBody.gameObject.AddComponent <OrbitRenderer> (); } // Setup orbit generatedBody.orbitDriver.updateMode = OrbitDriver.UpdateMode.UPDATE; orbit.Apply(generatedBody); } // If a PQS version was definied if (pqs != null) { // Assign the generated PQS to our new world generatedBody.pqsVersion = pqs.pqsVersion; // Adjust the radius of the PQSs appropriately foreach (PQS p in generatedBody.pqsVersion.GetComponentsInChildren(typeof(PQS), true)) { p.radius = generatedBody.celestialBody.Radius; } } // We need to generate new scaled space meshes if // a) we are using a template and we've change either the radius or type of body // b) we aren't using a template if (((template != null) && (Math.Abs(template.radius - generatedBody.celestialBody.Radius) > 1.0 || template.type != scaledVersion.type.value)) || template == null) { const double rJool = 6000000.0; const float rScaled = 1000.0f; // Compute scale between Jool and this body float scale = (float)(generatedBody.celestialBody.Radius / rJool); generatedBody.scaledVersion.transform.localScale = new Vector3(scale, scale, scale); // Attempt to load a cached version of the scale space string CacheDirectory = KSPUtil.ApplicationRootPath + ScaledSpaceCacheDirectory; string CacheFile = CacheDirectory + "/" + generatedBody.name + ".bin"; Directory.CreateDirectory(CacheDirectory); if (File.Exists(CacheFile)) { Debug.Log("[Kopernicus]: Body.PostApply(ConfigNode): Loading cached scaled space mesh: " + generatedBody.name); generatedBody.scaledVersion.GetComponent <MeshFilter> ().sharedMesh = Utility.DeserializeMesh(CacheFile); } // Otherwise we have to generate the mesh else { Debug.Log("[Kopernicus]: Body.PostApply(ConfigNode): Generating scaled space mesh: " + generatedBody.name); Mesh scaledVersionMesh = ComputeScaledSpaceMesh(generatedBody); generatedBody.scaledVersion.GetComponent <MeshFilter> ().sharedMesh = scaledVersionMesh; Utility.SerializeMesh(scaledVersionMesh, CacheFile); } // Apply mesh to the body SphereCollider collider = generatedBody.scaledVersion.GetComponent <SphereCollider>(); if (collider != null) { collider.radius = rScaled; } // If we have an atmosphere, generate that too if (generatedBody.celestialBody.atmosphere) { // Find atmosphere from ground AtmosphereFromGround[] afgs = generatedBody.scaledVersion.GetComponentsInChildren <AtmosphereFromGround>(true); if (afgs.Length > 0) { // Get the atmosphere from ground AtmosphereFromGround atmosphereFromGround = afgs[0]; // We need to get the body for Jool (to steal it's mesh) PSystemBody Jool = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Jool"); // Generate mesh using Jool as a template Mesh mesh = Utility.DuplicateMesh(Jool.scaledVersion.GetComponent <MeshFilter> ().sharedMesh); //Utility.ScaleVerts (mesh, (float)(generatedBody.celestialBody.Radius / rJool)); atmosphereFromGround.GetComponent <MeshFilter>().sharedMesh = mesh; } } } // Post gen celestial body Utility.DumpObjectFields(generatedBody.celestialBody, " Celestial Body "); }
// Post apply event void IParserEventSubscriber.PostApply(ConfigNode node) { // Should we remove the atmosphere if (Body.celestialBody.atmosphere && RemoveAtmosphere.Value) { // Find atmosphere from ground and destroy the game object AtmosphereFromGround atmosphere = Body.scaledVersion.GetComponentsInChildren <AtmosphereFromGround>(true)[0]; atmosphere.transform.parent = null; Object.Destroy(atmosphere.gameObject); // Destroy the light controller MaterialSetDirection light = Body.scaledVersion.GetComponentsInChildren <MaterialSetDirection>(true)[0]; Object.Destroy(light); // No more atmosphere :( Body.celestialBody.atmosphere = false; } Logger.Active.Log("Using Template \"" + Body.celestialBody.bodyName + "\""); // If we have a PQS if (Body.pqsVersion != null) { #if (!KSP_VERSION_1_8) // We only support one surface material per body, so use the one with the highest quality available if (GameSettings.TERRAIN_SHADER_QUALITY == 3) { Material surfaceMaterial = Body.pqsVersion.ultraQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.highQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.mediumQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.surfaceMaterial; } Body.pqsVersion.ultraQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.highQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.mediumQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.lowQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.surfaceMaterial = surfaceMaterial; } #endif if (GameSettings.TERRAIN_SHADER_QUALITY == 2) { Material surfaceMaterial = Body.pqsVersion.highQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.mediumQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.surfaceMaterial; } #if (!KSP_VERSION_1_8) Body.pqsVersion.ultraQualitySurfaceMaterial = surfaceMaterial; #endif Body.pqsVersion.highQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.mediumQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.lowQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.surfaceMaterial = surfaceMaterial; } else if (GameSettings.TERRAIN_SHADER_QUALITY == 1) { Material surfaceMaterial = Body.pqsVersion.mediumQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.surfaceMaterial; } #if (!KSP_VERSION_1_8) Body.pqsVersion.ultraQualitySurfaceMaterial = surfaceMaterial; #endif Body.pqsVersion.highQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.mediumQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.lowQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.surfaceMaterial = surfaceMaterial; } else if (GameSettings.TERRAIN_SHADER_QUALITY == 0) { Material surfaceMaterial = Body.pqsVersion.lowQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = Body.pqsVersion.surfaceMaterial; } #if (!KSP_VERSION_1_8) Body.pqsVersion.ultraQualitySurfaceMaterial = surfaceMaterial; #endif Body.pqsVersion.highQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.mediumQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.lowQualitySurfaceMaterial = surfaceMaterial; Body.pqsVersion.surfaceMaterial = surfaceMaterial; } // Should we remove the ocean? if (Body.celestialBody.ocean) { // Find atmosphere the ocean PQS PQS ocean = Body.pqsVersion.GetComponentsInChildren <PQS>(true) .First(pqs => pqs != Body.pqsVersion); PQSMod_CelestialBodyTransform cbt = Body.pqsVersion .GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).First(); #if (!KSP_VERSION_1_8) if (GameSettings.TERRAIN_SHADER_QUALITY == 3) { Material surfaceMaterial = ocean.ultraQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = ocean.highQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = ocean.mediumQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = ocean.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = ocean.surfaceMaterial; } ocean.ultraQualitySurfaceMaterial = surfaceMaterial; ocean.highQualitySurfaceMaterial = surfaceMaterial; ocean.mediumQualitySurfaceMaterial = surfaceMaterial; ocean.lowQualitySurfaceMaterial = surfaceMaterial; ocean.surfaceMaterial = surfaceMaterial; } #endif if (GameSettings.TERRAIN_SHADER_QUALITY == 2) { Material surfaceMaterial = ocean.highQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = ocean.mediumQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = ocean.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = ocean.surfaceMaterial; } #if (!KSP_VERSION_1_8) ocean.ultraQualitySurfaceMaterial = surfaceMaterial; #endif ocean.highQualitySurfaceMaterial = surfaceMaterial; ocean.mediumQualitySurfaceMaterial = surfaceMaterial; ocean.lowQualitySurfaceMaterial = surfaceMaterial; ocean.surfaceMaterial = surfaceMaterial; } else if (GameSettings.TERRAIN_SHADER_QUALITY == 1) { Material surfaceMaterial = ocean.mediumQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = ocean.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = ocean.surfaceMaterial; } #if (!KSP_VERSION_1_8) ocean.ultraQualitySurfaceMaterial = surfaceMaterial; #endif ocean.highQualitySurfaceMaterial = surfaceMaterial; ocean.mediumQualitySurfaceMaterial = surfaceMaterial; ocean.lowQualitySurfaceMaterial = surfaceMaterial; ocean.surfaceMaterial = surfaceMaterial; } else if (GameSettings.TERRAIN_SHADER_QUALITY == 0) { Material surfaceMaterial = ocean.lowQualitySurfaceMaterial; if (!surfaceMaterial) { surfaceMaterial = ocean.lowQualitySurfaceMaterial; } if (!surfaceMaterial) { surfaceMaterial = ocean.surfaceMaterial; } #if (!KSP_VERSION_1_8) ocean.ultraQualitySurfaceMaterial = surfaceMaterial; #endif ocean.highQualitySurfaceMaterial = surfaceMaterial; ocean.mediumQualitySurfaceMaterial = surfaceMaterial; ocean.lowQualitySurfaceMaterial = surfaceMaterial; ocean.surfaceMaterial = surfaceMaterial; } if (RemoveOcean.Value) { // Destroy the ocean PQS (this could be bad - destroying the secondary fades...) cbt.planetFade.secondaryRenderers.Remove(ocean.gameObject); cbt.secondaryFades = null; ocean.transform.parent = null; Object.Destroy(ocean); // No more ocean :( Body.celestialBody.ocean = false; Body.pqsVersion.mapOcean = false; } } // Selectively remove PQS Mods if (RemovePqsMods != null && RemovePqsMods.Value.LongCount() > 0) { // We need a List with Types to remove List <Type> mods = new List <Type>(); Dictionary <String, Type> modsPerName = new Dictionary <String, Type>(); foreach (String mod in RemovePqsMods.Value) { // If the definition has a name specified, grab that String mType = mod; String mName = ""; if (mType.EndsWith("]")) { String[] split = mType.Split('['); mType = split[0]; mName = split[1].Remove(split[1].Length - 1); } // Get the mods matching the String String modName = mType; if (!mod.Contains("PQS")) { modName = "PQSMod_" + mod; } if (mName == "") { //mods.Add(Type.GetType(modName + ", Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")); Type t = Parser.ModTypes.Find(m => m.Name == modName); if (t != null) { mods.Add(t); } } else { //modsPerName.Add(name, Type.GetType(modName + ", Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")); Type t = Parser.ModTypes.Find(m => m.Name == modName); if (t != null) { modsPerName.Add(mName, t); } } } Utility.RemoveModsOfType(mods, Body.pqsVersion); foreach (KeyValuePair <String, Type> kvP in modsPerName) { Int32 index = 0; String modName = kvP.Key; if (modName.Contains(';')) { String[] split = modName.Split(';'); modName = split[0]; Int32.TryParse(split[1], out index); } PQSMod[] allMods = Body.pqsVersion.GetComponentsInChildren(kvP.Value, true) .OfType <PQSMod>().Where(m => m.name == modName).ToArray(); if (allMods.Length <= 0) { continue; } if (allMods[index] is PQSCity) { PQSCity city = (PQSCity)allMods[index]; if (city.lod != null) { foreach (PQSCity.LODRange range in city.lod) { if (range.objects != null) { foreach (GameObject o in range.objects) { Object.DestroyImmediate(o); } } if (range.renderers == null) { continue; } { foreach (GameObject o in range.renderers) { Object.DestroyImmediate(o); } } } } } if (allMods[index] is PQSCity2) { PQSCity2 city = (PQSCity2)allMods[index]; if (city.objects != null) { foreach (PQSCity2.LodObject range in city.objects) { if (range.objects == null) { continue; } foreach (GameObject o in range.objects) { Object.DestroyImmediate(o); } } } } // If no mod is left, delete the game object too GameObject gameObject = allMods[index].gameObject; Object.DestroyImmediate(allMods[index]); PQSMod[] allRemainingMods = gameObject.GetComponentsInChildren <PQSMod>(true); if (allRemainingMods.Length == 0) { Object.DestroyImmediate(gameObject); } } } if (RemoveAllMods != null && RemoveAllMods.Value) { // Remove all mods Utility.RemoveModsOfType(null, Body.pqsVersion); } } // Should we remove the progress tree if (RemoveProgressTree.Value) { Body.celestialBody.progressTree = null; } // Figure out what kind of body we are Boolean isStar = Body.scaledVersion.GetComponentsInChildren <SunShaderController>(true).Length > 0; // remove coronas if (isStar && RemoveCoronas) { foreach (SunCoronas corona in Body.scaledVersion.GetComponentsInChildren <SunCoronas>(true)) { // RnD hard refs Coronas, so we need to disable them corona.GetComponent <Renderer>().enabled = false; } } // Event Events.OnTemplateLoaderPostApply.Fire(this, node); }
public static void UpdateAFG(CelestialBody body, AtmosphereFromGround afg) { afg.outerRadius = (float)body.Radius * 1.025f; afg.innerRadius = afg.outerRadius * 0.975f; afg.KrESun = afg.Kr * afg.ESun; afg.KmESun = afg.Km * afg.ESun; afg.Kr4PI = afg.Kr * 4f * (float)Math.PI; afg.Km4PI = afg.Km * 4f * (float)Math.PI; afg.g2 = afg.g * afg.g; afg.outerRadius2 = afg.outerRadius * afg.outerRadius; afg.innerRadius2 = afg.innerRadius * afg.innerRadius; afg.scale = 1f / (afg.outerRadius - afg.innerRadius); afg.scaleDepth = -0.25f; afg.scaleOverScaleDepth = afg.scale / afg.scaleDepth; }
// Post apply event void IParserEventSubscriber.PostApply(ConfigNode node) { // Should we remove the atmosphere if (body.celestialBody.atmosphere && removeAtmosphere.Value) { // Find atmosphere from ground and destroy the game object AtmosphereFromGround atmosphere = body.scaledVersion.GetComponentsInChildren <AtmosphereFromGround>(true)[0]; atmosphere.transform.parent = null; UnityEngine.Object.Destroy(atmosphere.gameObject); // Destroy the light controller MaterialSetDirection light = body.scaledVersion.GetComponentsInChildren <MaterialSetDirection>(true)[0]; UnityEngine.Object.Destroy(light); // No more atmosphere :( body.celestialBody.atmosphere = false; } // If we have a PQS if (body.pqsVersion != null) { Logger.Active.Log("[Kopernicus]: Configuration.Template: Using Template \"" + body.celestialBody.bodyName + "\""); // Should we remove the ocean? if (body.celestialBody.ocean && removeOcean.Value) { // Find atmosphere the ocean PQS PQS ocean = body.pqsVersion.GetComponentsInChildren <PQS>(true).Where(pqs => pqs != body.pqsVersion).First(); PQSMod_CelestialBodyTransform cbt = body.pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).First(); // Destroy the ocean PQS (this could be bad - destroying the secondary fades...) cbt.planetFade.secondaryRenderers.Remove(ocean.gameObject); cbt.secondaryFades = null; ocean.transform.parent = null; UnityEngine.Object.Destroy(ocean); // No more ocean :( body.celestialBody.ocean = false; body.pqsVersion.mapOcean = false; } // Selectively remove PQS Mods if (removePQSMods != null && removePQSMods.Value.LongCount() > 0) { // We need a List with Types to remove List <Type> mods = new List <Type>(); Dictionary <String, Type> modsPerName = new Dictionary <String, Type>(); foreach (String mod in removePQSMods.Value) { // If the definition has a name specified, grab that String mType = mod; String name = ""; if (mType.EndsWith("]")) { String[] split = mType.Split('['); mType = split[0]; name = split[1].Remove(split[1].Length - 1); } // Get the mods matching the String String modName = mType; if (!mod.Contains("PQS")) { modName = "PQSMod_" + mod; } if (name == "") { //mods.Add(Type.GetType(modName + ", Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")); Type t = Parser.ModTypes.Find(m => m.Name == modName); if (t != null) { mods.Add(t); } } else { //modsPerName.Add(name, Type.GetType(modName + ", Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")); Type t = Parser.ModTypes.Find(m => m.Name == modName); if (t != null) { modsPerName.Add(name, t); } } } Utility.RemoveModsOfType(mods, body.pqsVersion); foreach (KeyValuePair <String, Type> kvP in modsPerName) { Int32 index = 0; String name = kvP.Key; if (name.Contains(';')) { String[] split = name.Split(';'); name = split[0]; Int32.TryParse(split[1], out index); } PQSMod[] allMods = body.pqsVersion.GetComponentsInChildren(kvP.Value, true).Select(m => m as PQSMod).Where(m => m.name == name).ToArray(); if (allMods.Length > 0) { if (allMods[index] is PQSCity) { PQSCity city = allMods[index] as PQSCity; if (city.lod != null) { foreach (PQSCity.LODRange range in city.lod) { if (range.objects != null) { foreach (GameObject o in range.objects) { UnityEngine.Object.DestroyImmediate(o); } } if (range.renderers != null) { foreach (GameObject o in range.renderers) { UnityEngine.Object.DestroyImmediate(o); } } } } } if (allMods[index] is PQSCity2) { PQSCity2 city = allMods[index] as PQSCity2; if (city.objects != null) { foreach (PQSCity2.LodObject range in city.objects) { if (range.objects != null) { foreach (GameObject o in range.objects) { UnityEngine.Object.DestroyImmediate(o); } } } } } // If no mod is left, delete the game object too GameObject gameObject = allMods[index].gameObject; UnityEngine.Object.DestroyImmediate(allMods[index]); PQSMod[] allRemainingMods = gameObject.GetComponentsInChildren <PQSMod>(true); if (allRemainingMods.Length == 0) { UnityEngine.Object.DestroyImmediate(gameObject); } } } } if (removeAllMods != null && removeAllMods.Value) { // Remove all mods Utility.RemoveModsOfType(null, body.pqsVersion); } } // Should we remove the progress tree if (removeProgressTree.Value) { body.celestialBody.progressTree = null; } // Figure out what kind of body we are if (body.scaledVersion.GetComponentsInChildren <SunShaderController>(true).Length > 0) { type = BodyType.Star; } else if (body.celestialBody.atmosphere) { type = BodyType.Atmospheric; } else { type = BodyType.Vacuum; } // remove coronas if (type == BodyType.Star && removeCoronas) { foreach (SunCoronas corona in body.scaledVersion.GetComponentsInChildren <SunCoronas>(true)) { corona.GetComponent <Renderer>().enabled = false; // RnD hard refs Coronas, so we need to disable them } } // Event Events.OnTemplateLoaderPostApply.Fire(this, node); }
public static void UpdateAFG(CelestialBody body, AtmosphereFromGround afg, ConfigNode modNode = null) { if(modNode != null) { float ftmp; // the default afg.outerRadius = (float)body.Radius * 1.025f * ScaledSpace.InverseScaleFactor; if (modNode.TryGetValue("outerRadius", ref afg.outerRadius)) { afg.outerRadius *= ScaledSpace.InverseScaleFactor; } else if (modNode.HasValue("outerRadiusAtmo")) { afg.outerRadius = ((float)body.Radius + body.maxAtmosphereAltitude) * ScaledSpace.InverseScaleFactor; } else if (modNode.TryGetValue("outerRadiusMult", ref afg.outerRadius)) { afg.outerRadius *= (float)body.Radius * ScaledSpace.InverseScaleFactor; } // the default afg.innerRadius = afg.outerRadius * 0.975f; if (modNode.TryGetValue("innerRadius", ref afg.innerRadius)) { afg.innerRadius *= ScaledSpace.InverseScaleFactor; } else if (modNode.TryGetValue("innerRadiusMult", ref afg.innerRadius)) { afg.innerRadius *= afg.outerRadius; } modNode.TryGetValue("doScale", ref afg.doScale); if (modNode.HasValue("transformScale")) { if (float.TryParse(modNode.GetValue("transformScale"), out ftmp) && afg.transform != null) afg.transform.localScale = new Vector3(ftmp, ftmp, ftmp); } else if (modNode.HasValue("transformAtmo")) { afg.transform.localScale = Vector3.one * ((float)(body.Radius + body.maxAtmosphereAltitude) / (float)body.Radius); } if (modNode.HasValue("invWaveLength")) { //will be recomputed by SQUAD anyway so no point. // so instead, compute waveLength from it try { Vector4 col = KSPUtil.ParseVector4(modNode.GetValue("invWaveLength")); afg.invWaveLength = new Color(col.x, col.y, col.z, col.w); afg.waveLength = new Color((float)Math.Pow(1/col.x, 0.25), (float)Math.Pow(1/col.y, 0.25), (float)Math.Pow(1/col.z, 0.25), 1f); } catch(Exception e) { print("*RSS* Error parsing as color4: original text: " + modNode.GetValue("invWaveLength") + " --- exception " + e.Message); } } if (modNode.HasValue("waveLength")) { try { Vector4 col = KSPUtil.ParseVector4(modNode.GetValue("waveLength")); afg.waveLength = new Color(col.x, col.y, col.z, col.w); } catch(Exception e) { print("*RSS* Error parsing as color4: original text: " + modNode.GetValue("waveLength") + " --- exception " + e.Message); } } modNode.TryGetValue("Kr", ref afg.Kr); modNode.TryGetValue("Km", ref afg.Km); modNode.TryGetValue("ESun", ref afg.ESun); modNode.TryGetValue("g", ref afg.g); modNode.TryGetValue("samples", ref afg.samples); } else { // the defaults afg.outerRadius = (float)body.Radius * 1.025f * ScaledSpace.InverseScaleFactor; afg.innerRadius = afg.outerRadius * 0.975f; } afg.KrESun = afg.Kr * afg.ESun; afg.KmESun = afg.Km * afg.ESun; afg.Kr4PI = afg.Kr * 4f * (float)Math.PI; afg.Km4PI = afg.Km * 4f * (float)Math.PI; afg.g2 = afg.g * afg.g; afg.outerRadius2 = afg.outerRadius * afg.outerRadius; afg.innerRadius2 = afg.innerRadius * afg.innerRadius; afg.scale = 1f / (afg.outerRadius - afg.innerRadius); afg.scaleDepth = -0.25f; afg.scaleOverScaleDepth = afg.scale / afg.scaleDepth; try { MethodInfo setMaterial = afg.GetType().GetMethod("SetMaterial", BindingFlags.NonPublic | BindingFlags.Instance); setMaterial.Invoke(afg, new object[] { true }); } catch (Exception e) { print("*RSS* *ERROR* setting AtmosphereFromGround " + afg.name + " for body " + body.name + ": " + e); } }