internal void Apply(CelestialBody celestialBody, Transform scaledCelestialTransform, float radius) { Remove(); this.celestialBody = celestialBody; this.scaledCelestialTransform = scaledCelestialTransform; SimpleCube hp = new SimpleCube(2000, ref AtmosphereMaterial, AtmosphereShader); AtmosphereMesh = hp.GameObject; atmosphereMaterial.Scale = 500f / (float)celestialBody.Radius; this.radius = radius; if (celestialBody.ocean) { atmosphereMaterial.OceanRadius = (float)celestialBody.Radius; } else { atmosphereMaterial.OceanRadius = 0; } atmosphereMaterial.SphereRadius = (float)celestialBody.Radius; Scaled = false; }
internal void Apply(string body, TerrainMaterial terrainMaterial, OceanMaterial oceanMaterial) { celestialBody = Tools.GetCelestialBody(body); PQS pqs = null; if (celestialBody != null && celestialBody.pqsController != null) { pqs = celestialBody.pqsController; } else { pqs = PQSManagerClass.GetPQS(body); } Transform transform = Tools.GetScaledTransform(body); if (pqs != null) { this.sphere = pqs; this.transform.parent = pqs.transform; this.requirements = PQS.ModiferRequirements.Default; this.modEnabled = true; this.order += 10; this.transform.localPosition = Vector3.zero; this.transform.localRotation = Quaternion.identity; this.transform.localScale = Vector3.one; //Scaled space Renderer r = (Renderer)transform.GetComponent(typeof(Renderer)); if (r != null) { terrainMaterial.SaveTextures(r.material); originalPlanetShader = r.material.shader; TerrainManager.Log("planet shader: " + r.material.shader); r.sharedMaterial.shader = TerrainManager.PlanetShader; terrainMaterial.ApplyMaterialProperties(r.sharedMaterial); } terrainMaterial.SaveTextures(pqs.surfaceMaterial); originalTerrainShader = pqs.surfaceMaterial.shader; TerrainManager.Log("Terrain Shader Name: " + originalTerrainShader.name); String[] keywords = pqs.surfaceMaterial.shaderKeywords; pqs.surfaceMaterial.shader = TerrainManager.TerrainShader; /* foreach (String keyword in keywords) { pqs.surfaceMaterial.EnableKeyword(keyword); } */ terrainMaterial.ApplyMaterialProperties(pqs.surfaceMaterial); if (oceanMaterial != null && pqs.ChildSpheres.Length > 0) { PQS ocean = pqs.ChildSpheres[0]; OceanSurfaceMaterial = ocean.surfaceMaterial; pqs.surfaceMaterial.EnableKeyword("OCEAN_ON"); r.sharedMaterial.EnableKeyword("OCEAN_ON"); keywords = OceanSurfaceMaterial.shaderKeywords; originalOceanShader = OceanSurfaceMaterial.shader; TerrainManager.Log("Ocean Shader Name: " + originalOceanShader.name); OceanSurfaceMaterial.shader = TerrainManager.OceanShader; /* foreach (String keyword in keywords) { OceanSurfaceMaterial.EnableKeyword(keyword); } */ terrainMaterial.ApplyMaterialProperties(OceanSurfaceMaterial); oceanMaterial.ApplyMaterialProperties(OceanSurfaceMaterial); PQSLandControl landControl = (PQSLandControl)pqs.transform.GetComponentInChildren(typeof(PQSLandControl)); if (landControl != null) { PQSLandControl.LandClass[] landClasses = landControl.landClasses; if (landClasses != null) { PQSLandControl.LandClass lcBeach = landClasses.FirstOrDefault(lc => lc.landClassName == "BaseBeach"); PQSLandControl.LandClass lcOcean = landClasses.FirstOrDefault(lc => lc.landClassName == "Ocean Bottom"); if (lcBeach != null || lcOcean != null) { lcOcean.color = lcBeach.color; } } /* PQS ocean = sphere.ChildSpheres[0]; GameObject go = new GameObject(); FakeOceanPQS fakeOcean = go.AddComponent<FakeOceanPQS>(); fakeOcean.Apply(ocean); */ } SimpleCube hp = new SimpleCube(2000, ref OceanBackingMaterial, TerrainManager.OceanBackingShader); OceanBacking = hp.GameObject; OceanBacking.transform.parent = FlightCamera.fetch.transform; OceanBacking.transform.localPosition = Vector3.zero; OceanBacking.transform.localScale = Vector3.one; OceanBacking.layer = (int)Tools.Layer.Local; OceanBackingMaterial.SetFloat("_OceanRadius", (float)celestialBody.Radius); terrainMaterial.ApplyMaterialProperties(OceanBackingMaterial); } else { pqs.surfaceMaterial.DisableKeyword("OCEAN_ON"); r.sharedMaterial.DisableKeyword("OCEAN_ON"); } PQSMod_CelestialBodyTransform cbt = (PQSMod_CelestialBodyTransform)pqs.transform.GetComponentInChildren(typeof(PQSMod_CelestialBodyTransform)); if (cbt != null) { pqs.surfaceMaterial.SetFloat("_MainTexHandoverDist", (float)(1f / cbt.deactivateAltitude)); if (oceanMaterial != null && pqs.ChildSpheres.Length > 0) { PQS ocean = pqs.ChildSpheres[0]; OceanSurfaceMaterial.SetFloat("_MainTexHandoverDist", (float)(1f / cbt.deactivateAltitude)); } pqs.surfaceMaterial.SetFloat("_OceanRadius", (float)celestialBody.Radius); } } this.OnSetup(); pqs.EnableSphere(); }