diff --git a/Plugins/Source/CHANGES.txt b/Plugins/Source/CHANGES.txt index 53fa6a9b..6a57ca24 100644 --- a/Plugins/Source/CHANGES.txt +++ b/Plugins/Source/CHANGES.txt @@ -1 +1,2 @@ Pre-release changes: +- [Fix] #122: For some parts attach point is wrongly detected. diff --git a/Plugins/Source/KISAddonPointer.cs b/Plugins/Source/KISAddonPointer.cs index 8a4b0a66..e112dcd5 100644 --- a/Plugins/Source/KISAddonPointer.cs +++ b/Plugins/Source/KISAddonPointer.cs @@ -681,8 +681,12 @@ public enum PointerState { /// Sets pointer origin to the current attachment node private static void UpdatePointerAttachNode() { - pointerNodeTransform.localPosition = GetCurrentAttachNode().position; - pointerNodeTransform.localRotation = KIS_Shared.GetNodeRotation(GetCurrentAttachNode()); + var node = GetCurrentAttachNode(); + pointerNodeTransform.localPosition = node.position; + // HACK(ihsoft): For some reason Z orientation axis is get mirrored in the parts. It results in + // a weird behavior when aligning parts in "back" or "front" node attach modes. It may be a + // KIS code bug but I gave up finding it. + pointerNodeTransform.localRotation = KIS_Shared.GetNodeRotation(node, mirrorZ: true); } /// Destroyes object(s) allocated to represent a pointer. diff --git a/Plugins/Source/KIS_Shared.cs b/Plugins/Source/KIS_Shared.cs index 127f5cfb..cbab9d73 100644 --- a/Plugins/Source/KIS_Shared.cs +++ b/Plugins/Source/KIS_Shared.cs @@ -495,8 +495,7 @@ public enum MessageAction { Quaternion adjust) { Vector3 refDir = hit.transform.TransformDirection(Vector3.up); Quaternion rotation = Quaternion.LookRotation(hit.normal, refDir); - source.rotation = (rotation * adjust) * childNode.localRotation; - source.position = source.position - (childNode.position - hit.point); + MoveAlign(source, childNode, hit.point, rotation * adjust); } public static void MoveAlign(Transform source, Transform childNode, Transform target, @@ -549,8 +548,17 @@ public enum MessageAction { return null; } - public static Quaternion GetNodeRotation(AttachNode attachNode) { - return Quaternion.LookRotation(attachNode.orientation); + /// Returns a rotation for the attach node. + /// A node to get orientation from. + /// If true then Z axis in the node's orientation will be mirrored. + /// E.g. (1, 1, 1) will be translated into (1, 1, -1). + /// Rotation quaternion. + public static Quaternion GetNodeRotation(AttachNode attachNode, bool mirrorZ = false) { + var orientation = attachNode.orientation; + if (mirrorZ) { + orientation.z = -orientation.z; + } + return Quaternion.LookRotation(orientation); } public static void AssignAttachIcon(Part part, AttachNode node, Color iconColor,