예제 #1
0
        public virtual void updateShape()
        {
            changed = false;

            var node = part.findAttachNode("bottom");

            if (node != null)
            {
                node.size = Mathf.RoundToInt(baseSize / diameterStepLarge);
            }

            node = part.findAttachNode("top");
            if (node != null)
            {
                node.size = Mathf.RoundToInt(baseSize / diameterStepLarge);
            }

            node = part.findAttachNode(topNodeName);
            if (node != null)
            {
                node.position = new Vector3(0, height, 0);
                node.size     = Mathf.RoundToInt(topSize / diameterStepLarge);
                if (!justLoaded)
                {
                    PFUtils.updateAttachedPartPos(node, part);
                }
            }
            else
            {
                Debug.LogError("[ProceduralAdapterBase] No '" + topNodeName + "' node in part", this);
            }
        }
예제 #2
0
        public override void resizePart(float scale)
        {
            base.resizePart(scale);

            var node = part.findAttachNode("bottom");

            foreach (var n in part.findAttachNodes("bottom"))
            {
                n.position.y = node.position.y;
                if (!justLoaded)
                {
                    PFUtils.updateAttachedPartPos(n, part);
                }
            }

            var nnt = part.GetComponent <KzNodeNumberTweaker>();

            if (nnt)
            {
                float mr = size * 0.5f;
                if (nnt.radius > mr)
                {
                    nnt.radius = mr;
                }
                ((UI_FloatEdit)nnt.Fields["radius"].uiControlEditor).maxValue = mr;
            }
        }
예제 #3
0
        public void scaleNode(AttachNode node, float scale, bool setSize)
        {
            if (node == null)
            {
                return;
            }

            node.position = node.originalPosition * scale;

            if (!justLoaded)
            {
                PFUtils.updateAttachedPartPos(node, part);
            }

            if (setSize)
            {
                node.size = Mathf.RoundToInt(scale / diameterStepLarge);
            }

            if (node.attachedPart != null)
            {
                var baseEventDatum = new BaseEventDetails(0);

                baseEventDatum.Set <Vector3>("location", node.position);
                baseEventDatum.Set <Vector3>("orientation", node.orientation);
                baseEventDatum.Set <Vector3>("secondaryAxis", node.secondaryAxis);
                baseEventDatum.Set <AttachNode>("node", node);

                node.attachedPart.SendEvent("OnPartAttachNodePositionChanged", baseEventDatum);
            }
        }
예제 #4
0
        public override void resizePart(float scale)
        {
            float sth = calcSideThickness();

            float br = size * 0.5f - sth;

            scale = br * 2;

            base.resizePart(scale);

            var topNode    = part.FindAttachNode("top");
            var bottomNode = part.FindAttachNode("bottom");

            float y = (topNode.position.y + bottomNode.position.y) * 0.5f;

            int sideNodeSize = Mathf.RoundToInt(scale / diameterStepLarge) - 1;

            if (sideNodeSize < 0)
            {
                sideNodeSize = 0;
            }

            var nodes = part.FindAttachNodes("connect");

            for (int i = 0; i < nodes.Length; i++)
            {
                var n = nodes [i];

                n.position.y = y;
                n.size       = sideNodeSize;

                if (!justLoaded)
                {
                    PFUtils.updateAttachedPartPos(n, part);
                }
            }

            var nnt = part.GetComponent <KzNodeNumberTweaker>();

            if (nnt)
            {
                nnt.radius = size * 0.5f;
            }

            var fbase = part.GetComponent <ProceduralFairingBase>();

            if (fbase)
            {
                fbase.baseSize        = br * 2;
                fbase.sideThickness   = sth;
                fbase.needShapeUpdate = true;
            }
        }
예제 #5
0
 public void scaleNode(AttachNode node, float scale, bool setSize)
 {
     if (node == null)
     {
         return;
     }
     node.position = node.originalPosition * scale;
     if (!justLoaded)
     {
         PFUtils.updateAttachedPartPos(node, part);
     }
     if (setSize)
     {
         node.size = Mathf.RoundToInt(scale / diameterStepLarge);
     }
 }
        void updateNodePositions()
        {
            float d = Mathf.Sin(Mathf.PI / numNodes) * radius * 2;

            int size = Mathf.RoundToInt(d / (radiusStepLarge * 2));

            for (int i = 1; i <= numNodes; ++i)
            {
                var node = findNode(i);

                if (node == null)
                {
                    continue;
                }

                float a = Mathf.PI * 2 * (i - 1) / numNodes;

                node.position.x = Mathf.Cos(a) * radius;
                node.position.z = Mathf.Sin(a) * radius;

                if (shouldResizeNodes)
                {
                    node.size = size;
                }

                if (!justLoaded)
                {
                    PFUtils.updateAttachedPartPos(node, part);
                }
            }

            for (int i = numNodes + 1; i <= maxNumber; ++i)
            {
                var node = findNode(i);

                if (node == null)
                {
                    continue;
                }

                node.position.x = 10000;
            }
        }
예제 #7
0
        public static void UpdateNode(Part part, AttachNode node, Vector3 newPosition, int size, bool pushAttachments, float attachDiameter = 0)
        {
            if (node is AttachNode)
            {
                Vector3 oldPosWorld = part.transform.TransformPoint(node.position);
                node.position = newPosition;
                node.size     = size;

                if (pushAttachments)
                {
                    PFUtils.updateAttachedPartPos(node, part, oldPosWorld);
                }

                if (node.attachedPart is Part)
                {
                    PFUtils.InformAttachedPartNodePositionChanged(node);
                    PFUtils.InformAttachNodeSizeChanged(node, attachDiameter > 0 ? attachDiameter : Mathf.Max(node.size, 0.01f));
                }
            }
        }
예제 #8
0
        public virtual void updateShape()
        {
            changed = false;

            float topheight     = 0;
            float topnodeheight = 0;

            var node = part.FindAttachNode("bottom");

            if (node != null)
            {
                node.size = Mathf.RoundToInt(baseSize / diameterStepLarge);
            }

            node = part.FindAttachNode("top");

            if (node != null)
            {
                node.size = Mathf.RoundToInt(baseSize / diameterStepLarge);

                topheight = node.position.y;
            }

            node = part.FindAttachNode(topNodeName);

            if (node != null)
            {
                node.position = new Vector3(0, height, 0);

                node.size = Mathf.RoundToInt(topSize / diameterStepLarge);

                if (!justLoaded)
                {
                    PFUtils.updateAttachedPartPos(node, part);
                }

                topnodeheight = height;
            }
            else
            {
                Debug.LogError("[PF]: No '" + topNodeName + "' node in part!", this);
            }

            var internodes = part.FindAttachNodes("interstage");

            if (internodes != null)
            {
                var inc = (topnodeheight - topheight) / (internodes.Length / 2 + 1);

                for (int i = 0, j = 0; i < internodes.Length; i = i + 2)
                {
                    var height = topheight + (j + 1) * inc;

                    j++;

                    node = internodes [i];

                    node.position.y = height;
                    node.size       = node.size = Mathf.RoundToInt(topSize / diameterStepLarge) - 1;

                    if (!justLoaded)
                    {
                        PFUtils.updateAttachedPartPos(node, part);
                    }

                    node = internodes [i + 1];

                    node.position.y = height;
                    node.size       = node.size = Mathf.RoundToInt(topSize / diameterStepLarge) - 1;

                    if (!justLoaded)
                    {
                        PFUtils.updateAttachedPartPos(node, part);
                    }
                }
            }
        }
예제 #9
0
        public override void updateShape()
        {
            base.updateShape();

            float sth = calcSideThickness();

            float br    = baseSize * 0.5f - sth;
            float scale = br * 2;

            part.mass = totalMass = ((specificMass.x * scale + specificMass.y) * scale + specificMass.z) * scale + specificMass.w;

            massDisplay = PFUtils.formatMass(totalMass);
            costDisplay = PFUtils.formatCost(part.partInfo.cost + GetModuleCost(part.partInfo.cost, ModifierStagingSituation.CURRENT));

            part.breakingForce  = specificBreakingForce * Mathf.Pow(br, 2);
            part.breakingTorque = specificBreakingTorque * Mathf.Pow(br, 2);

            var model = part.FindModelTransform("model");

            if (model != null)
            {
                model.localScale = Vector3.one * scale;
            }
            else
            {
                Debug.LogError("[PF]: No 'model' transform found in part!", this);
            }

            part.rescaleFactor = scale;

            var node = part.FindAttachNode("top");

            node.position = node.originalPosition * scale;

            if (!justLoaded)
            {
                PFUtils.updateAttachedPartPos(node, part);
            }

            var topNode    = part.FindAttachNode("top");
            var bottomNode = part.FindAttachNode("bottom");

            float y = (topNode.position.y + bottomNode.position.y) * 0.5f;

            int sideNodeSize = Mathf.RoundToInt(scale / diameterStepLarge) - 1;

            if (sideNodeSize < 0)
            {
                sideNodeSize = 0;
            }

            var nodes = part.FindAttachNodes("connect");

            if (nodes != null)
            {
                for (int i = 0; i < nodes.Length; i++)
                {
                    var n = nodes [i];

                    n.position.y = y;
                    n.size       = sideNodeSize;

                    if (!justLoaded)
                    {
                        PFUtils.updateAttachedPartPos(n, part);
                    }
                }
            }

            var topnode2   = part.FindAttachNode(topNodeName);
            var internodes = part.FindAttachNodes("interstage");

            if (internodes != null && topnode2 != null)
            {
                var topheight      = topNode.position.y;
                var topnode2height = topnode2.position.y;

                var inc = (topnode2height - topheight) / (internodes.Length / 2 + 1);

                for (int i = 0, j = 0; i < internodes.Length; i = i + 2)
                {
                    var baseHeight = topheight + (j + 1) * inc;

                    j++;

                    node = internodes [i];

                    node.position.y = baseHeight;
                    node.size       = topNode.size;

                    if (!justLoaded)
                    {
                        PFUtils.updateAttachedPartPos(node, part);
                    }

                    node = internodes [i + 1];

                    node.position.y = baseHeight;
                    node.size       = sideNodeSize;

                    if (!justLoaded)
                    {
                        PFUtils.updateAttachedPartPos(node, part);
                    }
                }
            }

            var nnt = part.GetComponent <KzNodeNumberTweaker>();

            if (nnt)
            {
                nnt.radius = baseSize * 0.5f;
            }

            var fbase = part.GetComponent <ProceduralFairingBase>();

            if (fbase)
            {
                fbase.baseSize        = br * 2;
                fbase.sideThickness   = sth;
                fbase.needShapeUpdate = true;
            }

            StartCoroutine(PFUtils.updateDragCubeCoroutine(part, dragAreaScale));
        }
예제 #10
0
        public override void updateShape()
        {
            base.updateShape();

            float sth   = calcSideThickness();
            float br    = baseSize * 0.5f - sth;
            float scale = br * 2;

            part.mass           = ((specificMass.x * scale + specificMass.y) * scale + specificMass.z) * scale + specificMass.w;
            massDisplay         = PFUtils.formatMass(part.mass);
            costDisplay         = PFUtils.formatCost(part.partInfo.cost + GetModuleCost());
            part.breakingForce  = specificBreakingForce * Mathf.Pow(br, 2);
            part.breakingTorque = specificBreakingTorque * Mathf.Pow(br, 2);

            var model = part.FindModelTransform("model");

            if (model != null)
            {
                model.localScale = Vector3.one * scale;
            }
            else
            {
                Debug.LogError("[ProceduralFairingAdapter] No 'model' transform in the part", this);
            }

            var node = part.findAttachNode("top");

            node.position = node.originalPosition * scale;
            if (!justLoaded)
            {
                PFUtils.updateAttachedPartPos(node, part);
            }

            var topNode    = part.findAttachNode("top");
            var bottomNode = part.findAttachNode("bottom");

            float y            = (topNode.position.y + bottomNode.position.y) * 0.5f;
            int   sideNodeSize = Mathf.RoundToInt(scale / diameterStepLarge) - 1;

            if (sideNodeSize < 0)
            {
                sideNodeSize = 0;
            }

            foreach (var n in part.findAttachNodes("connect"))
            {
                n.position.y = y;
                n.size       = sideNodeSize;
                if (!justLoaded)
                {
                    PFUtils.updateAttachedPartPos(n, part);
                }
            }

            var nnt = part.GetComponent <KzNodeNumberTweaker>();

            if (nnt)
            {
                nnt.radius = baseSize * 0.5f;
            }

            var fbase = part.GetComponent <ProceduralFairingBase>();

            if (fbase)
            {
                fbase.baseSize      = br * 2;
                fbase.sideThickness = sth;
                fbase.updateDelay   = 0;
            }
        }