private Vector3 GetRotation(WeldingData wData) { var offset = Quaternion.Inverse(wData.DockingPortA.transform.localRotation) * wData.DockingPortB.transform.localRotation; var oAngle = offset.eulerAngles; //Add a 180 x-flip. return(new Vector3(oAngle.x, oAngle.y, CorrectAngle(oAngle.z - 180))); }
private void PerformWeld(WeldingData wData, bool compress, bool fixRotation) { var nodeA = NodeUtilities.GetLinkingNode(wData.LinkedPartA, wData.DockingPortA); var nodeB = NodeUtilities.GetLinkingNode(wData.LinkedPartB, wData.DockingPortB); var offset = GetOffset(wData); var rotation = GetRotation(wData); if (fixRotation) { wData.LinkedPartB.transform.Rotate(rotation, Space.Self); } NodeUtilities.DetachPart(wData.DockingPortA); NodeUtilities.DetachPart(wData.DockingPortB); NodeUtilities.SwapLinks( wData.LinkedPartA, wData.DockingPortA, wData.LinkedPartB); NodeUtilities.SwapLinks( wData.LinkedPartB, wData.DockingPortB, wData.LinkedPartA); wData.DockingPortB.SetCollisionIgnores(); wData.DockingPortA.SetCollisionIgnores(); NodeUtilities.SpawnStructures(wData.LinkedPartA, nodeA); NodeUtilities.SpawnStructures(wData.LinkedPartB, nodeB); if (compress) { NodeUtilities.MovePart(wData.LinkedPartB, offset); } PartJoint newJoint = PartJoint.Create( wData.LinkedPartB, wData.LinkedPartA, nodeB, nodeA, AttachModes.STACK); wData.LinkedPartB.attachJoint = newJoint; SoftExplode(wData.DockingPortA); SoftExplode(wData.DockingPortB); }
private Vector3 GetOffset(WeldingData wData) { var totalThickness = 0f; var objA = new GameObject(); var objB = new GameObject(); var transformA = objA.transform; var transformB = objB.transform; transformA.localPosition = wData.DockingPortA.transform.localPosition; transformB.localPosition = wData.DockingPortB.transform.localPosition; var offset = transformA.localPosition - transformB.localPosition; offset.Normalize(); totalThickness += NodeUtilities.GetPartThickness(wData.DockingPortA); totalThickness += NodeUtilities.GetPartThickness(wData.DockingPortB); offset *= totalThickness; return(offset); }
private WeldingData LoadWeldingData(bool silent = false, bool retry = false) { /********************** * * LPA==DPA-><-DPB==LPB * * LPA==LPB * **********************/ var wData = new WeldingData(); if (IsWeldablePort(part.parent)) { wData.DockingPortA = part.parent; wData.DockingPortB = part; } else if (part.children != null && part.children.Count > 0) { foreach (var p in part.children.Where(IsWeldablePort)) { wData.DockingPortA = part; wData.DockingPortB = p; break; } } //Check if either are null if (wData.DockingPortA == null || wData.DockingPortB == null) { if (!silent) { ScreenMessages.PostScreenMessage("Must weld two connected, weldable docking ports!"); } return(null); } wData.LinkedPartA = FindAttachedPart(wData.DockingPortA, wData.DockingPortB); wData.LinkedPartB = FindAttachedPart(wData.DockingPortB, wData.DockingPortA); if (wData.LinkedPartA == null || wData.LinkedPartB == null) { if (!silent) { ScreenMessages.PostScreenMessage("Both weldable ports must be connected to another part!"); } return(null); } if (wData.DockingPortA == vessel.rootPart) { if (!silent) { ScreenMessages.PostScreenMessage("This port is the root part! Cancelling"); } return(null); } if (wData.DockingPortB == vessel.rootPart) { if (!silent) { ScreenMessages.PostScreenMessage("Attempting to weld to root part! Cancelling"); } return(null); } return(wData); }