AttachNode [] getFairingParams() { if (part.GetComponent <KzNodeNumberTweaker>() is KzNodeNumberTweaker nnt && part.FindAttachNodes("connect") is AttachNode[] attached) { if (!AllFairingSidesAttached()) { shape = null; sideFairing = null; boundCylY0 = boundCylY1 = boundCylRad = 0; lookupCenter = Vector3.zero; lookupRad = 0; return(null); } ProceduralFairingSide sf = attached[0].attachedPart.GetComponent <ProceduralFairingSide>(); sideFairing = sf; // Get the polyline shape. shape = (sf.inlineHeight <= 0) ? ProceduralFairingBase.buildFairingShape(sf.baseRad, sf.maxRad, sf.cylStart, sf.cylEnd, sf.noseHeightRatio, sf.baseConeShape, sf.noseConeShape, (int)sf.baseConeSegments, (int)sf.noseConeSegments, sf.vertMapping, sf.mappingScale.y) : ProceduralFairingBase.buildInlineFairingShape(sf.baseRad, sf.maxRad, sf.topRad, sf.cylStart, sf.cylEnd, sf.inlineHeight, sf.baseConeShape, (int)sf.baseConeSegments, sf.vertMapping, sf.mappingScale.y); // Offset shape by thickness. for (int i = 0; i < shape.Length; ++i) { if (i == 0 || i == shape.Length - 1) { shape[i] += new Vector3(sf.sideThickness, 0, 0); } else { Vector2 n = shape[i + 1] - shape[i - 1]; n.Set(n.y, -n.x); n.Normalize(); shape[i] += new Vector3(n.x, n.y, 0) * sf.sideThickness; } } // Compute the bounds. boundCylRad = shape[0].x; boundCylY0 = shape[0].y; boundCylY1 = shape[0].y; foreach (Vector3 p in shape) { boundCylRad = Math.Max(boundCylRad, p.x); boundCylY0 = Math.Min(boundCylY0, p.y); boundCylY1 = Math.Max(boundCylY1, p.y); } lookupCenter = new Vector3(0, (boundCylY0 + boundCylY1) / 2, 0); lookupRad = new Vector2(boundCylRad, (boundCylY1 - boundCylY0) / 2).magnitude; return(attached); } return(null); }
AttachNode [] getFairingParams() { var nnt = part.GetComponent <KzNodeNumberTweaker>(); // Check for attached side parts and get their parameters. var attached = part.FindAttachNodes("connect"); ProceduralFairingSide sf = null; for (int i = 0; i < nnt.numNodes; ++i) { var n = attached [i]; if (!n.attachedPart) { sf = null; break; } sf = n.attachedPart.GetComponent <ProceduralFairingSide>(); if (!sf) { break; } } sideFairing = sf; if (!sf) { shape = null; boundCylY0 = boundCylY1 = boundCylRad = 0; lookupCenter = Vector3.zero; lookupRad = 0; return(null); } // Get the polyline shape. if (sf.inlineHeight <= 0) { shape = ProceduralFairingBase.buildFairingShape(sf.baseRad, sf.maxRad, sf.cylStart, sf.cylEnd, sf.noseHeightRatio, sf.baseConeShape, sf.noseConeShape, (int)sf.baseConeSegments, (int)sf.noseConeSegments, sf.vertMapping, sf.mappingScale.y); } else { shape = ProceduralFairingBase.buildInlineFairingShape(sf.baseRad, sf.maxRad, sf.topRad, sf.cylStart, sf.cylEnd, sf.inlineHeight, sf.baseConeShape, (int)sf.baseConeSegments, sf.vertMapping, sf.mappingScale.y); } // Offset shape by thickness. for (int i = 0; i < shape.Length; ++i) { if (i == 0 || i == shape.Length - 1) { shape [i] += new Vector3(sf.sideThickness, 0, 0); } else { Vector2 n = shape [i + 1] - shape [i - 1]; n.Set(n.y, -n.x); n.Normalize(); shape [i] += new Vector3(n.x, n.y, 0) * sf.sideThickness; } } // Compute the bounds. float y0, y1, mr; y0 = y1 = shape [0].y; mr = shape [0].x; for (int i = 0; i < shape.Length; ++i) { var p = shape [i]; if (p.x > mr) { mr = p.x; } if (p.y < y0) { y0 = p.y; } else if (p.y > y1) { y1 = p.y; } } boundCylY0 = y0; boundCylY1 = y1; boundCylRad = mr; lookupCenter = new Vector3(0, (y0 + y1) * 0.5f, 0); lookupRad = new Vector2(mr, (y1 - y0) * 0.5f).magnitude; return(attached); }
AttachNode[] getFairingParams() { // check attached side parts and get params var attached=part.findAttachNodes("connect"); ProceduralFairingSide sf=null; for (int i=0; i<attached.Length; ++i) { var n=attached[i]; if (!n.attachedPart) { sf=null; break; } sf=n.attachedPart.GetComponent<ProceduralFairingSide>(); if (!sf) break; } sideFairing=sf; if (!sf) { shape=null; boundCylY0=boundCylY1=boundCylRad=0; lookupCenter=Vector3.zero; lookupRad=0; return null; } // get shape polyline if (sf.inlineHeight<=0) shape=ProceduralFairingBase.buildFairingShape( sf.baseRad, sf.maxRad, sf.cylStart, sf.cylEnd, sf.noseHeightRatio, sf.baseConeShape, sf.noseConeShape, sf.baseConeSegments, sf.noseConeSegments, sf.vertMapping, sf.mappingScale.y); else shape=ProceduralFairingBase.buildInlineFairingShape( sf.baseRad, sf.maxRad, sf.topRad, sf.cylStart, sf.cylEnd, sf.inlineHeight, sf.baseConeShape, sf.baseConeSegments, sf.vertMapping, sf.mappingScale.y); // offset shape by thickness for (int i=0; i<shape.Length; ++i) { if (i==0 || i==shape.Length-1) shape[i]+=new Vector3(sf.sideThickness, 0, 0); else { Vector2 n=shape[i+1]-shape[i-1]; n.Set(n.y, -n.x); n.Normalize(); shape[i]+=new Vector3(n.x, n.y, 0)*sf.sideThickness; } } // compute bounds float y0, y1, mr; y0=y1=shape[0].y; mr=shape[0].x; for (int i=0; i<shape.Length; ++i) { var p=shape[i]; if (p.x>mr) mr=p.x; if (p.y<y0) y0=p.y; else if (p.y>y1) y1=p.y; } boundCylY0=y0; boundCylY1=y1; boundCylRad=mr; lookupCenter=new Vector3(0, (y0+y1)*0.5f, 0); lookupRad=new Vector2(mr, (y1-y0)*0.5f).magnitude; return attached; }