예제 #1
0
        private void TranslateAttachedPart(Vector3 newPosition)
        {
            if (bottomAttachNode.attachedPart is Part pushTarget)
            {
                Vector3 opposingNodePos = pushTarget.transform.TransformPoint(bottomAttachNode.FindOpposingNode().position);

                if (pushTarget == part.parent)
                {
                    pushTarget = part;
                }
                Vector3 shift = pushTarget == part
                    ? opposingNodePos - newPosition
                    : newPosition - opposingNodePos;
                Debug.Log($"{ModTag} {this}: shifting: {pushTarget} by {shift}");
                pushTarget.transform.Translate(shift, Space.World);
            }
        }
예제 #2
0
        void AddMoreJoints()
        {
            int i;

            AttachNode attachNode;

            if (!morejointsadded)
            {
                AttachNode attachNode1 = base.part.FindAttachNode("bottom");

                AttachNode [] attachNodeArray  = base.part.FindAttachNodes("interstage");
                AttachNode [] attachNodeArray1 = base.part.FindAttachNodes("top");

                string [] _vessel = { "[PF]: Adding Joints to Vessel: ", vessel.vesselName, " (Launch ID: ", base.part.launchID.ToString(), ") (GUID: ", base.vessel.id.ToString(), ")" };

                Debug.Log(string.Concat(_vessel));

                _vessel = new [] { "[PF]: For PF Part: ", base.part.name, " (", base.part.craftID.ToString(), ")" };

                Debug.Log(string.Concat(_vessel));

                Part part = null;

                if ((attachNode1 == null ? false : attachNode1.attachedPart != null))
                {
                    part = attachNode1.attachedPart;

                    bottomNodePart = part;

                    addStrut(part, base.part, Vector3.zero);

                    _vessel = new [] { "[PF]: Bottom Part: ", part.name, " (", part.craftID.ToString(), ")" };

                    Debug.Log(string.Concat(_vessel));
                }

                Debug.Log("[PF]: Top Parts:");

                if (attachNodeArray1 != null)
                {
                    for (i = 0; i < (int)attachNodeArray1.Length; i++)
                    {
                        attachNode = attachNodeArray1 [i];

                        if (attachNode.attachedPart != null)
                        {
                            if (part != null)
                            {
                                AddPartJoint(attachNode.attachedPart, part, attachNode.FindOpposingNode(), attachNode1.FindOpposingNode());
                            }

                            addStrut(attachNode.attachedPart, base.part, Vector3.zero);

                            nodeParts.Add(attachNode.attachedPart);

                            _vessel = new [] { "[PF]:", attachNode.attachedPart.name, " (", attachNode.attachedPart.craftID.ToString(), ")" };

                            Debug.Log(string.Concat(_vessel));
                        }
                    }
                }

                if (attachNodeArray != null)
                {
                    for (i = 0; i < (int)attachNodeArray.Length; i++)
                    {
                        attachNode = attachNodeArray [i];

                        if (attachNode.attachedPart != null)
                        {
                            if (part != null)
                            {
                                AddPartJoint(attachNode.attachedPart, part, attachNode.FindOpposingNode(), attachNode1.FindOpposingNode());
                            }

                            addStrut(attachNode.attachedPart, base.part, Vector3.zero);

                            nodeParts.Add(attachNode.attachedPart);

                            _vessel = new [] { "[PF]:", attachNode.attachedPart.name, " (", attachNode.attachedPart.craftID.ToString(), ")" };

                            Debug.Log(string.Concat(_vessel));
                        }
                    }
                }

                morejointsadded = true;
            }
        }
예제 #3
0
 private static string attachNodeStructureError()
 {
     try {
         List <Part> parts = EditorLogic.fetch?.ship?.parts;
         if (parts == null)
         {
             return("No parts found");
         }
         else if (parts.Count < 2)
         {
             // 0 or 1 parts
             // Make sure the nodes are all empty
             for (int p = 0; p < (parts?.Count ?? 0); ++p)
             {
                 Part part = parts[p];
                 for (int n = 0; n < (part.attachNodes?.Count ?? 0); ++n)
                 {
                     AttachNode an = part.attachNodes[n];
                     if (an.attachedPart != null)
                     {
                         return($"{part.partInfo.name}'s node {an.id} is attached");
                     }
                 }
             }
             return("");
         }
         else
         {
             // 2 or more parts
             // Make sure each part has at least one connected node
             // Make sure each connected node has an opposing node
             for (int p = 0; p < (parts?.Count ?? 0); ++p)
             {
                 Part part = parts[p];
                 if ((part.attachNodes?.Count ?? 0) > 1)
                 {
                     bool anyAttached = false;
                     for (int n = 0; n < (part.attachNodes?.Count ?? 0); ++n)
                     {
                         AttachNode an = part.attachNodes[n];
                         if (an.attachedPart != null && an.nodeType == AttachNode.NodeType.Stack)
                         {
                             anyAttached = true;
                             if (an.FindOpposingNode() == null)
                             {
                                 return($"{part.partInfo.name}'s node {an.id} lacks an opposing node");
                             }
                         }
                     }
                     if (!anyAttached)
                     {
                         return($"{part.partInfo.name} has no attached nodes");
                     }
                 }
             }
             return("");
         }
     } catch (Exception ex) {
         MonoBehaviour.print($"Oops during node structure check: {ex.Message}");
         MonoBehaviour.print($"{ex.StackTrace}");
         return("Exception: {ex.Message}");
     }
 }
예제 #4
0
        public void ListJoints()
        {
            int j;

            string [] _name;

            float _breakForce;

            Vector3 _anchor;

            string str;
            string str1;

            ClearJointLines();

            List <Part> activeVessel = FlightGlobals.ActiveVessel.parts;

            for (int i = 0; i < activeVessel.Count; i++)
            {
                ConfigurableJoint [] components = activeVessel[i].gameObject.GetComponents <ConfigurableJoint>();

                if (components != null)
                {
                    for (j = 0; j < (int)components.Length; j++)
                    {
                        ConfigurableJoint configurableJoint = components [j];

                        _name = new string [18];

                        _name[0]    = "[PF]: <ConfigurableJoint>, ";
                        _name[1]    = activeVessel [i].name;
                        _name[2]    = ", ";
                        _name[3]    = (configurableJoint.connectedBody == null ? "<none>" : configurableJoint.connectedBody.name);
                        _name[4]    = ", ";
                        _breakForce = configurableJoint.breakForce;
                        _name[5]    = _breakForce.ToString();
                        _name[6]    = ", ";
                        _breakForce = configurableJoint.breakTorque;
                        _name[7]    = _breakForce.ToString();
                        _name[8]    = ", ";
                        _anchor     = configurableJoint.anchor;
                        _name[9]    = _anchor.ToString();
                        _name[10]   = ", ";
                        _anchor     = configurableJoint.connectedAnchor;
                        _name[11]   = _anchor.ToString();
                        _name[12]   = ", ";

                        string [] strArrays = _name;

                        if (configurableJoint.connectedBody == null)
                        {
                            str1 = "--";
                        }
                        else
                        {
                            _anchor = activeVessel [i].transform.position - configurableJoint.connectedBody.position;

                            str1 = _anchor.ToString();
                        }

                        strArrays [13] = str1;

                        _name [14]  = ", ";
                        _breakForce = configurableJoint.linearLimitSpring.damper;
                        _name [15]  = _breakForce.ToString("F2");
                        _name [16]  = ", ";
                        _breakForce = configurableJoint.linearLimitSpring.spring;
                        _name [17]  = _breakForce.ToString("F2");

                        Debug.Log(string.Concat(_name));
                    }
                }

                PartJoint [] partJointArray = activeVessel[i].gameObject.GetComponents <PartJoint>();

                if (partJointArray != null)
                {
                    for (j = 0; j < (int)partJointArray.Length; j++)
                    {
                        PartJoint partJoint = partJointArray [j];

                        if ((partJoint.Host != null ? true : !(partJoint.Target == null)))
                        {
                            _name = new string [] { "[PF]: <PartJoint>, ", partJoint.Host.name, ", ", null, null, null, null, null, null, null, null };

                            _name[3] = (partJoint.Target == null ? "<none>" : partJoint.Target.name);

                            string [] strArrays1 = _name;

                            if (partJoint.Joint == null)
                            {
                                int count = partJoint.joints.Count;

                                str = string.Concat("<no single joint> (", count.ToString(), ")");
                            }
                            else
                            {
                                _breakForce = partJoint.Joint.breakForce;

                                string str2 = _breakForce.ToString();

                                _breakForce = partJoint.Joint.breakTorque;

                                str = string.Concat(", ", str2, ", ", _breakForce.ToString());
                            }

                            strArrays1 [4] = str;

                            _name [5]   = ", ";
                            _breakForce = partJoint.stiffness;
                            _name [6]   = _breakForce.ToString("F2");
                            _name [7]   = ", ";
                            _anchor     = partJoint.HostAnchor;
                            _name [8]   = _anchor.ToString();
                            _name [9]   = ", ";
                            _anchor     = partJoint.TgtAnchor;
                            _name [10]  = _anchor.ToString();

                            Debug.Log(string.Concat(_name));
                        }
                        else
                        {
                            Debug.Log("[PF]: <PartJoint>, <none>, <none>");
                        }

                        if (partJoint.Target)
                        {
                            AttachNode attachNode = activeVessel [i].FindAttachNodeByPart(partJoint.Target);

                            if (attachNode != null)
                            {
                                object [] objArray = { "[PF]: <AttachNode>, ", partJoint.Host.name, ", ", partJoint.Target.name, ", ", attachNode.breakingForce.ToString(), ", ", attachNode.breakingTorque.ToString(), ", ", attachNode.contactArea.ToString("F2"), ", ", attachNode.attachMethod, ", ", attachNode.rigid.ToString(), ", ", attachNode.radius.ToString("F2") };

                                Debug.Log(string.Concat(objArray));

                                AttachNode attachNode1 = attachNode.FindOpposingNode();

                                if ((attachNode1 == null ? false : attachNode1.owner != null))
                                {
                                    objArray = new object [] { "[PF]: <Opposing AttachNode>, ", attachNode1.owner.name, ", ", (attachNode1.attachedPart != null ? attachNode1.attachedPart.name : "<none>"), ", ", attachNode1.breakingForce.ToString(), ", ", attachNode1.breakingTorque.ToString(), ", ", attachNode1.contactArea.ToString("F2"), ", ", attachNode1.attachMethod, ", ", attachNode1.rigid.ToString(), ", ", attachNode1.radius.ToString("F2") };

                                    Debug.Log(string.Concat(objArray));
                                }
                            }
                        }
                    }
                }

                FixedJoint [] fixedJointArray = activeVessel [i].gameObject.GetComponents <FixedJoint>();

                if (fixedJointArray != null)
                {
                    for (j = 0; j < (int)fixedJointArray.Length; j++)
                    {
                        FixedJoint fixedJoint = fixedJointArray [j];

                        _name = new string [] { "[PF]: <FixedJoint>, ", fixedJoint.name, ", ", null, null, null, null, null, null, null, null, null };

                        _name [3]   = (fixedJoint.connectedBody == null ? "<none>" : fixedJoint.connectedBody.name);
                        _name [4]   = ", ";
                        _breakForce = fixedJoint.breakForce;
                        _name [5]   = _breakForce.ToString();
                        _name [6]   = ", ";
                        _breakForce = fixedJoint.breakTorque;
                        _name [7]   = _breakForce.ToString();
                        _name [8]   = ", ";
                        _anchor     = fixedJoint.anchor;
                        _name [9]   = _anchor.ToString();
                        _name [10]  = ", ";
                        _anchor     = fixedJoint.connectedAnchor;
                        _name [11]  = _anchor.ToString();

                        Debug.Log(string.Concat(_name));
                    }
                }
            }
        }
예제 #5
0
        void AddMoreJoints()
        {
            if (!morejointsadded)
            {
                AttachNode attachNode1 = base.part.FindAttachNode("bottom");

                Debug.Log($"[PF]: Adding Joints to Vessel: {vessel.vesselName}, (Launch ID: {base.part.launchID}) (GUID: {base.vessel.id})");
                Debug.Log($"[PF]: For PF Part: {base.part.name} ({base.part.craftID})");

                Part targetPart = null;
                if (attachNode1 is AttachNode && attachNode1.attachedPart is Part)
                {
                    targetPart = attachNode1.attachedPart;

                    bottomNodePart = targetPart;

                    addStrut(targetPart, base.part, Vector3.zero);
                    Debug.Log($"[PF]: Bottom Part: {targetPart.name} ({targetPart.craftID})");
                }

                Debug.Log("[PF]: Top Parts:");

                if (base.part.FindAttachNodes("top") is AttachNode[] topNodes)
                {
                    foreach (AttachNode attachNode in topNodes)
                    {
                        if (attachNode.attachedPart is Part)
                        {
                            if (targetPart is Part)
                            {
                                AddPartJoint(attachNode.attachedPart, targetPart, attachNode.FindOpposingNode(), attachNode1.FindOpposingNode());
                            }

                            addStrut(attachNode.attachedPart, base.part, Vector3.zero);

                            nodeParts.Add(attachNode.attachedPart);
                            Debug.Log($"[PF]: {attachNode.attachedPart.name} ({attachNode.attachedPart.craftID})");
                        }
                    }
                }

                if (base.part.FindAttachNodes("interstage") is AttachNode[] interNodes)
                {
                    foreach (AttachNode an in interNodes)
                    {
                        if (an.attachedPart is Part)
                        {
                            if (targetPart is Part)
                            {
                                AddPartJoint(an.attachedPart, targetPart, an.FindOpposingNode(), attachNode1.FindOpposingNode());
                            }

                            addStrut(an.attachedPart, base.part, Vector3.zero);

                            nodeParts.Add(an.attachedPart);
                            Debug.Log($"[PF]: {an.attachedPart.name} ({an.attachedPart.craftID})");
                        }
                    }
                }

                morejointsadded = true;
            }
        }