diff --git a/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs b/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs index cb4bfb1b2..86bd3c38d 100644 --- a/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs +++ b/FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs @@ -178,11 +178,22 @@ private void DebugPrint() debugInfo.Print(part); } + private void OnEditorAttach() + { + if (meshDataList is null || meshDataList.Count == 0) + { + RebuildAllMeshData(); + } + } + public override void OnAwake() { base.OnAwake(); ignoredTransforms = new List(); unignoredTransforms = new List(); + + // Part has connected member that would work but it is not public... + part.OnEditorAttach += OnEditorAttach; } private void Start() @@ -203,6 +214,8 @@ private void OnDestroy() animStates = null; animStateTime = null; destroyed = true; + + part.OnEditorAttach -= OnEditorAttach; } public override void OnStart(StartState state) @@ -253,6 +266,10 @@ private IEnumerator DoRebuildMeshEditor() while (EditorLogic.SelectedPart == part) yield return waiter; + // skip if not the root part, OnEditorAttach will rebuild the mesh data + if (EditorLogic.RootPart != part) + yield break; + RebuildAllMeshData(); } @@ -350,6 +367,13 @@ private bool IgnoredPredicate(Transform t) private Bounds SetBoundsFromMeshes() { + if (meshDataList.Count == 0) + { + // If the mesh is empty, try rebuilding it. This can happen when a part was added to the editor but not + // the ship before adding it to the ship + RebuildAllMeshData(); + } + Vector3 upper = Vector3.one * float.NegativeInfinity, lower = Vector3.one * float.PositiveInfinity; foreach (GeometryMesh geoMesh in meshDataList) { diff --git a/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll b/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll index 1066b83d7..934400dc0 100644 Binary files a/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll and b/GameData/FerramAerospaceResearch/Plugins/FerramAerospaceResearch.dll differ