Skip to content

Commit

Permalink
Fix #451: reset special renderqueue value when leaving IVA mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Oct 26, 2024
1 parent 10a7602 commit 287c0c3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
44 changes: 11 additions & 33 deletions FreeIva/FreeIva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,14 @@ public void OnDestroy()

public void FixedUpdate()
{
if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA && CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.Internal) return;
if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA && CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.Internal)
{
if (CurrentInternalModuleFreeIva != null)
{
SetCurrentPart(null);
}
return;
}

UpdateCurrentPart();

Expand Down Expand Up @@ -310,18 +317,6 @@ void LateUpdate()
}
}

public static int DepthMaskQueue = 999;

/// <summary>
///
/// </summary>
/// <param name="activePart">The part that the IVA player is currently inside.</param>
public static void SetRenderQueues(Part activePart)
{
InternalModuleFreeIva.RefreshDepthMasks();
return;
}

List<InternalModuleFreeIva> possibleModules = new List<InternalModuleFreeIva>();
Vector3 _previousCameraPosition = Vector3.zero;
public void UpdateCurrentPart()
Expand Down Expand Up @@ -458,36 +453,19 @@ public static void GetInternalModulesBoundingCamera(Part p, List<InternalModuleF
Profiler.EndSample();
}

static void SetModelRenderQueue(InternalModuleFreeIva internalModule, int fromRenderQueue, int toRenderQueue)
{
if (internalModule == null) return;
var internalModel = internalModule.internalModel;
if (internalModel == null) return;
var modelTransform = internalModel.transform.Find("model");
if (modelTransform == null) return;

foreach (var renderer in modelTransform.GetComponentsInChildren<Renderer>())
{
if (renderer.material.renderQueue == fromRenderQueue)
{
renderer.material.renderQueue = toRenderQueue;
}
}
}

public static void SetCurrentPart(InternalModel newModel)
{
var newModule = InternalModuleFreeIva.GetForModel(newModel);

if (newModule == null && CurrentInternalModuleFreeIva != null)
if (newModule == null && CurrentInternalModuleFreeIva != null && CameraManager.Instance != null && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA)
{
Log.Warning($"setting current module to null (was {CurrentInternalModuleFreeIva.internalModel.internalName}) for INTERNAL {(newModel == null ? "null" : newModel.internalName)}");
}

if (FreeIva.CurrentInternalModuleFreeIva != newModule)
{
SetModelRenderQueue(FreeIva.CurrentInternalModuleFreeIva, InternalModuleFreeIva.CURRENT_PART_RENDER_QUEUE, InternalModuleFreeIva.OPAQUE_RENDER_QUEUE);
SetModelRenderQueue(newModule, InternalModuleFreeIva.OPAQUE_RENDER_QUEUE, InternalModuleFreeIva.CURRENT_PART_RENDER_QUEUE);
if (CurrentInternalModuleFreeIva != null) CurrentInternalModuleFreeIva.SetIsCurrentModule(false);
if (newModule != null) newModule.SetIsCurrentModule(true);

CurrentInternalModuleFreeIva = newModule;
CameraManager.Instance.activeInternalPart = CurrentPart;
Expand Down
1 change: 0 additions & 1 deletion FreeIva/Gui/GuiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ private static void MeshRendererGui()
if (GUILayout.Button("Select current MeshRenderer"))
FreeIva.SelectedObject = mr.gameObject;

FreeIva.DepthMaskQueue = GUIUtil.EditableIntField("Render Queue for open parts", FreeIva.DepthMaskQueue, null);
mr.gameObject.layer = GUIUtil.EditableIntField("Layer", mr.gameObject.layer, null);
}
}
Expand Down
19 changes: 19 additions & 0 deletions FreeIva/InternalModules/InternalModuleFreeIva.cs
Original file line number Diff line number Diff line change
Expand Up @@ -804,5 +804,24 @@ void OnDestroy()
GameObject.Destroy(SecondaryInternalModel.gameObject);
}
}

internal void SetIsCurrentModule(bool isCurrentModule)
{
if (internalModel == null) return;
var modelTransform = internalModel.transform.Find("model");
if (modelTransform == null) return;

int fromRenderQueue = isCurrentModule ? OPAQUE_RENDER_QUEUE : CURRENT_PART_RENDER_QUEUE;
int toRenderQueue = isCurrentModule ? CURRENT_PART_RENDER_QUEUE : OPAQUE_RENDER_QUEUE;

// TODO: this includes seated kerbals
foreach (var renderer in modelTransform.GetComponentsInChildren<Renderer>())
{
if (renderer.material.renderQueue == fromRenderQueue)
{
renderer.material.renderQueue = toRenderQueue;
}
}
}
}
}

0 comments on commit 287c0c3

Please sign in to comment.