Skip to content

Commit

Permalink
fix voxelization for unattached parts in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
dkavolis committed May 9, 2021
1 parent 28d9af9 commit 63a9c11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions FerramAerospaceResearch/FARPartGeometry/GeometryPartModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
unignoredTransforms = new List<string>();

// Part has connected member that would work but it is not public...
part.OnEditorAttach += OnEditorAttach;
}

private void Start()
Expand All @@ -203,6 +214,8 @@ private void OnDestroy()
animStates = null;
animStateTime = null;
destroyed = true;

part.OnEditorAttach -= OnEditorAttach;
}

public override void OnStart(StartState state)
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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)
{
Expand Down
Binary file not shown.

0 comments on commit 63a9c11

Please sign in to comment.