コード例 #1
0
        private void CalculatePartBounds(Part p)
        {
            FARPartModule m = p.GetComponent <FARPartModule>();

            if (m == null)
            {
                return;
            }
            if (p == this.part)
            {
                for (int i = 0; i < m.PartBounds.Length; i++)
                {
                    fairingBounds.Encapsulate(m.PartBounds[i]);
                }
            }
            else
            {
                Matrix4x4 matrix = part.transform.worldToLocalMatrix * p.transform.localToWorldMatrix;
                for (int i = 0; i < m.PartBounds.Length; i++)
                {
                    Bounds bounds = m.PartBounds[i];
                    bounds.SetMinMax(matrix.MultiplyPoint(bounds.min), matrix.MultiplyPoint(bounds.max));
                    fairingBounds.Encapsulate(bounds);
                }
            }
        }
コード例 #2
0
 public void TriggerPartColliderUpdate()
 {
     //Set up part collider list to easy runtime overhead with memory churning
     for (int i = 0; i < part.Modules.Count; i++)
     {
         PartModule m = part.Modules[i];
         if (m is FARPartModule)
         {
             FARPartModule farModule = (m as FARPartModule);
             if (farModule.partColliders != null)
             {
                 this.partColliders = farModule.partColliders;
                 break;
             }
         }
     }
     // For some reason fuelLine throws NRE when trying to get colliders
     if (this.partColliders == null)
     {
         try
         {
             this.partColliders = part.GetPartColliders();
         }
         catch (NullReferenceException)
         {
             FARLogger.Info("NullReferenceException trying to get part colliders from " + part + ", defaulting to no colliders");
             this.partColliders = new Collider[0];
         }
     }
 }
コード例 #3
0
        private bool UnattachedPartRightAgainstNode(Vector3d origToNode, double attachSize, Part attachedPart)
        {
            double mag = (origToNode).magnitude;

            ray.direction = origToNode;

            ray.origin = part.transform.position;

            RaycastHit[] hits = Physics.RaycastAll(ray, (float)(mag + attachSize), FARAeroUtil.RaycastMask);
            foreach (RaycastHit h in hits)
            {
                if (h.collider == part.collider)
                {
                    continue;
                }
                if (h.distance < (mag + attachSize) && h.distance > (mag - attachSize * 0.01))
                {
                    foreach (Part p in VesselPartList)
                    {
                        if (p == null || p == attachedPart)
                        {
                            continue;
                        }

                        FARPartModule m = p.GetComponent <FARPartModule>();
                        if (m == null)
                        {
                            if (p.GetPartColliders().Contains(h.collider))
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            if (m.PartColliders == null)
                            {
                                m.TriggerPartColliderUpdate();
                            }

                            if (m.PartColliders.Contains(h.collider))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
コード例 #4
0
 public void TriggerPartColliderUpdate()
 {
     //Set up part collider list to easy runtime overhead with memory churning
     for (int i = 0; i < part.Modules.Count; i++)
     {
         PartModule m = part.Modules[i];
         if (m is FARPartModule)
         {
             FARPartModule farModule = (m as FARPartModule);
             if (farModule.partColliders != null)
             {
                 this.partColliders = farModule.partColliders;
                 break;
             }
         }
     }
     if (this.partColliders == null)
         this.partColliders = part.GetPartColliders();
 }
コード例 #5
0
        private FARWingAerodynamicModel ExposureHitDetectionAndWingDetection(RaycastHit[] hits, List <Part> vesselPartList, ref double exposure, double exposureDecreasePerHit)
        {
            bool   gotSomething          = false;
            bool   firstHit              = true;
            double wingInteractionFactor = 0;

            FARWingAerodynamicModel wingHit = null;

            RaycastHit[] sortedHits = SortHitsByDistance(hits);
            for (int j = 0; j < sortedHits.Length; j++)
            {
                gotSomething = false;
                RaycastHit h = sortedHits[j];
                if (h.collider != null)
                {
                    for (int k = 0; k < vesselPartList.Count; k++)
                    {
                        Part p = vesselPartList[k];
                        if (p == null || p == parentWingPart)
                        {
                            continue;
                        }

                        FARPartModule farModule = p.GetComponent <FARPartModule>();

                        Collider[] colliders;

                        if (farModule != null)
                        {
                            colliders = farModule.PartColliders;
                            if (colliders == null)
                            {
                                farModule.TriggerPartColliderUpdate();
                                colliders = farModule.PartColliders;
                            }
                        }
                        else
                        {
                            colliders = new Collider[1] {
                                p.collider
                            }
                        };


                        for (int l = 0; l < colliders.Length; l++)
                        {
                            if (h.collider == colliders[l] && h.distance > 0)
                            {
                                if (firstHit)
                                {
                                    exposure -= exposureDecreasePerHit;
                                    firstHit  = false;
                                }

                                FARWingAerodynamicModel hitModule = p.GetComponent <FARWingAerodynamicModel>();
                                if (hitModule != null)
                                {
                                    double tmp = Math.Abs(Vector3.Dot(p.transform.forward, parentWingPart.partTransform.forward));
                                    if (tmp > wingInteractionFactor + 0.01)
                                    {
                                        wingInteractionFactor = tmp;
                                        wingHit = hitModule;
                                    }
                                }
                                gotSomething = true;
                                break;
                            }
                        }
                        if (gotSomething)
                        {
                            break;
                        }
                    }
                }
            }
            return(wingHit);
        }
コード例 #6
0
        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);
        }
コード例 #8
0
        private void FindPartsWithoutFARModel(Vessel v)
        {
            List <FARPartModule> FARPartModules = new List <FARPartModule>();

            bool returnValue = false;

            foreach (Part p in v.Parts)
            {
                if (p == null)
                {
                    continue;
                }

                string title = p.partInfo.title.ToLowerInvariant();

                if (p is StrutConnector || p is FuelLine || p is ControlSurface || p is Winglet || FARPartClassification.ExemptPartFromGettingDragModel(p, title))
                {
                    continue;
                }

                if (p.Modules.Contains("FARPartModule"))
                {
                    foreach (PartModule m in p.Modules)
                    {
                        if (m is FARPartModule)
                        {
                            FARPartModules.Add(m as FARPartModule);
                        }
                    }
                    continue;
                }

                if (p.Modules.Contains("ModuleCommand") && !p.Modules.Contains("FARControlSys"))
                {
                    p.AddModule("FARControlSys");
                    PartModule m = p.Modules["FARControlSys"];
                    m.OnStart(PartModule.StartState.Flying);

                    FARPartModules.Add(m as FARPartModule);
                }

                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);
                        FARPartModules.Add(m as FARPartModule);

                        FARAeroUtil.AddBasicDragModule(p);
                        m = p.Modules["FARBasicDragModel"];
                        m.OnStart(PartModule.StartState.Flying);
                        FARPartModules.Add(m as FARPartModule);

                        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);
                            FARPartModules.Add(m as FARPartModule);

                            FARAeroUtil.AddBasicDragModule(p);
                            m = p.Modules["FARBasicDragModel"];
                            m.OnStart(PartModule.StartState.Flying);
                            FARPartModules.Add(m as FARPartModule);
                            updatedModules = true;
                        }
                    }

                    if (!updatedModules && !p.Modules.Contains("FARBasicDragModel"))
                    {
                        FARAeroUtil.AddBasicDragModule(p);
                        PartModule m = p.Modules["FARBasicDragModel"];
                        m.OnStart(PartModule.StartState.Flying);
                        FARPartModules.Add(m as FARPartModule);

                        updatedModules = true;
                    }
                }

                returnValue |= updatedModules;

                FARPartModule b = p.GetComponent <FARPartModule>();
                if (b != null)
                {
                    b.VesselPartList = v.Parts;             //This prevents every single part in the ship running this due to VesselPartsList not being initialized
                }
            }

            /*if (vesselFARPartModules.ContainsKey(v))
             * {
             *  List<FARPartModule> Modules = vesselFARPartModules[v];
             *  FARPartModules = FARPartModules.Union(Modules).ToList();
             *  vesselFARPartModules[v] = FARPartModules;
             * }
             * else
             *  vesselFARPartModules.Add(v, FARPartModules);*/
            //return returnValue;
        }
コード例 #9
0
        private bool FindPartsWithoutFARModel(List <Part> editorShip)
        {
            bool returnValue = false;

            foreach (Part p in editorShip)
            {
                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 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.AddBasicDragModule(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.AddBasicDragModule(p);
                            p.Modules["FARBasicDragModel"].OnStart(PartModule.StartState.Editor);
                            updatedModules = true;
                        }
                    }

                    if (!updatedModules && !p.Modules.Contains("FARBasicDragModel"))
                    {
                        FARAeroUtil.AddBasicDragModule(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
                }
            }
            return(returnValue);
        }