/** * Constructor for pre-existing PQS * * @param pqsVersion Existing PQS to augment **/ public PQSLoader(PQS pqsVersion) { this.pqsVersion = pqsVersion; // Get the required PQS information transform = pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform> (true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); lightDirection = pqsVersion.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); uvs = pqsVersion.GetComponentsInChildren <PQSMod_UVPlanetRelativePosition>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); collider = pqsVersion.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); // Create physics material editor physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial); }
// Constructor for pre-existing PQS public PQSLoader(PQS pqsVersion) { this.pqsVersion = pqsVersion; // Get the required PQS information transform = pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform> (true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); lightDirection = pqsVersion.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); uvs = pqsVersion.GetComponentsInChildren <PQSMod_UVPlanetRelativePosition>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); collider = pqsVersion.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault(); // Create physics material editor physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial); // Clone the surface material of the PQS if (PQSMainOptimised.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainOptimisedLoader(pqsVersion.surfaceMaterial); if (((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity < 2) { ((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f; } } else if (PQSMainShader.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainShaderLoader(pqsVersion.surfaceMaterial); if (((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity < 2) { ((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f; } } else if (PQSProjectionAerialQuadRelative.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(pqsVersion.surfaceMaterial); if (((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity < 2) { ((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f; } } else if (PQSProjectionSurfaceQuad.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionSurfaceQuadLoader(pqsVersion.surfaceMaterial); } surfaceMaterial = pqsVersion.surfaceMaterial; surfaceMaterial.name = Guid.NewGuid().ToString(); // Clone the fallback material of the PQS fallbackMaterial = new PQSProjectionFallbackLoader(pqsVersion.fallbackMaterial); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid().ToString(); }
/** * Constructor for new PQS **/ public PQSLoader() { // Create a new PQS GameObject root = new GameObject(); root.transform.parent = Utility.Deactivator; this.pqsVersion = root.AddComponent <PQS> (); // TODO - Copy internal settings from a different body // Create the required mods for the pqs GameObject required = new GameObject("_Required"); required.transform.parent = pqsVersion.transform; // Create the celestial body transform transform = required.AddComponent <PQSMod_CelestialBodyTransform> (); transform.requirements = PQS.ModiferRequirements.Default; transform.modEnabled = true; transform.order = 10; // TODO - Many things to set up for transform // Create the material direction setter lightDirection = required.AddComponent <PQSMod_MaterialSetDirection> (); lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the pqs quad UV controller uvs = required.AddComponent <PQSMod_UVPlanetRelativePosition> (); uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = int.MaxValue; // Create the pqs quad collider collider = required.AddComponent <PQSMod_QuadMeshColliders> (); collider.physicsMaterial = new PhysicMaterial(); collider.maxLevelOffset = 0; collider.requirements = PQS.ModiferRequirements.Default; collider.modEnabled = true; collider.order = 100; // Create physics material editor physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial); }
// Constructor for pre-existing PQS public PQSLoader(PQS pqsVersion) { this.pqsVersion = pqsVersion; // Get the required PQS information transform = pqsVersion.GetComponentsInChildren<PQSMod_CelestialBodyTransform> (true).FirstOrDefault (mod => mod.transform.parent == pqsVersion.transform); lightDirection = pqsVersion.GetComponentsInChildren<PQSMod_MaterialSetDirection> (true).FirstOrDefault (mod => mod.transform.parent == pqsVersion.transform); uvs = pqsVersion.GetComponentsInChildren<PQSMod_UVPlanetRelativePosition> (true).FirstOrDefault (mod => mod.transform.parent == pqsVersion.transform); collider = pqsVersion.GetComponentsInChildren<PQSMod_QuadMeshColliders> (true).FirstOrDefault (mod => mod.transform.parent == pqsVersion.transform); // Create physics material editor physicsMaterial = new PhysicsMaterialParser (collider.physicsMaterial); // Clone the surface material of the PQS if (PQSMainOptimised.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainOptimisedLoader(pqsVersion.surfaceMaterial); if (((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity < 2) ((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f; } else if (PQSMainShader.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainShaderLoader(pqsVersion.surfaceMaterial); if (((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity < 2) ((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f; } else if (PQSProjectionAerialQuadRelative.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(pqsVersion.surfaceMaterial); if (((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity < 2) ((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f; } else if (PQSProjectionSurfaceQuad.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionSurfaceQuadLoader(pqsVersion.surfaceMaterial); } surfaceMaterial = pqsVersion.surfaceMaterial; surfaceMaterial.name = Guid.NewGuid ().ToString (); // Clone the fallback material of the PQS fallbackMaterial = new PQSProjectionFallbackLoader (pqsVersion.fallbackMaterial); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid ().ToString (); }
/** * Constructor for new PQS **/ public PQSLoader() { if (generatedBody.pqsVersion != null) { // Save the PQSVersion pqsVersion = generatedBody.pqsVersion; // Get the required PQS information transform = pqsVersion.GetComponentsInChildren<PQSMod_CelestialBodyTransform>(true).FirstOrDefault(Mod => Mod.transform.parent == pqsVersion.transform); lightDirection = pqsVersion.GetComponentsInChildren<PQSMod_MaterialSetDirection>(true).FirstOrDefault(Mod => Mod.transform.parent == pqsVersion.transform); uvs = pqsVersion.GetComponentsInChildren<PQSMod_UVPlanetRelativePosition>(true).FirstOrDefault(Mod => Mod.transform.parent == pqsVersion.transform); collider = pqsVersion.GetComponentsInChildren<PQSMod_QuadMeshColliders>(true).FirstOrDefault(Mod => Mod.transform.parent == pqsVersion.transform); // Create physics material editor physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial); // Clone the surface material of the PQS if (PQSMainOptimised.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainOptimisedLoader(pqsVersion.surfaceMaterial); if (((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity < 2) ((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06; } else if (PQSMainShader.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainShaderLoader(pqsVersion.surfaceMaterial); if (((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity < 2) ((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06; } else if (PQSProjectionAerialQuadRelative.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(pqsVersion.surfaceMaterial); if (((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity < 2) ((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06; } else if (PQSProjectionSurfaceQuad.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionSurfaceQuadLoader(pqsVersion.surfaceMaterial); } surfaceMaterial = pqsVersion.surfaceMaterial; surfaceMaterial.name = Guid.NewGuid().ToString(); // Clone the fallback material of the PQS fallbackMaterial = new PQSProjectionFallbackLoader(pqsVersion.fallbackMaterial); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid().ToString(); return; } // Create a new PQS GameObject controllerRoot = new GameObject (); controllerRoot.transform.parent = Utility.Deactivator; pqsVersion = controllerRoot.AddComponent<PQS> (); // I am at this time unable to determine some of the magic parameters which cause the PQS to work... PSystemBody Laythe = Utility.FindBody (PSystemManager.Instance.systemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(Laythe.pqsVersion, pqsVersion); pqsVersion.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial; // Create the fallback material (always the same shader) fallbackMaterial = new PQSProjectionFallbackLoader (); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid ().ToString (); // Create the celestial body transform GameObject mod = new GameObject("_CelestialBody"); mod.transform.parent = controllerRoot.transform; transform = mod.AddComponent<PQSMod_CelestialBodyTransform>(); transform.sphere = pqsVersion; transform.forceActivate = false; transform.deactivateAltitude = 115000; transform.forceRebuildOnTargetChange = false; transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade(); transform.planetFade.fadeFloatName = "_PlanetOpacity"; transform.planetFade.fadeStart = 100000.0f; transform.planetFade.fadeEnd = 110000.0f; transform.planetFade.valueStart = 0.0f; transform.planetFade.valueEnd = 1.0f; transform.planetFade.secondaryRenderers = new List<GameObject>(); transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; transform.requirements = PQS.ModiferRequirements.Default; transform.modEnabled = true; transform.order = 10; // Create the material direction mod = new GameObject("_Material_SunLight"); mod.transform.parent = controllerRoot.gameObject.transform; lightDirection = mod.AddComponent<PQSMod_MaterialSetDirection>(); lightDirection.sphere = pqsVersion; lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the UV planet relative position mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = controllerRoot.transform; uvs = mod.AddComponent<PQSMod_UVPlanetRelativePosition>(); uvs.sphere = pqsVersion; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Crete the quad mesh colliders mod = new GameObject("QuadMeshColliders"); mod.transform.parent = controllerRoot.gameObject.transform; collider = mod.AddComponent<PQSMod_QuadMeshColliders>(); collider.sphere = pqsVersion; collider.maxLevelOffset = 0; collider.physicsMaterial = new PhysicMaterial(); collider.physicsMaterial.name = "Ground"; collider.physicsMaterial.dynamicFriction = 0.6f; collider.physicsMaterial.staticFriction = 0.8f; collider.physicsMaterial.bounciness = 0.0f; collider.physicsMaterial.frictionCombine = PhysicMaterialCombine.Maximum; collider.physicsMaterial.bounceCombine = PhysicMaterialCombine.Average; collider.requirements = PQS.ModiferRequirements.Default; collider.modEnabled = true; collider.order = 100; // Create physics material editor physicsMaterial = new PhysicsMaterialParser (collider.physicsMaterial); // Assing the new PQS generatedBody.pqsVersion = pqsVersion; }
public PQSLoader(CelestialBody body) { // Is this a spawned body? if (body.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } if (body.pqsController != null) { // Save the PQSVersion Value = body.pqsController; // Get the required PQS information _transform = Value.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true) .FirstOrDefault(mod => mod.transform.parent == Value.transform); _collider = Value.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true) .FirstOrDefault(mod => mod.transform.parent == Value.transform); // Clone the surface material of the PQS if (MaterialType == SurfaceMaterialType.AtmosphericOptimized) { SurfaceMaterial = new PQSMainOptimisedLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.AtmosphericMain) { SurfaceMaterial = new PQSMainShaderLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.AtmosphericBasic) { SurfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.Vacuum) { SurfaceMaterial = new PQSProjectionSurfaceQuadLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.AtmosphericExtra) { SurfaceMaterial = new PQSMainExtrasLoader(SurfaceMaterial); } SurfaceMaterial.name = Guid.NewGuid().ToString(); // Clone the fallback material of the PQS FallbackMaterial = new PQSProjectionFallbackLoader(FallbackMaterial) { name = Guid.NewGuid().ToString() }; } else { // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = body.transform; Value = controllerRoot.AddComponent <PQS>(); // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work... // And I (Thomas) am at this time just too lazy to do it differently... PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(laythe.pqsVersion, Value); Value.surfaceMaterial = laythe.pqsVersion.surfaceMaterial; // Create the fallback material (always the same shader) FallbackMaterial = new PQSProjectionFallbackLoader(); Value.fallbackMaterial = FallbackMaterial; FallbackMaterial.name = Guid.NewGuid().ToString(); // Create the celestial body transform GameObject mod = new GameObject("_CelestialBody"); mod.transform.parent = controllerRoot.transform; _transform = mod.AddComponent <PQSMod_CelestialBodyTransform>(); _transform.sphere = Value; _transform.forceActivate = false; _transform.deactivateAltitude = 115000; _transform.forceRebuildOnTargetChange = false; _transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade { fadeFloatName = "_PlanetOpacity", fadeStart = 100000.0f, fadeEnd = 110000.0f, valueStart = 0.0f, valueEnd = 1.0f, secondaryRenderers = new List <GameObject>() }; _transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; _transform.requirements = PQS.ModiferRequirements.Default; _transform.modEnabled = true; _transform.order = 10; // Create the material direction // ReSharper disable Unity.InefficientPropertyAccess mod = new GameObject("_Material_SunLight"); mod.transform.parent = controllerRoot.gameObject.transform; PQSMod_MaterialSetDirection lightDirection = mod.AddComponent <PQSMod_MaterialSetDirection>(); lightDirection.sphere = Value; lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the UV planet relative position mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = controllerRoot.transform; PQSMod_UVPlanetRelativePosition uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>(); uvs.sphere = Value; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Crete the quad mesh colliders mod = new GameObject("QuadMeshColliders"); mod.transform.parent = controllerRoot.gameObject.transform; _collider = mod.AddComponent <PQSMod_QuadMeshColliders>(); _collider.sphere = Value; _collider.maxLevelOffset = 0; _collider.requirements = PQS.ModiferRequirements.Default; _collider.modEnabled = true; _collider.order = 100; // ReSharper restore Unity.InefficientPropertyAccess } // Assigning the new PQS body.pqsController = Value; Transform transform = body.transform; body.pqsController.name = transform.name; body.pqsController.transform.name = transform.name; body.pqsController.gameObject.name = transform.name; body.pqsController.radius = body.Radius; // Add an OnDemand Handler if (Value.GetComponentsInChildren <PQSMod_OnDemandHandler>(true).Length == 0) { OnDemandStorage.AddHandler(Value); } // Load existing mods foreach (PQSMod mod in Value.GetComponentsInChildren <PQSMod>(true).Where(m => m.sphere == Value)) { Type modType = mod.GetType(); Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType); foreach (Type loaderType in Parser.ModTypes) { if (!modLoaderType.IsAssignableFrom(loaderType)) { continue; } // We found our loader type IModLoader loader = (IModLoader)Activator.CreateInstance(loaderType); loader.Create(mod, Value); Mods.Add(loader); } } }
public 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); }
/** * Constructor for new PQS **/ public PQSLoader () { // Create a new PQS GameObject controllerRoot = new GameObject (); controllerRoot.transform.parent = Utility.Deactivator; this.pqsVersion = controllerRoot.AddComponent<PQS> (); // I am at this time unable to determine some of the magic parameters which cause the PQS to work... PSystemBody Laythe = Utility.FindBody (PSystemManager.Instance.systemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(Laythe.pqsVersion, pqsVersion); pqsVersion.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial; // These parameters magically make the PQS work for some reason. Need to decipher... /*pqsVersion.maxFrameTime = 0.075f; pqsVersion.subdivisionThreshold = 1; pqsVersion.collapseSeaLevelValue = 2; pqsVersion.collapseAltitudeValue = 16; pqsVersion.collapseAltitudeMax = 10000000; pqsVersion.visRadSeaLevelValue = 5; pqsVersion.visRadAltitudeValue = 1.79999995231628; pqsVersion.visRadAltitudeMax = 10000;*/ // Create the fallback material (always the same shader) fallbackMaterial = new PQSProjectionFallbackLoader (); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid ().ToString (); // Create the celestial body transform GameObject mod = new GameObject("_CelestialBody"); mod.transform.parent = controllerRoot.transform; transform = mod.AddComponent<PQSMod_CelestialBodyTransform>(); transform.sphere = pqsVersion; transform.forceActivate = false; transform.deactivateAltitude = 115000; transform.forceRebuildOnTargetChange = false; transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade(); transform.planetFade.fadeFloatName = "_PlanetOpacity"; transform.planetFade.fadeStart = 100000.0f; transform.planetFade.fadeEnd = 110000.0f; transform.planetFade.valueStart = 0.0f; transform.planetFade.valueEnd = 1.0f; transform.planetFade.secondaryRenderers = new List<GameObject>(); transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; transform.requirements = PQS.ModiferRequirements.Default; transform.modEnabled = true; transform.order = 10; // Create the material direction mod = new GameObject("_Material_SunLight"); mod.transform.parent = controllerRoot.gameObject.transform; lightDirection = mod.AddComponent<PQSMod_MaterialSetDirection>(); lightDirection.sphere = pqsVersion; lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the UV planet relative position mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = controllerRoot.transform; uvs = mod.AddComponent<PQSMod_UVPlanetRelativePosition>(); uvs.sphere = pqsVersion; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Crete the quad mesh colliders mod = new GameObject("QuadMeshColliders"); mod.transform.parent = controllerRoot.gameObject.transform; collider = mod.AddComponent<PQSMod_QuadMeshColliders>(); collider.sphere = pqsVersion; collider.maxLevelOffset = 0; collider.physicsMaterial = new PhysicMaterial(); collider.physicsMaterial.name = "Ground"; collider.physicsMaterial.dynamicFriction = 0.6f; collider.physicsMaterial.staticFriction = 0.8f; collider.physicsMaterial.bounciness = 0.0f; collider.physicsMaterial.frictionDirection2 = Vector3.zero; collider.physicsMaterial.dynamicFriction2 = 0.0f; collider.physicsMaterial.staticFriction2 = 0.0f; collider.physicsMaterial.frictionCombine = PhysicMaterialCombine.Maximum; collider.physicsMaterial.bounceCombine = PhysicMaterialCombine.Average; collider.requirements = PQS.ModiferRequirements.Default; collider.modEnabled = true; collider.order = 100; // Create physics material editor physicsMaterial = new PhysicsMaterialParser (collider.physicsMaterial); }
public PQSLoader(CelestialBody body) { // Is this a spawned body? if (body?.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } if (body.pqsController != null) { // Save the PQSVersion Value = body.pqsController; // Get the required PQS information _transform = Value.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true) .FirstOrDefault(Mod => Mod.transform.parent == Value.transform); _collider = Value.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true) .FirstOrDefault(Mod => Mod.transform.parent == Value.transform); // Clone the surface material of the PQS if (PQSMainOptimised.UsesSameShader(surfaceMaterial)) { PQSMainOptimisedLoader loader = new PQSMainOptimisedLoader(surfaceMaterial); loader.globalDensity = loader.globalDensity < 2 ? (Single)(-8E-06) : loader.globalDensity; surfaceMaterial = loader; } else if (PQSMainShader.UsesSameShader(surfaceMaterial)) { PQSMainShaderLoader loader = new PQSMainShaderLoader(surfaceMaterial); loader.globalDensity = loader.globalDensity < 2 ? (Single)(-8E-06) : loader.globalDensity; surfaceMaterial = loader; } else if (PQSProjectionAerialQuadRelative.UsesSameShader(surfaceMaterial)) { PQSProjectionAerialQuadRelativeLoader loader = new PQSProjectionAerialQuadRelativeLoader(surfaceMaterial); loader.globalDensity = loader.globalDensity < 2 ? (Single)(-8E-06) : loader.globalDensity; surfaceMaterial = loader; } else if (PQSProjectionSurfaceQuad.UsesSameShader(surfaceMaterial)) { surfaceMaterial = new PQSProjectionSurfaceQuadLoader(surfaceMaterial); } surfaceMaterial.name = Guid.NewGuid().ToString(); // Clone the fallback material of the PQS fallbackMaterial = new PQSProjectionFallbackLoader(fallbackMaterial); fallbackMaterial.name = Guid.NewGuid().ToString(); } else { // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = body.transform; Value = controllerRoot.AddComponent <PQS>(); // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work... // And I (Thomas) am at this time just too lazy to do it differently... PSystemBody Laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(Laythe.pqsVersion, Value); Value.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial; // Create the fallback material (always the same shader) fallbackMaterial = new PQSProjectionFallbackLoader(); Value.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid().ToString(); // Create the celestial body transform GameObject mod = new GameObject("_CelestialBody"); mod.transform.parent = controllerRoot.transform; _transform = mod.AddComponent <PQSMod_CelestialBodyTransform>(); _transform.sphere = Value; _transform.forceActivate = false; _transform.deactivateAltitude = 115000; _transform.forceRebuildOnTargetChange = false; _transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade(); _transform.planetFade.fadeFloatName = "_PlanetOpacity"; _transform.planetFade.fadeStart = 100000.0f; _transform.planetFade.fadeEnd = 110000.0f; _transform.planetFade.valueStart = 0.0f; _transform.planetFade.valueEnd = 1.0f; _transform.planetFade.secondaryRenderers = new List <GameObject>(); _transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; _transform.requirements = PQS.ModiferRequirements.Default; _transform.modEnabled = true; _transform.order = 10; // Create the material direction mod = new GameObject("_Material_SunLight"); mod.transform.parent = controllerRoot.gameObject.transform; PQSMod_MaterialSetDirection lightDirection = mod.AddComponent <PQSMod_MaterialSetDirection>(); lightDirection.sphere = Value; lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the UV planet relative position mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = controllerRoot.transform; PQSMod_UVPlanetRelativePosition uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>(); uvs.sphere = Value; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Crete the quad mesh colliders mod = new GameObject("QuadMeshColliders"); mod.transform.parent = controllerRoot.gameObject.transform; _collider = mod.AddComponent <PQSMod_QuadMeshColliders>(); _collider.sphere = Value; _collider.maxLevelOffset = 0; _collider.requirements = PQS.ModiferRequirements.Default; _collider.modEnabled = true; _collider.order = 100; } // Assing the new PQS body.pqsController = Value; body.pqsController.name = body.transform.name; body.pqsController.transform.name = body.transform.name; body.pqsController.gameObject.name = body.transform.name; body.pqsController.radius = body.Radius; // Add an OnDemand Handler if (Value.GetComponentsInChildren <PQSMod_OnDemandHandler>(true).Length == 0) { OnDemandStorage.AddHandler(Value); } // Load existing mods foreach (PQSMod mod in Value.GetComponentsInChildren <PQSMod>(true) .Where(m => m.sphere == Value)) { Type modType = mod.GetType(); foreach (Type loaderType in Parser.ModTypes) { if (loaderType.BaseType == null) { continue; } if (loaderType.BaseType.Namespace != "Kopernicus.Configuration.ModLoader") { continue; } if (!loaderType.BaseType.Name.StartsWith("ModLoader")) { continue; } if (loaderType.BaseType.GetGenericArguments()[0] != modType) { continue; } // We found our loader type IModLoader loader = (IModLoader)Activator.CreateInstance(loaderType); loader.Create(mod, Value); mods.Add(loader); } } }
public PQSLoader(CelestialBody body) { // Is this a spawned body? if (body.scaledBody == null || Injector.IsInPrefab) { throw new InvalidOperationException("The body must be already spawned by the PSystemManager."); } if (body.pqsController != null) { // Save the PQSVersion Value = body.pqsController; // Get the required PQS information _transform = Utility.GetMod <PQSMod_CelestialBodyTransform>(Value); _collider = Utility.GetMod <PQSMod_QuadMeshColliders>(Value); } else { // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = body.transform; Value = controllerRoot.AddComponent <PQS>(); PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(laythe.pqsVersion, Value); // Create the fallback material (always the same shader) FallbackMaterial = new PQSProjectionFallbackLoader(); // Create the celestial body transform _transform = Utility.AddMod <PQSMod_CelestialBodyTransform>(Value, 10); _transform.forceActivate = false; _transform.deactivateAltitude = 115000; _transform.forceRebuildOnTargetChange = false; _transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade { fadeFloatName = "_PlanetOpacity", fadeStart = 100000.0f, fadeEnd = 110000.0f, valueStart = 0.0f, valueEnd = 1.0f, secondaryRenderers = new List <GameObject>() }; _transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; // Crete the quad mesh colliders _collider = Utility.AddMod <PQSMod_QuadMeshColliders>(Value, 100); _collider.maxLevelOffset = 0; // Create the material direction Utility.AddMod <PQSMod_MaterialSetDirection>(Value, 100).valueName = "_sunLightDirection"; // Create the UV planet relative position Utility.AddMod <PQSMod_UVPlanetRelativePosition>(Value, 999999); } // Assigning the new PQS body.pqsController = Value; Transform transform = body.transform; body.pqsController.name = transform.name; body.pqsController.transform.name = transform.name; body.pqsController.gameObject.name = transform.name; body.pqsController.radius = body.Radius; // Add an OnDemand Handler if (!Utility.HasMod <PQSMod_OnDemandHandler>(Value)) { Utility.AddMod <PQSMod_OnDemandHandler>(Value, 0); } // Add fixes for LandControl and TextureAtlas if (!Utility.HasMod <PQSLandControlFixer>(Value)) { Utility.AddMod <PQSLandControlFixer>(Value, 0); } #if (KSP_VERSION_1_9_1 || KSP_VERSION_1_10_1 || KSP_VERSION_1_11_1) if (!Utility.HasMod <PQSMod_TextureAtlasFixer>(Value)) { Utility.AddMod <PQSMod_TextureAtlasFixer>(Value, 0); } #endif // Add the PQSROCControl mod for surface anomalies if (!Utility.HasMod <PQSROCControl>(Value)) { PQSROCControl roc = Utility.AddMod <PQSROCControl>(Value, 999999); roc.rocs = new List <LandClassROC>(); roc.currentCBName = Value.name; } else { PQSROCControl roc = Utility.GetMod <PQSROCControl>(Value); roc.currentCBName = Value.name; } // Load existing mods PQSMod[] mods = Utility.GetMods <PQSMod>(Value); for (Int32 i = 0; i < mods.Length; i++) { Type modType = mods[i].GetType(); Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType); for (Int32 j = 0; j < Parser.ModTypes.Count; j++) { if (!modLoaderType.IsAssignableFrom(Parser.ModTypes[j])) { continue; } IModLoader loader = (IModLoader)Activator.CreateInstance(Parser.ModTypes[j]); loader.Create(mods[i], Value); Mods.Add(loader); } } }
/// <summary> /// Creates a new PQS Loader from the Injector context. /// </summary> public PQSLoader() { // Is this the parser context? if (!Injector.IsInPrefab) { throw new InvalidOperationException("Must be executed in Injector context."); } if (generatedBody.pqsVersion != null) { // Save the PQSVersion Value = generatedBody.pqsVersion; // Get the required PQS information _transform = Utility.GetMod <PQSMod_CelestialBodyTransform>(Value); _collider = Utility.GetMod <PQSMod_QuadMeshColliders>(Value); } else { // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = generatedBody.celestialBody.transform; Value = controllerRoot.AddComponent <PQS>(); // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work... // And I (Thomas) am at this time just too lazy to do it differently... PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(laythe.pqsVersion, Value); // Create the fallback material (always the same shader) FallbackMaterial = new PQSProjectionFallbackLoader(); // Create the celestial body transform _transform = Utility.AddMod <PQSMod_CelestialBodyTransform>(Value, 10); _transform.forceActivate = false; _transform.deactivateAltitude = 115000; _transform.forceRebuildOnTargetChange = false; _transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade { fadeFloatName = "_PlanetOpacity", fadeStart = 100000.0f, fadeEnd = 110000.0f, valueStart = 0.0f, valueEnd = 1.0f, secondaryRenderers = new List <GameObject>() }; _transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; // Crete the quad mesh colliders _collider = Utility.AddMod <PQSMod_QuadMeshColliders>(Value, 100); _collider.maxLevelOffset = 0; // Create the material direction Utility.AddMod <PQSMod_MaterialSetDirection>(Value, 100).valueName = "_sunLightDirection"; // Create the UV planet relative position Utility.AddMod <PQSMod_UVPlanetRelativePosition>(Value, 999999); } // Assigning the new PQS generatedBody.pqsVersion = Value; generatedBody.pqsVersion.name = generatedBody.name; generatedBody.pqsVersion.transform.name = generatedBody.name; generatedBody.pqsVersion.gameObject.name = generatedBody.name; generatedBody.pqsVersion.radius = generatedBody.celestialBody.Radius; generatedBody.celestialBody.pqsController = generatedBody.pqsVersion; // Add an OnDemand Handler if (!Utility.HasMod <PQSMod_OnDemandHandler>(Value)) { Utility.AddMod <PQSMod_OnDemandHandler>(Value, 0); } // Add fixes for LandControl and TextureAtlas if (!Utility.HasMod <PQSLandControlFixer>(Value)) { Utility.AddMod <PQSLandControlFixer>(Value, 0); } #if (KSP_VERSION_1_9_1 || KSP_VERSION_1_10_1 || KSP_VERSION_1_11_1) if (!Utility.HasMod <PQSMod_TextureAtlasFixer>(Value)) { Utility.AddMod <PQSMod_TextureAtlasFixer>(Value, 0); } #endif // hacky hack if (generatedBody.celestialBody.isHomeWorld && Value.gameObject.GetChild("KSC") == null) { PSystemBody kerbinTemplate = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Kerbin"); GameObject scTree = kerbinTemplate.pqsVersion.gameObject.GetChild("KSC"); GameObject newScTree = Object.Instantiate(scTree, Value.transform, true); newScTree.transform.localPosition = scTree.transform.localPosition; newScTree.transform.localScale = scTree.transform.localScale; newScTree.transform.localRotation = scTree.transform.localRotation; newScTree.name = "KSC"; } // Add the PQSROCControl mod for surface anomalies if (!Utility.HasMod <PQSROCControl>(Value)) { PQSROCControl roc = Utility.AddMod <PQSROCControl>(Value, 999999); roc.rocs = new List <LandClassROC>(); roc.currentCBName = Value.name; } else { PQSROCControl roc = Utility.GetMod <PQSROCControl>(Value); roc.currentCBName = Value.name; } // Load existing mods PQSMod[] mods = Utility.GetMods <PQSMod>(Value); for (Int32 i = 0; i < mods.Length; i++) { Type modType = mods[i].GetType(); Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType); for (Int32 j = 0; j < Parser.ModTypes.Count; j++) { if (!modLoaderType.IsAssignableFrom(Parser.ModTypes[j])) { continue; } IModLoader loader = (IModLoader)Activator.CreateInstance(Parser.ModTypes[j]); loader.Create(mods[i], Value); Mods.Add(loader); } } }
/// <summary> /// Renders the Window /// </summary> protected override void Render(Int32 id) { // Call base base.Render(id); // Check for PQS if (Current.pqsController == null) { Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_ADD, () => { // Create a new PQS GameObject controllerRoot = new GameObject(Current.name); controllerRoot.transform.parent = Current.transform; PQS pqsVersion = controllerRoot.AddComponent <PQS>(); // I am at this time unable to determine some of the magic parameters which cause the PQS to work... (Or just lazy but who cares :P) PSystemBody Laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(Laythe.pqsVersion, pqsVersion); pqsVersion.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial; // Create the fallback material (always the same shader) pqsVersion.fallbackMaterial = new PQSProjectionFallbackLoader(); pqsVersion.fallbackMaterial.name = Guid.NewGuid().ToString(); // Create the celestial body transform GameObject mod = new GameObject("_CelestialBody"); mod.transform.parent = controllerRoot.transform; PQSMod_CelestialBodyTransform transform = mod.AddComponent <PQSMod_CelestialBodyTransform>(); transform.sphere = pqsVersion; transform.forceActivate = false; transform.deactivateAltitude = 115000; transform.forceRebuildOnTargetChange = false; transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade(); transform.planetFade.fadeFloatName = "_PlanetOpacity"; transform.planetFade.fadeStart = 100000.0f; transform.planetFade.fadeEnd = 110000.0f; transform.planetFade.valueStart = 0.0f; transform.planetFade.valueEnd = 1.0f; transform.planetFade.secondaryRenderers = new List <GameObject>(); transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; transform.requirements = PQS.ModiferRequirements.Default; transform.modEnabled = true; transform.order = 10; // Create the material direction mod = new GameObject("_Material_SunLight"); mod.transform.parent = controllerRoot.gameObject.transform; PQSMod_MaterialSetDirection lightDirection = mod.AddComponent <PQSMod_MaterialSetDirection>(); lightDirection.sphere = pqsVersion; lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the UV planet relative position mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = controllerRoot.transform; PQSMod_UVPlanetRelativePosition uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>(); uvs.sphere = pqsVersion; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Crete the quad mesh colliders mod = new GameObject("QuadMeshColliders"); mod.transform.parent = controllerRoot.gameObject.transform; PQSMod_QuadMeshColliders collider = mod.AddComponent <PQSMod_QuadMeshColliders>(); collider.sphere = pqsVersion; collider.maxLevelOffset = 0; collider.physicsMaterial = new PhysicMaterial(); collider.physicsMaterial.name = "Ground"; collider.physicsMaterial.dynamicFriction = 0.6f; collider.physicsMaterial.staticFriction = 0.8f; collider.physicsMaterial.bounciness = 0.0f; collider.physicsMaterial.frictionCombine = PhysicMaterialCombine.Maximum; collider.physicsMaterial.bounceCombine = PhysicMaterialCombine.Average; collider.requirements = PQS.ModiferRequirements.Default; collider.modEnabled = true; collider.order = 100; // Assing the new PQS Current.pqsController = pqsVersion; pqsVersion.transform.position = Current.transform.position; pqsVersion.transform.localPosition = Vector3.zero; // Set mode _mode = Modes.List; }, new Rect(20, index * distance + 10, 350, 20)); return; } // Mode List if (_mode == Modes.List) { // Get the PQS-Spheres and their mods IEnumerable <PQS> pqsList = Current.GetComponentsInChildren <PQS>(true); IEnumerable <PQSMod> pqsModList = Current.GetComponentsInChildren <PQSMod>(true); // Scroll BeginScrollView(250, (pqsList.Count() + pqsModList.Count()) * distance + distance * 4, 20); // Index index = 0; // Render foreach (PQS pqs in pqsList) { Button(pqs.ToString(), () => { _mode = Modes.PQS; _sphere = pqs; }, new Rect(20, index * distance + 10, 350, 20)); } foreach (PQSMod mod in pqsModList) { Button(mod.ToString(), () => { _mode = Modes.PQSMod; _sphere = mod.sphere; _mod = mod; }, new Rect(20, index * distance + 10, 350, 20)); } index++; Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_ADD_MOD, () => _mode = Modes.AddMod, new Rect(20, index * distance + 10, 350, 20)); if (Current.pqsController.ChildSpheres.All(s => s.name != Current.pqsController.name + "Ocean")) { Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_ADD_OCEAN, () => { // Generate the PQS object GameObject gameObject = new GameObject("Ocean"); gameObject.layer = Constants.GameLayers.LocalSpace; PQS ocean = gameObject.AddComponent <PQS>(); // Setup materials PSystemBody Body = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe"); foreach (PQS oc in Body.pqsVersion.GetComponentsInChildren <PQS>(true)) { if (oc.name != "LaytheOcean") { continue; } // Copying Laythes Ocean-properties Utility.CopyObjectFields <PQS>(oc, ocean); } // Load our new Material into the PQS ocean.surfaceMaterial = new PQSOceanSurfaceQuadLoader(ocean.surfaceMaterial); ocean.surfaceMaterial.name = Guid.NewGuid().ToString(); // Load fallback material into the PQS ocean.fallbackMaterial = new PQSOceanSurfaceQuadFallbackLoader(ocean.fallbackMaterial); ocean.fallbackMaterial.name = Guid.NewGuid().ToString(); // Create the UV planet relative position GameObject mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = gameObject.transform; PQSMod_UVPlanetRelativePosition uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>(); uvs.sphere = ocean; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Create the AerialPerspective Material AerialPerspectiveMaterial mat = new AerialPerspectiveMaterial(); mat.Create(ocean); // Create the OceanFX OceanFX oceanFX = new OceanFX(); oceanFX.Create(ocean); // Apply the Ocean ocean.transform.parent = Current.pqsController.transform; // Add the ocean PQS to the secondary renders of the CelestialBody Transform PQSMod_CelestialBodyTransform transform = Current.pqsController.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).FirstOrDefault(mod_ => mod_.transform.parent == Current.pqsController.transform); transform.planetFade.secondaryRenderers.Add(ocean.gameObject); typeof(PQS).GetField("_childSpheres", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(Current.pqsController, null); // Names! ocean.name = Current.pqsController.name + "Ocean"; ocean.gameObject.name = Current.pqsController.name + "Ocean"; ocean.transform.name = Current.pqsController.name + "Ocean"; // Set up the ocean PQS ocean.parentSphere = Current.pqsController; ocean.transform.position = Current.pqsController.transform.position; ocean.transform.localPosition = Vector3.zero; ocean.radius = Current.Radius; }, new Rect(20, index * distance + 10, 350, 20)); } else { Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_REMOVE_OCEAN, () => { // Find atmosphere the ocean PQS PQS ocean = Current.pqsController.GetComponentsInChildren <PQS>(true).First(pqs => pqs != Current.pqsController); PQSMod_CelestialBodyTransform cbt = Current.pqsController.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).First(); // Destroy the ocean PQS (this could be bad - destroying the secondary fades...) cbt.planetFade.secondaryRenderers.Remove(ocean.gameObject); typeof(PQS).GetField("_childSpheres", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(Current.pqsController, null); cbt.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; ocean.transform.parent = null; UnityEngine.Object.Destroy(ocean); }, new Rect(20, index * distance + 10, 350, 20)); } // End Scroll EndScrollView(); } // Mode PQS if (_mode == Modes.PQS) { // Scroll BeginScrollView(250, Utils.GetScrollSize <PQS>() + Utils.GetScrollSize <HazardousOcean>() + distance * 1, 20); // Index index = 0; // Render the PQS RenderObject(_sphere); // If it is an ocean, create an Hazardous Ocean button if (PQSOceanSurfaceQuad.UsesSameShader(_sphere.surfaceMaterial)) { Label("hazardousOcean"); index--; if (_sphere.GetComponent <HazardousOcean>() != null) { Button(Localization.LOC_KITTOPIATECH_EDIT, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Curve, _sphere.GetComponent <HazardousOcean>().heatCurve ?? new FloatCurve(), c => _sphere.GetComponent <HazardousOcean>().heatCurve = c); UIController.Instance.EnableWindow(KittopiaWindows.Curve); }, new Rect(200, index * distance + 10, 75, 20)); index--; Button(Localization.LOC_KITTOPIATECH_REMOVE, () => UnityEngine.Object.DestroyImmediate(_sphere.GetComponent <HazardousOcean>()), new Rect(285, index * distance + 10, 75, 20)); } else { Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_ADD_HAZOCEAN, () => _sphere.gameObject.AddComponent <HazardousOcean>(), new Rect(200, index * distance + 10, 170, 20)); } } index++; // Rebuild Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_REBUILD, () => _sphere.RebuildSphere()); // End Scroll EndScrollView(); } // Mode PQSMod if (_mode == Modes.PQSMod) { // Scroll BeginScrollView(250, Utils.GetScrollSize(_mod.GetType()) + distance * 5, 20); // Index index = 0; // Render the PQS RenderObject(_mod); index++; // Rebuild Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_REBUILD, () => _sphere.RebuildSphere()); // Remove Button(Localization.LOC_KITTOPIATECH_PQSEDITOR_REMOVE_MOD, () => { _mod.sphere = null; UnityEngine.Object.Destroy(_mod); _mod = null; // Hack _sphere.SetupExternalRender(); _sphere.CloseExternalRender(); _mode = Modes.List; }); // End Scroll EndScrollView(); } // Mode AddPQSMod if (_mode == Modes.AddMod) { // Get all PQSMod types List <Type> types = Parser.ModTypes.Where(t => t.IsSubclassOf(typeof(PQSMod))).ToList(); // Begin Scroll BeginScrollView(250, types.Count * distance + 10, 20); // Index index = 0; // Render the possible types foreach (Type t in types) { Button(t.FullName, () => { // Hack^6 GameObject pqsModObject = new GameObject(t.Name); pqsModObject.transform.parent = Current.pqsController.transform; PQSMod mod = pqsModObject.AddComponent(t) as PQSMod; mod.sphere = Current.pqsController; if (t == typeof(PQSMod_VoronoiCraters)) { PQS mun = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Mun").pqsVersion; PQSMod_VoronoiCraters craters = mun.GetComponentsInChildren <PQSMod_VoronoiCraters>()[0]; PQSMod_VoronoiCraters nc = pqsModObject.GetComponentsInChildren <PQSMod_VoronoiCraters>()[0]; nc.craterColourRamp = craters.craterColourRamp; nc.craterCurve = craters.craterCurve; nc.jitterCurve = craters.jitterCurve; } else if (t == typeof(PQSMod_VertexPlanet)) { PQSMod_VertexPlanet vp = mod as PQSMod_VertexPlanet; vp.landClasses = new [] { new PQSMod_VertexPlanet.LandClass("Class", 0, 1, Color.black, Color.white, 0) }; vp.continental = new PQSMod_VertexPlanet.SimplexWrapper(0, 0, 0, 0); vp.continentalRuggedness = new PQSMod_VertexPlanet.SimplexWrapper(0, 0, 0, 0); vp.continentalSharpness = new PQSMod_VertexPlanet.NoiseModWrapper(0, 0, 0, 0); vp.continentalSharpnessMap = new PQSMod_VertexPlanet.SimplexWrapper(0, 0, 0, 0); vp.terrainType = new PQSMod_VertexPlanet.SimplexWrapper(0, 0, 0, 0); } else if (t == typeof(PQSMod_HeightColorMap)) { (mod as PQSMod_HeightColorMap).landClasses = new [] { new PQSMod_HeightColorMap.LandClass("Class", 0, 1, Color.black, Color.white, 0) }; } else if (t == typeof(PQSMod_HeightColorMap2)) { (mod as PQSMod_HeightColorMap2).landClasses = new[] { new PQSMod_HeightColorMap2.LandClass("Class", 0, 1, Color.black, Color.white, 0) }; } else if (t == typeof(PQSMod_HeightColorMapNoise)) { (mod as PQSMod_HeightColorMapNoise).landClasses = new[] { new PQSMod_HeightColorMapNoise.LandClass("Class", 0, 1, Color.black, Color.white, 0) }; } else if (t == typeof(PQSLandControl)) { PQSLandControl lc = mod as PQSLandControl; lc.altitudeSimplex = new Simplex(); lc.scatters = new PQSLandControl.LandClassScatter[0]; lc.landClasses = new [] { new PQSLandControl.LandClass() { altitudeRange = new PQSLandControl.LerpRange(), coverageSimplex = new Simplex(), longitudeRange = new PQSLandControl.LerpRange(), latitudeDoubleRange = new PQSLandControl.LerpRange(), latitudeRange = new PQSLandControl.LerpRange(), scatter = new PQSLandControl.LandClassScatterAmount[0] } }; lc.latitudeSimplex = new Simplex(); lc.longitudeSimplex = new Simplex(); } // Edit the mod _mod = mod; _sphere = mod.sphere; _mode = Modes.PQSMod; }, new Rect(20, index * distance + 10, 350, 20)); } // End Scroll EndScrollView(); } }
/** * Constructor for new PQS **/ public PQSLoader() { // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = Utility.Deactivator; this.pqsVersion = controllerRoot.AddComponent <PQS> (); // I am at this time unable to determine some of the magic parameters which cause the PQS to work... PSystemBody Laythe = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(Laythe.pqsVersion, pqsVersion); pqsVersion.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial; // These parameters magically make the PQS work for some reason. Need to decipher... /*pqsVersion.maxFrameTime = 0.075f; * pqsVersion.subdivisionThreshold = 1; * pqsVersion.collapseSeaLevelValue = 2; * pqsVersion.collapseAltitudeValue = 16; * pqsVersion.collapseAltitudeMax = 10000000; * pqsVersion.visRadSeaLevelValue = 5; * pqsVersion.visRadAltitudeValue = 1.79999995231628; * pqsVersion.visRadAltitudeMax = 10000;*/ // Create the fallback material (always the same shader) fallbackMaterial = new PQSProjectionFallbackLoader(); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid().ToString(); // Create the celestial body transform GameObject mod = new GameObject("_CelestialBody"); mod.transform.parent = controllerRoot.transform; transform = mod.AddComponent <PQSMod_CelestialBodyTransform>(); transform.sphere = pqsVersion; transform.forceActivate = false; transform.deactivateAltitude = 115000; transform.forceRebuildOnTargetChange = false; transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade(); transform.planetFade.fadeFloatName = "_PlanetOpacity"; transform.planetFade.fadeStart = 100000.0f; transform.planetFade.fadeEnd = 110000.0f; transform.planetFade.valueStart = 0.0f; transform.planetFade.valueEnd = 1.0f; transform.planetFade.secondaryRenderers = new List <GameObject>(); transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; transform.requirements = PQS.ModiferRequirements.Default; transform.modEnabled = true; transform.order = 10; // Create the material direction mod = new GameObject("_Material_SunLight"); mod.transform.parent = controllerRoot.gameObject.transform; lightDirection = mod.AddComponent <PQSMod_MaterialSetDirection>(); lightDirection.sphere = pqsVersion; lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the UV planet relative position mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = controllerRoot.transform; uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>(); uvs.sphere = pqsVersion; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Crete the quad mesh colliders mod = new GameObject("QuadMeshColliders"); mod.transform.parent = controllerRoot.gameObject.transform; collider = mod.AddComponent <PQSMod_QuadMeshColliders>(); collider.sphere = pqsVersion; collider.maxLevelOffset = 0; collider.physicsMaterial = new PhysicMaterial(); collider.physicsMaterial.name = "Ground"; collider.physicsMaterial.dynamicFriction = 0.6f; collider.physicsMaterial.staticFriction = 0.8f; collider.physicsMaterial.bounciness = 0.0f; collider.physicsMaterial.frictionDirection2 = Vector3.zero; collider.physicsMaterial.dynamicFriction2 = 0.0f; collider.physicsMaterial.staticFriction2 = 0.0f; collider.physicsMaterial.frictionCombine = PhysicMaterialCombine.Maximum; collider.physicsMaterial.bounceCombine = PhysicMaterialCombine.Average; collider.requirements = PQS.ModiferRequirements.Default; collider.modEnabled = true; collider.order = 100; // Create physics material editor physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial); }
/** * Constructor for new PQS **/ public PQSLoader() { if (generatedBody.pqsVersion != null) { // Save the PQSVersion pqsVersion = generatedBody.pqsVersion; // Get the required PQS information transform = pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault(); lightDirection = pqsVersion.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault(); uvs = pqsVersion.GetComponentsInChildren <PQSMod_UVPlanetRelativePosition>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault(); collider = pqsVersion.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault(); // Create physics material editor physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial); // Clone the surface material of the PQS if (PQSMainOptimised.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainOptimisedLoader(pqsVersion.surfaceMaterial); if (((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity < 2) { ((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06; } } else if (PQSMainShader.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainShaderLoader(pqsVersion.surfaceMaterial); if (((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity < 2) { ((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06; } } else if (PQSProjectionAerialQuadRelative.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(pqsVersion.surfaceMaterial); if (((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity < 2) { ((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06; } } else if (PQSProjectionSurfaceQuad.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionSurfaceQuadLoader(pqsVersion.surfaceMaterial); } surfaceMaterial = pqsVersion.surfaceMaterial; surfaceMaterial.name = Guid.NewGuid().ToString(); // Clone the fallback material of the PQS fallbackMaterial = new PQSProjectionFallbackLoader(pqsVersion.fallbackMaterial); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid().ToString(); return; } // Create a new PQS GameObject controllerRoot = new GameObject(); controllerRoot.transform.parent = Utility.Deactivator; pqsVersion = controllerRoot.AddComponent <PQS> (); // I am at this time unable to determine some of the magic parameters which cause the PQS to work... PSystemBody Laythe = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Laythe"); Utility.CopyObjectFields(Laythe.pqsVersion, pqsVersion); pqsVersion.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial; // Create the fallback material (always the same shader) fallbackMaterial = new PQSProjectionFallbackLoader(); pqsVersion.fallbackMaterial = fallbackMaterial; fallbackMaterial.name = Guid.NewGuid().ToString(); // Create the celestial body transform GameObject mod = new GameObject("_CelestialBody"); mod.transform.parent = controllerRoot.transform; transform = mod.AddComponent <PQSMod_CelestialBodyTransform>(); transform.sphere = pqsVersion; transform.forceActivate = false; transform.deactivateAltitude = 115000; transform.forceRebuildOnTargetChange = false; transform.planetFade = new PQSMod_CelestialBodyTransform.AltitudeFade(); transform.planetFade.fadeFloatName = "_PlanetOpacity"; transform.planetFade.fadeStart = 100000.0f; transform.planetFade.fadeEnd = 110000.0f; transform.planetFade.valueStart = 0.0f; transform.planetFade.valueEnd = 1.0f; transform.planetFade.secondaryRenderers = new List <GameObject>(); transform.secondaryFades = new PQSMod_CelestialBodyTransform.AltitudeFade[0]; transform.requirements = PQS.ModiferRequirements.Default; transform.modEnabled = true; transform.order = 10; // Create the material direction mod = new GameObject("_Material_SunLight"); mod.transform.parent = controllerRoot.gameObject.transform; lightDirection = mod.AddComponent <PQSMod_MaterialSetDirection>(); lightDirection.sphere = pqsVersion; lightDirection.valueName = "_sunLightDirection"; lightDirection.requirements = PQS.ModiferRequirements.Default; lightDirection.modEnabled = true; lightDirection.order = 100; // Create the UV planet relative position mod = new GameObject("_Material_SurfaceQuads"); mod.transform.parent = controllerRoot.transform; uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>(); uvs.sphere = pqsVersion; uvs.requirements = PQS.ModiferRequirements.Default; uvs.modEnabled = true; uvs.order = 999999; // Crete the quad mesh colliders mod = new GameObject("QuadMeshColliders"); mod.transform.parent = controllerRoot.gameObject.transform; collider = mod.AddComponent <PQSMod_QuadMeshColliders>(); collider.sphere = pqsVersion; collider.maxLevelOffset = 0; collider.physicsMaterial = new PhysicMaterial(); collider.physicsMaterial.name = "Ground"; collider.physicsMaterial.dynamicFriction = 0.6f; collider.physicsMaterial.staticFriction = 0.8f; collider.physicsMaterial.bounciness = 0.0f; collider.physicsMaterial.frictionCombine = PhysicMaterialCombine.Maximum; collider.physicsMaterial.bounceCombine = PhysicMaterialCombine.Average; collider.requirements = PQS.ModiferRequirements.Default; collider.modEnabled = true; collider.order = 100; // Create physics material editor physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial); // Assing the new PQS generatedBody.pqsVersion = pqsVersion; }