From 4cab2f46478f86c53166431eee1374da7ced5187 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 6 Sep 2020 14:57:42 +0900 Subject: [PATCH] Add internal module to facilitate animated IVAs ie, when the sub-model that holds the IVA moves relative to the part. It's just a simple parent-constraint that doesn't (yet?) support offset position or rotation. --- Source/InternalParentConstraint.cs | 36 ++++++++++++++++++++++++++++++ Source/Makefile | 1 + 2 files changed, 37 insertions(+) create mode 100644 Source/InternalParentConstraint.cs diff --git a/Source/InternalParentConstraint.cs b/Source/InternalParentConstraint.cs new file mode 100644 index 00000000..e0ae16df --- /dev/null +++ b/Source/InternalParentConstraint.cs @@ -0,0 +1,36 @@ +using System; +using UnityEngine; + +public class ELInternalParentConstraint : InternalModule +{ + [KSPField] + public string parentTransformName; + + Transform parentTransform; + + public override void OnAwake () + { + if (part == null) { + return; + } + if (!String.IsNullOrEmpty (parentTransformName)) { + parentTransform = part.FindModelTransform (parentTransformName); + } + if (parentTransform == null) { + Debug.Log ($"[ELInternalParentConstraint] could not find {parentTransformName}"); + } + } + + void Update () + { + if (parentTransform == null) { + return; + } + Vector3 pos = parentTransform.position; + Quaternion rot = parentTransform.rotation; + + var xform = internalModel.transform; + xform.position = InternalSpace.WorldToInternal (pos); + xform.rotation = InternalSpace.WorldToInternal (rot) * Quaternion.Euler(90, 180, 0); + } +} diff --git a/Source/Makefile b/Source/Makefile index 3df6fc6e..399f500b 100644 --- a/Source/Makefile +++ b/Source/Makefile @@ -26,6 +26,7 @@ EL_FILES := \ Hull/FaceSet.cs \ Hull/RawMesh.cs \ Hull/Triangle.cs \ + InternalParentConstraint.cs \ Recipes/BuildCost.cs \ Recipes/BuildResource.cs \ Recipes/BuildResourceSet.cs \