예제 #1
0
        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;
        }
예제 #2
0
        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;
        }