/// <summary> /// If a part dies, rebuild the sphere /// </summary> void onPartDie(Part part) { // If there's no part or vessel, abort if (part == null || part.vessel == null) return; // Get the CelestialBody CelestialBody body = part.vessel.mainBody; // Get the Vessel Vessel vessel = part.vessel; // Create the Deformation Deformation deformation = new Deformation { position = Utility.LLAtoECEF(vessel.latitude, vessel.longitude, vessel.terrainAltitude, body.Radius), vPos = vessel.vesselTransform.position, altitude = vessel.terrainAltitude + body.Radius, body = body, surfaceSpeed = vessel.srfSpeed, mass = part.mass + part.GetResourceMass(), srfAngle = Vector3d.Angle(Vector3d.up, vessel.vesselTransform.forward) }; deformations.Enqueue(deformation); }
// Load the saved Deformations public override void OnLoad(ConfigNode node) { // Loop through all child-nodes foreach (ConfigNode bodyNode in node.nodes) { // Get the CelestialBody CelestialBody body = PSystemManager.Instance.localBodies.Find(b => b.transform.name == bodyNode.name); // Get the Deformation controller and clear it PQSMod_TerrainDeformation pqsDeformation = body.pqsController.GetComponentInChildren<PQSMod_TerrainDeformation>(); pqsDeformation.deformations.Clear(); // Build the Deformations foreach (ConfigNode deformationNode in bodyNode.nodes) { Deformation deformation = new Deformation(); deformation.altitude = Double.Parse(deformationNode.GetValue("altitude")); deformation.position = ConfigNode.ParseVector3D(deformationNode.GetValue("position")); deformation.vPos = ConfigNode.ParseVector3D(deformationNode.GetValue("vPos")); deformation.mass = Double.Parse(deformationNode.GetValue("mass")); deformation.srfAngle = Double.Parse(deformationNode.GetValue("srfAngle")); deformation.surfaceSpeed = Double.Parse(deformationNode.GetValue("surfaceSpeed")); deformation.body = body; pqsDeformation.deformations.Add(deformation); } } }