private void UpdateShieldedParts()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            if (bayAnim)
            {
                if (bayAnim.isPlaying && !bayAnimating)
                {
                    ClearShieldedParts();
                    bayAnimating = true;
                }
                else if (bayAnimating && !bayAnim.isPlaying)
                {
                    bayAnimating = false;

                    if (bayOpen && CheckBayClosed())
                    {
                        FindShieldedParts();
                    }
                }
                //                bayProgress = bayAnim[bayAnimationName].normalizedTime;
            }
            else if (BayController == null)
            {
                BayController = this;
            }
        }
Example #2
0
        private void UpdateShieldedParts()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            if (bayAnim)
            {
                if ((bayAnim.isPlaying && bayAnimState.speed != 0) && !bayAnimating)
                {
                    ClearShieldedParts();
                    bayAnimating = true;
                }
                else if (bayAnimating && (!bayAnim.isPlaying || bayAnimState.speed == 0))
                {
                    bayAnimating = false;

                    if (bayOpen && CheckBayClosed())
                    {
                        FindShieldedParts();
                    }
                }
            }
            else if (BayController == null)
            {
                BayController = this;
            }
        }
Example #3
0
        private void AttachNodeCdAdjust()
        {
            if (part.Modules.Contains("FARPayloadFairingModule"))       //This doesn't apply blunt drag drag to fairing parts if one of their "exempt" attach nodes is used, indicating attached fairings
            {
                return;
            }
            if (VesselPartList == null)
            {
                UpdateShipPartsList();
            }

            if (attachNodeDragList == null)
            {
                attachNodeDragList = new List <attachNodeData>();
            }

            attachNodeDragList.Clear();

            Transform transform = part.transform;

            if (transform == null)
            {
                transform = part.transform;
            }
            if (transform == null)
            {
                Debug.LogError("Part " + part.partInfo.title + " has null transform; drag interactions cannot be applied.");
                return;
            }

            SPlusAttachArea = S;

            Vector3d partUpVector = transform.TransformDirection(localUpVector);

            //print("Updating drag for " + part.partInfo.title);
            foreach (AttachNode attach in part.attachNodes)
            {
                if (attach.nodeType == AttachNode.NodeType.Stack)
                {
                    if (attach.id.ToLowerInvariant() == "strut")
                    {
                        continue;
                    }

                    Vector3d relPos = attach.position;// +Attach.offset;

                    if (part.Modules.Contains("FARCargoBayModule"))
                    {
                        FARCargoBayModule bay = (FARCargoBayModule)part.Modules["FARCargoBayModule"];

                        if (bay.bayBounds.Contains(relPos))
                        {
                            continue;
                        }
                    }

                    Vector3d origToNode = transform.localToWorldMatrix.MultiplyVector(relPos);
                    double   attachSize = FARMathUtil.Clamp(attach.size, 0.5, double.PositiveInfinity);

                    if (attach.attachedPart != null)
                    {
                        Vector3           location = attach.attachedPart.transform.position;
                        FARBasicDragModel d        = attach.attachedPart.GetComponent <FARBasicDragModel>();
                        if (d != null)
                        {
                            location += attach.attachedPart.transform.localToWorldMatrix.MultiplyVector(d.CenterOfDrag);
                        }

                        //Debug.Log(Attach.attachedPart.partInfo.title + " " + location + " " + Attach.attachedPart.transform.position + " " + (origToNode + part.transform.position));

                        if (AttachedPartCoDIsFurtherThanAttachLocation(location, origToNode))
                        {
                            continue;
                        }
                        if (AttachedPartIsNotClipping(location, PartBounds))
                        {
                            if (d != null)
                            {
                                location  = this.part.transform.localToWorldMatrix.MultiplyVector(this.CenterOfDrag);
                                location += this.part.transform.position;
                                if (d.AttachedPartIsNotClipping(location, d.PartBounds))
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        //this is a bit of a hack to make intakes function slightly better, since very thin ones seem to have issues.
                        ModuleResourceIntake intake = attach.attachedPart.GetComponent <ModuleResourceIntake>();
                        if (intake != null)
                        {
                            Transform intakeTrans = attach.attachedPart.FindModelTransform(intake.intakeTransformName);
                            if ((object)intakeTrans != null)
                            {
                                Vector3 intakeForwardVec = (intakeTrans.forward);
                                //Vector3 attachOrientation = this.part.transform.localToWorldMatrix.MultiplyVector(attach.orientation);

                                int intakeOrientSign = Math.Sign(Vector3.Dot((Vector3)origToNode, intakeForwardVec));
                                //int attachLocSign = Math.Sign(Vector3.Dot(attachOrientation, (Vector3)origToNode));
                                //int intakeOrientationSign = Math.Sign(Vector3.Dot(intakeForwardVec, (Vector3)origToNode));
                                if (intakeOrientSign > 0)
                                {
                                    continue;
                                }
                            }
                        }
                    }


                    if (UnattachedPartRightAgainstNode(origToNode, attachSize, attach.attachedPart))
                    {
                        continue;
                    }

                    attachNodeData newAttachNodeData = new attachNodeData();

                    double exposedAttachArea = attachSize * FARAeroUtil.attachNodeRadiusFactor;

                    newAttachNodeData.recipDiameter = 1 / (2 * exposedAttachArea);

                    exposedAttachArea *= exposedAttachArea;
                    exposedAttachArea *= Math.PI * FARAeroUtil.areaFactor;

                    SPlusAttachArea += exposedAttachArea;

                    exposedAttachArea /= FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                    newAttachNodeData.areaValue = exposedAttachArea;
                    if (Vector3d.Dot(origToNode, partUpVector) > 0)
                    {
                        newAttachNodeData.pitchesAwayFromUpVec = true;
                    }
                    else
                    {
                        newAttachNodeData.pitchesAwayFromUpVec = false;
                    }

                    newAttachNodeData.location = relPos;
                    //Debug.Log(part.partInfo.title + " found open node");
                    attachNodeDragList.Add(newAttachNodeData);
                }
            }
        }
Example #4
0
        private void AttachNodeCdAdjust()
        {
            if (part.Modules.Contains("FARPayloadFairingModule"))       //This doesn't apply blunt drag drag to fairing parts if one of their "exempt" attach nodes is used, indicating attached fairings
            {
                return;
            }
            if (VesselPartList == null)
            {
                UpdateShipPartsList();
            }

            if (attachNodeDragList == null)
            {
                attachNodeDragList = new List <attachNodeData>();
            }

            attachNodeDragList.Clear();

            Transform transform = part.partTransform;

            if (transform == null)
            {
                transform = part.transform;
            }
            if (transform == null)
            {
                Debug.LogError("Part " + part.partInfo.title + " has null transform; drag interactions cannot be applied.");
                return;
            }

            SPlusAttachArea = S;

            Vector3d partUpVector = transform.TransformDirection(localUpVector);

            Bounds[] rendererBounds = part.GetRendererBounds();

            //print("Updating drag for " + part.partInfo.title);
            foreach (AttachNode Attach in part.attachNodes)
            {
                if (Attach.nodeType == AttachNode.NodeType.Stack)
                {
                    if (Attach.id.ToLowerInvariant() == "strut")
                    {
                        continue;
                    }

                    Vector3d relPos = Attach.position + Attach.offset;

                    if (part.Modules.Contains("FARCargoBayModule"))
                    {
                        FARCargoBayModule bay = (FARCargoBayModule)part.Modules["FARCargoBayModule"];

                        Vector3d maxBounds = bay.maxBounds;
                        Vector3d minBounds = bay.minBounds;

                        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;
                        }
                    }

                    if (Attach.attachedPart != null)
                    {
                        if (AttachedPartIsNotClipping(Attach.attachedPart, rendererBounds))
                        {
                            continue;
                        }
                    }

                    Vector3d origToNode = transform.localToWorldMatrix.MultiplyVector(relPos);
                    double   attachSize = FARMathUtil.Clamp(Attach.size, 0.5, double.PositiveInfinity);

                    if (UnattachedPartRightAgainstNode(origToNode, attachSize, relPos, Attach.attachedPart))
                    {
                        continue;
                    }

                    attachNodeData newAttachNodeData = new attachNodeData();

                    double exposedAttachArea = attachSize * FARAeroUtil.attachNodeRadiusFactor;

                    newAttachNodeData.recipDiameter = 1 / (2 * exposedAttachArea);

                    exposedAttachArea *= exposedAttachArea;
                    exposedAttachArea *= Math.PI * FARAeroUtil.areaFactor;

                    SPlusAttachArea += exposedAttachArea;

                    exposedAttachArea /= FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                    newAttachNodeData.areaValue = exposedAttachArea;
                    if (Vector3d.Dot(origToNode, partUpVector) > 1)
                    {
                        newAttachNodeData.pitchesAwayFromUpVec = true;
                    }
                    else
                    {
                        newAttachNodeData.pitchesAwayFromUpVec = false;
                    }

                    newAttachNodeData.location = transform.worldToLocalMatrix.MultiplyVector(origToNode);

                    attachNodeDragList.Add(newAttachNodeData);
                }
            }
        }
Example #5
0
        private void AttachNodeCdAdjust()
        {
            //BaseCd = 0;
//            if (!part.Modules.Contains("FARPayloadFairingModule"))
//            {
            if (part.Modules.Contains("FARPayloadFairingModule"))       //This doesn't apply blunt drag drag to fairing parts if one of their "exempt" attach nodes is used, indicating attached fairings
            {
                return;
            }

            if (VesselPartList == null)
            {
                UpdateShipPartsList();
            }

            if (attachNodeDragDict == null)
            {
                attachNodeDragDict = new Dictionary <Vector3d, attachNodeData>();
            }

            attachNodeDragDict.Clear();

            Transform transform = part.partTransform;

            Vector3d partUpVector = transform.TransformDirection(localUpVector);

            //print("Updating drag for " + part.partInfo.title);
            foreach (AttachNode Attach in part.attachNodes)
            {
                if (Attach.nodeType == AttachNode.NodeType.Stack)
                {
                    if (Attach.attachedPart != null)
                    {
                        continue;
                    }
                    if (Attach.id.ToLowerInvariant() == "strut")
                    {
                        continue;
                    }

/*                    string attachId = Attach.id.ToLowerInvariant();
 *                  bool leaveAttachLoop = false;
 *                  foreach (string s in FARMiscData.exemptAttachNodes)
 *                      if (attachId.Contains(s))
 *                      {
 *                          leaveAttachLoop = true;
 *                          break;
 *                      }
 *                  if (leaveAttachLoop)
 *                      continue;*/


                    Ray ray = new Ray();

                    Vector3d relPos = Attach.position + Attach.offset;

                    if (part.Modules.Contains("FARCargoBayModule"))
                    {
                        FARCargoBayModule bay = (FARCargoBayModule)part.Modules["FARCargoBayModule"];

                        Vector3d maxBounds = bay.maxBounds;
                        Vector3d minBounds = bay.minBounds;

                        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)
                        {
                            return;
                        }
                    }

                    Vector3d origToNode = transform.localToWorldMatrix.MultiplyVector(relPos);

                    double mag = (origToNode).magnitude;



                    //print(part.partInfo.title + " Part Loc: " + part.transform.position + " Attach Loc: " + (origToNode + part.transform.position) + " Dist: " + mag);

                    ray.direction = origToNode;
                    ray.origin    = transform.position;

                    double attachSize = FARMathUtil.Clamp(Attach.size, 0.5, double.PositiveInfinity);

                    bool         gotIt = false;
                    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))
                        {
                            foreach (Part p in VesselPartList)
                            {
                                if (p.collider == h.collider)
                                {
                                    gotIt = true;
                                    break;
                                }
                            }
                        }
                        if (gotIt)
                        {
                            break;
                        }
                    }

                    if (!gotIt)
                    {
//                            float exposedAttachArea = (Mathf.PI * Mathf.Pow(attachSize * FARAeroUtil.attachNodeRadiusFactor, 2) / Mathf.Clamp(S, 0.01f, Mathf.Infinity));
                        double exposedAttachArea = attachSize * FARAeroUtil.attachNodeRadiusFactor;
                        exposedAttachArea *= exposedAttachArea;
                        exposedAttachArea *= Math.PI * FARAeroUtil.areaFactor;
                        exposedAttachArea /= FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                        attachNodeData newAttachNodeData = new attachNodeData();
                        newAttachNodeData.areaValue = exposedAttachArea;
                        if (Vector3d.Dot(origToNode, partUpVector) > 1)
                        {
                            newAttachNodeData.pitchesAwayFromUpVec = true;
                        }
                        else
                        {
                            newAttachNodeData.pitchesAwayFromUpVec = false;
                        }


                        if (attachNodeDragDict.ContainsKey(transform.worldToLocalMatrix.MultiplyVector(origToNode)))
                        {
                            attachNodeData tmp = attachNodeDragDict[transform.worldToLocalMatrix.MultiplyVector(origToNode)];
                            tmp.areaValue += newAttachNodeData.areaValue;
                            attachNodeDragDict[transform.worldToLocalMatrix.MultiplyVector(origToNode)] = tmp;
                        }
                        else
                        {
                            attachNodeDragDict.Add(part.transform.worldToLocalMatrix.MultiplyVector(origToNode), newAttachNodeData);
                        }
                    }
                }
            }
//            }

            //print(part.partInfo.title + " Num unused Attach Nodes: " + attachNodeDragDict.Count);
        }
        private void UpdateShieldedParts()
        {
            if (HighLogic.LoadedSceneIsEditor)
                return;
            if (bayAnim)
            {
                if (bayAnim.isPlaying && !bayAnimating)
                {
                    ClearShieldedParts();
                    bayAnimating = true;
                }
                else if (bayAnimating && !bayAnim.isPlaying)
                {
                    bayAnimating = false;

                    if (bayOpen && CheckBayClosed())
                        FindShieldedParts();
                }
                //                bayProgress = bayAnim[bayAnimationName].normalizedTime;

            }
            else if (BayController == null)
                BayController = this;
        }
Example #7
0
        private void AttachNodeCdAdjust()
        {
            if (part.Modules.Contains("FARPayloadFairingModule"))       //This doesn't apply blunt drag drag to fairing parts if one of their "exempt" attach nodes is used, indicating attached fairings
            {
                return;
            }
            if (VesselPartList == null)
            {
                UpdateShipPartsList();
            }

            if (attachNodeDragList == null)
            {
                attachNodeDragList = new List <attachNodeData>();
            }

            attachNodeDragList.Clear();

            Transform transform = part.partTransform;

            if (transform == null)
            {
                transform = part.transform;
            }
            if (transform == null)
            {
                Debug.LogError("Part " + part.partInfo.title + " has null transform; drag interactions cannot be applied.");
                return;
            }

            SPlusAttachArea = S;

            Vector3d partUpVector = transform.TransformDirection(localUpVector);

            //print("Updating drag for " + part.partInfo.title);
            foreach (AttachNode Attach in part.attachNodes)
            {
                if (Attach.nodeType == AttachNode.NodeType.Stack)
                {
                    if (Attach.attachedPart != null)
                    {
                        continue;
                    }
                    if (Attach.id.ToLowerInvariant() == "strut")
                    {
                        continue;
                    }

                    Ray ray = new Ray();

                    Vector3d relPos = Attach.position + Attach.offset;

                    if (part.Modules.Contains("FARCargoBayModule"))
                    {
                        FARCargoBayModule bay = (FARCargoBayModule)part.Modules["FARCargoBayModule"];

                        Vector3d maxBounds = bay.maxBounds;
                        Vector3d minBounds = bay.minBounds;

                        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)
                        {
                            return;
                        }
                    }

                    Vector3d origToNode = transform.localToWorldMatrix.MultiplyVector(relPos);

                    double mag = (origToNode).magnitude;



                    //print(part.partInfo.title + " Part Loc: " + part.transform.position + " Attach Loc: " + (origToNode + part.transform.position) + " Dist: " + mag);

                    ray.direction = origToNode;
                    ray.origin    = transform.position;

                    double attachSize = FARMathUtil.Clamp(Attach.size, 0.5, double.PositiveInfinity);

                    bool         gotIt = false;
                    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))
                        {
                            foreach (Part p in VesselPartList)
                            {
                                if (p.collider == h.collider)
                                {
                                    gotIt = true;
                                    break;
                                }
                            }
                        }
                        if (gotIt)
                        {
                            break;
                        }
                    }

                    if (!gotIt)
                    {
                        double exposedAttachArea = attachSize * FARAeroUtil.attachNodeRadiusFactor;
                        exposedAttachArea *= exposedAttachArea;
                        exposedAttachArea *= Math.PI * FARAeroUtil.areaFactor;

                        SPlusAttachArea += exposedAttachArea;

                        exposedAttachArea /= FARMathUtil.Clamp(S, 0.01, double.PositiveInfinity);

                        attachNodeData newAttachNodeData = new attachNodeData();
                        newAttachNodeData.areaValue = exposedAttachArea;
                        if (Vector3d.Dot(origToNode, partUpVector) > 1)
                        {
                            newAttachNodeData.pitchesAwayFromUpVec = true;
                        }
                        else
                        {
                            newAttachNodeData.pitchesAwayFromUpVec = false;
                        }

                        newAttachNodeData.location = transform.worldToLocalMatrix.MultiplyVector(origToNode);

                        attachNodeDragList.Add(newAttachNodeData);
                    }
                }
            }
        }