public static bool PartIsGreeble(Part p, double crossSectionalArea, double finenessRatio, double area) { bool isGreeble = false; if (p.parent) { Part parent = p.parent; if (parent.Modules.Contains("FARBasicDragModel")) { FARBasicDragModel d = parent.GetComponent <FARBasicDragModel>(); Vector3 parentVector = (p.transform.worldToLocalMatrix * parent.transform.localToWorldMatrix).MultiplyVector(d.localUpVector); double dotProd = Vector3.Dot(parentVector, Vector3.up); if (Math.Abs(dotProd) < 0.3) { if (crossSectionalArea / d.S <= 0.1 && d.S > area * 0.2 * Math.Sqrt(1 - dotProd * dotProd)) { isGreeble = true; } } } else if (parent.Modules.Contains("FARWingAerodynamicModel")) { FARWingAerodynamicModel w = parent.GetComponent <FARWingAerodynamicModel>(); if (w.S * 0.5 > area) { isGreeble = true; } } } return(isGreeble); }
public static bool PartIsGreeble(Part p, double crossSectionalArea, double finenessRatio, double area) { bool isGreeble = false; if (p.parent && p.parent.Modules != null) { Part parent = p.parent; if (parent.Modules.Contains("FARBasicDragModel")) { FARBasicDragModel d = null; foreach (PartModule m in parent.Modules) { if (m is FARBasicDragModel) { d = m as FARBasicDragModel; return(false); } } Transform selfTransform = p.transform; if ((object)selfTransform == null) { selfTransform = p.vessel.vesselTransform; } Transform parentTransform = p.parent.transform; if ((object)parentTransform == null) { parentTransform = p.vessel.vesselTransform; } Vector3d parentVector = (selfTransform.worldToLocalMatrix * parentTransform.localToWorldMatrix).MultiplyVector(d.localUpVector); double dotProd = Vector3d.Dot(parentVector, Vector3d.up); if (Math.Abs(dotProd) < 0.3) { if (crossSectionalArea / d.S <= 0.1 && d.S > area * 0.2 * Math.Sqrt(1 - dotProd * dotProd)) { isGreeble = true; } } } else if (parent.Modules.Contains("FARWingAerodynamicModel") || parent.Modules.Contains("FARControllableSurface")) { FARWingAerodynamicModel w = parent.GetComponent <FARWingAerodynamicModel>(); double comparisonArea = w.b_2 * w.MAC * 0.5; if (comparisonArea > area) { isGreeble = true; } Debug.Log(p.partInfo.title + " is greeble on wing? " + isGreeble + "\n\rPart area: " + area + " wing area comparison: " + comparisonArea); } } return(isGreeble); }
public static bool PartIsGreeble(Part p, double crossSectionalArea, double finenessRatio, double area) { bool isGreeble = false; if (p.parent && p.parent.Modules != null) { Part parent = p.parent; if (parent.Modules.Contains("FARBasicDragModel")) { FARBasicDragModel d = null; foreach (PartModule m in parent.Modules) { if (m is FARBasicDragModel) { d = m as FARBasicDragModel; return(false); } } Transform selfTransform = p.partTransform; if ((object)selfTransform == null) { selfTransform = p.vessel.vesselTransform; } Transform parentTransform = p.parent.partTransform; if ((object)parentTransform == null) { parentTransform = p.vessel.vesselTransform; } Vector3d parentVector = (selfTransform.worldToLocalMatrix * parentTransform.localToWorldMatrix).MultiplyVector(d.localUpVector); double dotProd = Vector3d.Dot(parentVector, Vector3d.up); if (Math.Abs(dotProd) < 0.3) { if (crossSectionalArea / d.S <= 0.1 && d.S > area * 0.2 * Math.Sqrt(1 - dotProd * dotProd)) { isGreeble = true; } } } else if (parent.Modules.Contains("FARWingAerodynamicModel")) { FARWingAerodynamicModel w = parent.GetComponent <FARWingAerodynamicModel>(); if (w.S * 0.5 > area) { isGreeble = true; } } } return(isGreeble); }
private bool FindPartsWithoutFARModel(List <Part> editorShip) { bool returnValue = false; for (int i = 0; i < editorShip.Count; i++) { Part p = editorShip[i]; if (p == null) { continue; } if (p != null && FARAeroUtil.IsNonphysical(p) && p.physicalSignificance != Part.PhysicalSignificance.NONE) { MonoBehaviour.print(p + ": FAR correcting physical significance to fix CoM in editor"); p.physicalSignificance = Part.PhysicalSignificance.NONE; } string title = p.partInfo.title.ToLowerInvariant(); if (p.Modules.Contains("FARBasicDragModel")) { List <PartModule> modulesToRemove = new List <PartModule>(); for (int j = 0; j < p.Modules.Count; j++) { PartModule m = p.Modules[j]; if (!(m is FARBasicDragModel)) { continue; } FARBasicDragModel d = m as FARBasicDragModel; if (d.CdCurve == null || d.ClPotentialCurve == null || d.ClViscousCurve == null || d.CmCurve == null) { modulesToRemove.Add(m); } } if (modulesToRemove.Count > 0) { for (int j = 0; j < modulesToRemove.Count; j++) { PartModule m = modulesToRemove[j]; p.RemoveModule(m); Debug.Log("Removing Incomplete FAR Drag Module"); } if (p.Modules.Contains("FARPayloadFairingModule")) { p.RemoveModule(p.Modules["FARPayloadFairingModule"]); } if (p.Modules.Contains("FARCargoBayModule")) { p.RemoveModule(p.Modules["FARCargoBayModule"]); } if (p.Modules.Contains("FARControlSys")) { p.RemoveModule(p.Modules["FARControlSys"]); } } } if (p is StrutConnector || p is FuelLine || p is ControlSurface || p is Winglet || FARPartClassification.ExemptPartFromGettingDragModel(p, title)) { continue; } FARPartModule q = p.GetComponent <FARPartModule>(); if (q != null && !(q is FARControlSys)) { continue; } bool updatedModules = false; if (FARPartClassification.PartIsCargoBay(p, title)) { if (!p.Modules.Contains("FARCargoBayModule")) { p.AddModule("FARCargoBayModule"); p.Modules["FARCargoBayModule"].OnStart(PartModule.StartState.Editor); FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p); p.Modules["FARBasicDragModel"].OnStart(PartModule.StartState.Editor); updatedModules = true; } } if (!updatedModules) { if (FARPartClassification.PartIsPayloadFairing(p, title)) { if (!p.Modules.Contains("FARPayloadFairingModule")) { p.AddModule("FARPayloadFairingModule"); p.Modules["FARPayloadFairingModule"].OnStart(PartModule.StartState.Editor); FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p); p.Modules["FARBasicDragModel"].OnStart(PartModule.StartState.Editor); updatedModules = true; } } if (!updatedModules && !p.Modules.Contains("FARBasicDragModel")) { FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p); p.Modules["FARBasicDragModel"].OnStart(PartModule.StartState.Editor); updatedModules = true; } } returnValue |= updatedModules; FARPartModule b = p.GetComponent <FARPartModule>(); if (b != null) { b.VesselPartList = editorShip; //This prevents every single part in the ship running this due to VesselPartsList not being initialized } } for (int i = 0; i < editorShip.Count; i++) { Part p = editorShip[i]; FARBasicDragModel d = p.GetComponent <FARBasicDragModel>(); if (d != null) { d.UpdatePropertiesWithShapeChange(); } } return(returnValue); }
private void FindPartsWithoutFARModel(Vessel v) { for (int i = 0; i < v.Parts.Count; i++) { Part p = v.Parts[i]; if (p == null) { continue; } string title = p.partInfo.title.ToLowerInvariant(); if (p.Modules.Contains("FARBasicDragModel")) { List <PartModule> modulesToRemove = new List <PartModule>(); for (int j = 0; j < p.Modules.Count; j++) { PartModule m = p.Modules[j]; if (!(m is FARBasicDragModel)) { continue; } FARBasicDragModel d = m as FARBasicDragModel; if (d.CdCurve == null || d.ClPotentialCurve == null || d.ClViscousCurve == null || d.CmCurve == null) { modulesToRemove.Add(m); } } if (modulesToRemove.Count > 0) { for (int j = 0; j < modulesToRemove.Count; j++) { PartModule m = modulesToRemove[j]; p.RemoveModule(m); Debug.Log("Removing Incomplete FAR Drag Module"); } if (p.Modules.Contains("FARPayloadFairingModule")) { p.RemoveModule(p.Modules["FARPayloadFairingModule"]); } if (p.Modules.Contains("FARCargoBayModule")) { p.RemoveModule(p.Modules["FARCargoBayModule"]); } if (p.Modules.Contains("FARControlSys")) { p.RemoveModule(p.Modules["FARControlSys"]); } } } if (p is StrutConnector || p is FuelLine || p is ControlSurface || p is Winglet || FARPartClassification.ExemptPartFromGettingDragModel(p, title)) { continue; } if (p.Modules.Contains("ModuleCommand") && !p.Modules.Contains("FARControlSys")) { p.AddModule("FARControlSys"); PartModule m = p.Modules["FARControlSys"]; m.OnStart(PartModule.StartState.Flying); //Debug.Log("Added FARControlSys to " + p.partInfo.title); } FARPartModule q = p.GetComponent <FARPartModule>(); if (q != null && !(q is FARControlSys)) { continue; } bool updatedModules = false; if (FARPartClassification.PartIsCargoBay(p, title)) { if (!p.Modules.Contains("FARCargoBayModule")) { p.AddModule("FARCargoBayModule"); PartModule m = p.Modules["FARCargoBayModule"]; m.OnStart(PartModule.StartState.Flying); FARAeroUtil.AddBasicDragModule(p); m = p.Modules["FARBasicDragModel"]; m.OnStart(PartModule.StartState.Flying); updatedModules = true; } } if (!updatedModules) { if (FARPartClassification.PartIsPayloadFairing(p, title)) { if (!p.Modules.Contains("FARPayloadFairingModule")) { p.AddModule("FARPayloadFairingModule"); PartModule m = p.Modules["FARPayloadFairingModule"]; m.OnStart(PartModule.StartState.Flying); FARAeroUtil.AddBasicDragModule(p); m = p.Modules["FARBasicDragModel"]; m.OnStart(PartModule.StartState.Flying); updatedModules = true; } } if (!updatedModules && !p.Modules.Contains("FARBasicDragModel")) { FARAeroUtil.AddBasicDragModule(p); PartModule m = p.Modules["FARBasicDragModel"]; m.OnStart(PartModule.StartState.Flying); updatedModules = true; } } //returnValue |= updatedModules; FARPartModule b = p.GetComponent <FARPartModule>(); if (b != null) { b.VesselPartList = p.vessel.Parts; //This prevents every single part in the ship running this due to VesselPartsList not being initialized } } UpdateFARPartModules(v); }
private void FindShieldedParts() { /*if (HighLogic.LoadedSceneIsEditor/* && FARAeroUtil.EditorAboutToAttach(false) && * !FARAeroUtil.CurEditorParts.Contains(part)) * return;*/ ClearShieldedParts(); UpdateShipPartsList(); CalculateFairingBounds(); Collider[] colliders = this.PartColliders; for (int i = 0; i < VesselPartList.Count; i++) { Part p = VesselPartList[i]; if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p)) { continue; } FARBaseAerodynamics b = null; FARBasicDragModel d = null; FARWingAerodynamicModel w = null; Vector3 relPos = -part.transform.position; w = p.GetComponent <FARWingAerodynamicModel>(); if ((object)w == null) { d = p.GetComponent <FARBasicDragModel>(); } if ((object)w == null && (object)d == null) { continue; } //if (p.GetComponent<FARPayloadFairingModule>() != null) // continue; if (w) { b = w as FARBaseAerodynamics; relPos += w.WingCentroid(); } else { b = d as FARBaseAerodynamics; relPos += p.transform.TransformDirection(d.CenterOfDrag) + p.transform.position; //No attach node shifting with this } relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); Vector3 fairingCenter = fairingBounds.center; fairingCenter *= 0.5f; fairingCenter = this.part.transform.localToWorldMatrix.MultiplyVector(fairingCenter); fairingCenter += this.part.transform.position; if (fairingBounds.Contains(relPos)) { Vector3 vecFromPToPFCenter; Vector3 origin; if (w) { origin = w.WingCentroid(); } else { origin = p.transform.position; } vecFromPToPFCenter = fairingCenter - origin; RaycastHit[] hits = Physics.RaycastAll(origin, vecFromPToPFCenter, vecFromPToPFCenter.magnitude, FARAeroUtil.RaycastMask); bool outsideMesh = false; for (int k = 0; k < hits.Length; k++) { if (colliders.Contains(hits[k].collider)) { outsideMesh = true; break; } } if (outsideMesh) { continue; } FARShieldedParts.Add(p); if (b) { b.ActivateShielding(); //print("Shielded: " + p.partInfo.title); } for (int k = 0; k < p.symmetryCounterparts.Count; k++) { Part q = p.symmetryCounterparts[k]; if (q == null) { continue; } FARShieldedParts.Add(q); b = q.GetComponent <FARBaseAerodynamics>(); if (b) { b.ActivateShielding(); //print("Shielded: " + p.partInfo.title); } } } } partsShielded = FARShieldedParts.Count; }
private void FindShieldedParts() { /*if (HighLogic.LoadedSceneIsEditor/* && FARAeroUtil.EditorAboutToAttach(false) && * !FARAeroUtil.CurEditorParts.Contains(part)) * return;*/ if (minBounds.Count == 0) { CalculateFairingBounds(); } ClearShieldedParts(); UpdateShipPartsList(); Collider[] colliders; try { colliders = part.GetComponentsInChildren <Collider>(); } catch (Exception e) { //Fail silently because it's the only way to avoid issues with pWings //Debug.LogException(e); colliders = new Collider[1] { part.collider }; } for (int i = 0; i < VesselPartList.Count; i++) { Part p = VesselPartList[i]; if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p)) { continue; } FARBaseAerodynamics b = null; FARBasicDragModel d = null; FARWingAerodynamicModel w = null; Vector3 relPos = -part.transform.position; w = p.GetComponent <FARWingAerodynamicModel>(); if ((object)w == null) { d = p.GetComponent <FARBasicDragModel>(); } if ((object)w == null && (object)d == null) { continue; } //if (p.GetComponent<FARPayloadFairingModule>() != null) // continue; if (w) { b = w as FARBaseAerodynamics; relPos += w.WingCentroid(); } else { b = d as FARBaseAerodynamics; relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position; //No attach node shifting with this } relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); for (int j = 0; j < minBounds.Count; j++) { Vector3 minBoundVec, maxBoundVec; minBoundVec = minBounds[j]; maxBoundVec = maxBounds[j]; if (relPos.x < maxBoundVec.x && relPos.y < maxBoundVec.y && relPos.z < maxBoundVec.z && relPos.x > minBoundVec.x && relPos.y > minBoundVec.y && relPos.z > minBoundVec.z) { Vector3 vecFromPToPFCenter; if (d) { vecFromPToPFCenter = p.partTransform.InverseTransformPoint(d.CoDshift); } else if (w) { vecFromPToPFCenter = w.WingCentroid(); } else { vecFromPToPFCenter = p.partTransform.position; } vecFromPToPFCenter = this.part.partTransform.position - vecFromPToPFCenter; RaycastHit[] hits = Physics.RaycastAll(p.partTransform.position, vecFromPToPFCenter, vecFromPToPFCenter.magnitude, FARAeroUtil.RaycastMask); bool outsideMesh = false; for (int k = 0; k < hits.Length; k++) { if (colliders.Contains(hits[k].collider)) { outsideMesh = true; break; } } if (outsideMesh) { break; } FARShieldedParts.Add(p); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } for (int k = 0; k < p.symmetryCounterparts.Count; k++) { Part q = p.symmetryCounterparts[k]; if (q == null) { continue; } FARShieldedParts.Add(q); b = q.GetComponent <FARBaseAerodynamics>(); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } } break; } } } partsShielded = FARShieldedParts.Count; }
public void GetClCdCmSteady(Vector3d CoM, double alpha, double beta, double phi, double alphaDot, double betaDot, double phiDot, double M, double pitch, out double Cl, out double Cd, out double Cm, out double Cy, out double Cn, out double C_roll, bool clear, bool reset_stall = false, int flap_setting = 0, bool spoilersDeployed = false, bool vehicleFueled = true) { Cl = 0; Cd = 0; Cm = 0; Cy = 0; Cn = 0; C_roll = 0; double area = 0; double MAC = 0; double b_2 = 0; alpha *= FARMathUtil.deg2rad; beta *= FARMathUtil.deg2rad; phi *= FARMathUtil.deg2rad; Vector3d forward = Vector3.forward; Vector3d up = Vector3.up; Vector3d right = Vector3.right; if (EditorDriver.editorFacility == EditorFacility.VAB) { forward = Vector3.up; up = -Vector3.forward; } Vector3d AngVel = (phiDot - Math.Sin(alpha) * betaDot) * forward + (Math.Cos(phi) * alphaDot + Math.Cos(alpha) * Math.Sin(phi) * betaDot) * right + (Math.Sin(phi) * alphaDot - Math.Cos(alpha) * Math.Cos(phi) * betaDot) * up; Vector3d velocity = forward * Math.Cos(alpha) * Math.Cos(beta) + right * (Math.Sin(phi) * Math.Sin(alpha) * Math.Cos(beta) - Math.Cos(phi) * Math.Sin(beta)) - up * (Math.Cos(phi) * Math.Sin(alpha) * Math.Cos(beta) - Math.Cos(phi) * Math.Sin(beta)); velocity.Normalize(); Vector3d liftVector = -forward *Math.Sin(alpha) + right * Math.Sin(phi) * Math.Cos(alpha) - up * Math.Cos(phi) * Math.Cos(alpha); Vector3d sideways = Vector3.Cross(velocity, liftVector); for (int i = 0; i < FARAeroUtil.CurEditorWings.Count; i++) { FARWingAerodynamicModel w = FARAeroUtil.CurEditorWings[i]; if (w.isShielded) { continue; } if (clear) { w.EditorClClear(reset_stall); } Vector3d relPos = w.GetAerodynamicCenter() - CoM; Vector3d vel = velocity + Vector3d.Cross(AngVel, relPos); if (w is FARControllableSurface) { (w as FARControllableSurface).SetControlStateEditor(CoM, vel, (float)pitch, 0, 0, flap_setting, spoilersDeployed); } w.ComputeClCdEditor(vel, M); double tmpCl = w.GetCl() * w.S; Cl += tmpCl * -Vector3d.Dot(w.GetLiftDirection(), liftVector); Cy += tmpCl * -Vector3d.Dot(w.GetLiftDirection(), sideways); double tmpCd = w.GetCd() * w.S; Cd += tmpCd; Cm += tmpCl * Vector3d.Dot((relPos), velocity) * -Vector3d.Dot(w.GetLiftDirection(), liftVector) + tmpCd * -Vector3d.Dot((relPos), liftVector); Cn += tmpCd * Vector3d.Dot((relPos), sideways) + tmpCl * Vector3d.Dot((relPos), velocity) * -Vector3d.Dot(w.GetLiftDirection(), sideways); C_roll += tmpCl * Vector3d.Dot((relPos), sideways) * -Vector3d.Dot(w.GetLiftDirection(), liftVector); area += w.S; MAC += w.GetMAC() * w.S; b_2 += w.Getb_2() * w.S; } for (int i = 0; i < FARAeroUtil.CurEditorOtherDrag.Count; i++) { FARBasicDragModel d = FARAeroUtil.CurEditorOtherDrag[i]; if (d.isShielded) { continue; } Vector3d relPos = d.part.transform.position - CoM; Vector3d vel = velocity + Vector3d.Cross(AngVel, relPos); double tmpCd = d.GetDragEditor(vel, M); Cd += tmpCd; double tmpCl = d.GetLiftEditor(); Cl += tmpCl * -Vector3d.Dot(d.GetLiftDirection(), liftVector); Cy += tmpCl * -Vector3d.Dot(d.GetLiftDirection(), sideways); relPos = d.GetCoDWithoutMomentShift() - CoM; Cm += d.GetMomentEditor() + tmpCl * Vector3d.Dot((relPos), velocity) * -Vector3d.Dot(d.GetLiftDirection(), liftVector) + tmpCd * -Vector3d.Dot((relPos), liftVector); Cn += tmpCd * Vector3d.Dot((relPos), sideways) + tmpCl * Vector3d.Dot((relPos), velocity) * -Vector3d.Dot(d.GetLiftDirection(), sideways); C_roll += tmpCl * Vector3d.Dot((relPos), sideways) * -Vector3d.Dot(d.GetLiftDirection(), liftVector); } for (int i = 0; i < FARAeroUtil.CurEditorParts.Count; i++) { Part p = FARAeroUtil.CurEditorParts[i]; if (FARAeroUtil.IsNonphysical(p)) { continue; } Vector3 part_pos = p.transform.TransformPoint(p.CoMOffset) - CoM; double partMass = p.mass; if (vehicleFueled && p.Resources.Count > 0) { partMass += p.GetResourceMass(); } double stock_drag = partMass * p.maximum_drag * FlightGlobals.DragMultiplier * 1000; Cd += stock_drag; Cm += stock_drag * -Vector3d.Dot(part_pos, liftVector); Cn += stock_drag * Vector3d.Dot(part_pos, sideways); } if (area == 0) { area = 1; b_2 = 1; MAC = 1; } double recipArea = 1 / area; MAC *= recipArea; b_2 *= recipArea; Cl *= recipArea; Cd *= recipArea; Cm *= recipArea / MAC; Cy *= recipArea; Cn *= recipArea / b_2; C_roll *= recipArea / b_2; }
private void FindShieldedParts() { if (minBounds == new Vector3()) { CalculateBayBounds(); } ClearShieldedParts(); bayOpen = false; UpdateShipPartsList(); double y_margin = Math.Max(0.12, 0.03 * (maxBounds.y - minBounds.y)); foreach (Part p in VesselPartList) { if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p)) { continue; } FARBaseAerodynamics b = null; FARBasicDragModel d = null; FARWingAerodynamicModel w = null; Vector3 relPos = -part.transform.position; w = p.GetComponent <FARWingAerodynamicModel>(); if ((object)w == null) { d = p.GetComponent <FARBasicDragModel>(); } if ((object)w == null && (object)d == null) { continue; } //if (p.GetComponent<FARPayloadFairingModule>() != null) // continue; if (w) { b = w as FARBaseAerodynamics; relPos += w.WingCentroid(); } else { b = d as FARBaseAerodynamics; relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position; //No attach node shifting with this } relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); if (relPos.x < maxBounds.x && relPos.y < maxBounds.y + y_margin && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y - y_margin && relPos.z > minBounds.z) { if (relPos.y > maxBounds.y || relPos.y < minBounds.y) { // Enforce strict y bounds for parent and stack children if (p == this.part.parent || p.parent == this.part && p.attachMode == AttachModes.STACK) { continue; } } /* if (w) * { * if (w.nonSideAttach <= 0) * { * relPos = p.transform.position - this.part.transform.position; * relPos -= p.transform.right * Mathf.Sign(p.srfAttachNode.originalOrientation.x) * w.b_2; * * relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); * * if (!(relPos.x < maxBounds.x && relPos.y < maxBounds.y && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y && relPos.z > minBounds.z)) * continue; * } * }*/ FARShieldedParts.Add(p); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } foreach (Part q in p.symmetryCounterparts) { if (q == null) { continue; } FARShieldedParts.Add(q); b = q.GetComponent <FARBaseAerodynamics>(); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } } } } if (HighLogic.LoadedSceneIsEditor) { foreach (Vessel v in FlightGlobals.Vessels) { if (v == this.vessel) { continue; } Vector3 relPos = v.transform.position - this.part.transform.position; relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); if (relPos.x < maxBounds.x && relPos.y < maxBounds.y && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y && relPos.z > minBounds.z) { foreach (Part p in v.Parts) { FARBaseAerodynamics b = null; b = p.GetComponent <FARBaseAerodynamics>(); if (b == null) { continue; } FARShieldedParts.Add(p); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } } } } } partsShielded = FARShieldedParts.Count; }
private void FindShieldedParts() { if (minBounds == new Vector3()) { CalculateBayBounds(); } ClearShieldedParts(); bayOpen = false; UpdateShipPartsList(); double y_margin = Math.Max(0.12, 0.03 * (maxBounds.y - minBounds.y)); Collider[] colliders; try { colliders = part.GetComponentsInChildren <Collider>(); } catch (Exception e) { //Fail silently because it's the only way to avoid issues with pWings //Debug.LogException(e); colliders = new Collider[1] { part.collider }; } for (int i = 0; i < VesselPartList.Count; i++) { Part p = VesselPartList[i]; if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p)) { continue; } FARBaseAerodynamics b = null; FARBasicDragModel d = null; FARWingAerodynamicModel w = null; Vector3 relPos = -part.transform.position; w = p.GetComponent <FARWingAerodynamicModel>(); if ((object)w == null) { d = p.GetComponent <FARBasicDragModel>(); } if ((object)w == null && (object)d == null) { continue; } //if (p.GetComponent<FARPayloadFairingModule>() != null) // continue; if (w) { b = w as FARBaseAerodynamics; relPos += w.WingCentroid(); } else { b = d as FARBaseAerodynamics; relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position; //No attach node shifting with this } relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); if (relPos.x < maxBounds.x && relPos.y < maxBounds.y + y_margin && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y - y_margin && relPos.z > minBounds.z) { if (relPos.y > maxBounds.y || relPos.y < minBounds.y) { // Enforce strict y bounds for parent and stack children if (p == this.part.parent || p.parent == this.part && p.attachMode == AttachModes.STACK) { continue; } } Vector3 vecFromPToCargoBayCenter; /*if (d) * vecFromPToCargoBayCenter = p.partTransform.InverseTransformPoint(d.CoDshift); * else if (w) * vecFromPToCargoBayCenter = w.WingCentroid(); * else*/ vecFromPToCargoBayCenter = p.partTransform.position; vecFromPToCargoBayCenter = this.part.partTransform.position - vecFromPToCargoBayCenter; RaycastHit[] hits = Physics.RaycastAll(p.partTransform.position, vecFromPToCargoBayCenter, vecFromPToCargoBayCenter.magnitude, FARAeroUtil.RaycastMask); bool outsideMesh = false; for (int j = 0; j < hits.Length; j++) { if (colliders.Contains(hits[j].collider)) { outsideMesh = true; break; } } if (outsideMesh) { break; } FARShieldedParts.Add(p); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } for (int j = 0; j < p.symmetryCounterparts.Count; j++) { Part q = p.symmetryCounterparts[j]; if (q == null) { continue; } FARShieldedParts.Add(q); b = q.GetComponent <FARBaseAerodynamics>(); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } } } } partsShielded = FARShieldedParts.Count; }
private void FindShieldedParts() { if (minBounds == new Vector3()) { CalculateBayBounds(); } ClearShieldedParts(); bayOpen = false; UpdateShipPartsList(); double y_margin = Math.Max(0.12, 0.03 * (maxBounds.y - minBounds.y)); Collider[] colliders = this.PartColliders; for (int i = 0; i < VesselPartList.Count; i++) { Part p = VesselPartList[i]; if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p)) { continue; } FARBaseAerodynamics b = null; FARBasicDragModel d = null; FARWingAerodynamicModel w = null; Vector3 relPos = -part.transform.position; w = p.GetComponent <FARWingAerodynamicModel>(); if ((object)w == null) { d = p.GetComponent <FARBasicDragModel>(); } if ((object)w == null && (object)d == null) { continue; } //if (p.GetComponent<FARPayloadFairingModule>() != null) // continue; if (w) { b = w as FARBaseAerodynamics; relPos += w.WingCentroid(); } else { b = d as FARBaseAerodynamics; relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position; //No attach node shifting with this } relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); if (relPos.x < maxBounds.x && relPos.y < maxBounds.y + y_margin && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y - y_margin && relPos.z > minBounds.z) { if (relPos.y > maxBounds.y || relPos.y < minBounds.y) { // Enforce strict y bounds for parent and stack children if (p == this.part.parent || p.parent == this.part && p.attachMode == AttachModes.STACK) { continue; } } Vector3 vecFromPToCargoBayCenter; Vector3 origin; if (w) { origin = w.WingCentroid(); } else { origin = p.transform.position; } vecFromPToCargoBayCenter = part.transform.position - origin; if (w) //This accounts for wings that are clipping into the cargo bay. { origin -= vecFromPToCargoBayCenter.normalized * 0.1f; } RaycastHit[] hits = Physics.RaycastAll(origin, vecFromPToCargoBayCenter, vecFromPToCargoBayCenter.magnitude, FARAeroUtil.RaycastMask); bool outsideMesh = false; for (int j = 0; j < hits.Length; j++) { if (colliders.Contains(hits[j].collider)) { outsideMesh = true; break; } } if (outsideMesh) { continue; } FARShieldedParts.Add(p); if (b) { b.ActivateShielding(); //print("Shielded: " + p.partInfo.title); } for (int j = 0; j < p.symmetryCounterparts.Count; j++) { Part q = p.symmetryCounterparts[j]; if (q == null) { continue; } FARShieldedParts.Add(q); b = q.GetComponent <FARBaseAerodynamics>(); if (b) { b.ActivateShielding(); //print("Shielded: " + p.partInfo.title); } } } } partsShielded = FARShieldedParts.Count; }
private void FindShieldedParts() { /*if (HighLogic.LoadedSceneIsEditor/* && FARAeroUtil.EditorAboutToAttach(false) && * !FARAeroUtil.CurEditorParts.Contains(part)) * return;*/ if (minBounds.Count == 0) { CalculateFairingBounds(); } ClearShieldedParts(); UpdateShipPartsList(); foreach (Part p in VesselPartList) { if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p)) { continue; } FARBaseAerodynamics b = null; FARBasicDragModel d = null; FARWingAerodynamicModel w = null; Vector3 relPos = -part.transform.position; w = p.GetComponent <FARWingAerodynamicModel>(); if ((object)w == null) { d = p.GetComponent <FARBasicDragModel>(); } if ((object)w == null && (object)d == null) { continue; } //if (p.GetComponent<FARPayloadFairingModule>() != null) // continue; if (w) { b = w as FARBaseAerodynamics; relPos += w.WingCentroid(); } else { b = d as FARBaseAerodynamics; relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position; //No attach node shifting with this } relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos); for (int i = 0; i < minBounds.Count; i++) { Vector3 minBoundVec, maxBoundVec; minBoundVec = minBounds[i]; maxBoundVec = maxBounds[i]; if (relPos.x < maxBoundVec.x && relPos.y < maxBoundVec.y && relPos.z < maxBoundVec.z && relPos.x > minBoundVec.x && relPos.y > minBoundVec.y && relPos.z > minBoundVec.z) { FARShieldedParts.Add(p); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } foreach (Part q in p.symmetryCounterparts) { if (q == null) { continue; } FARShieldedParts.Add(q); b = q.GetComponent <FARBaseAerodynamics>(); if (b) { b.isShielded = true; //print("Shielded: " + p.partInfo.title); } } break; } } } partsShielded = FARShieldedParts.Count; }