Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Source/Firefly/AtmoFxModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ public void CreateVesselFx()
return;
}

// reset part cache before bounds are set-up
ResetPartModelCache();

// calculate the vessel bounds
bool correctBounds = CalculateVesselBounds(fxVessel, vessel, true);
if (!correctBounds)
Expand All @@ -251,9 +254,6 @@ public void CreateVesselFx()
// create the command buffer
InitializeCommandBuffer();

// reset part cache
ResetPartModelCache();

// create the fx envelopes
UpdateFxEnvelopes();
fxVessel.material.SetTexture("_AirstreamTex", fxVessel.airstreamTexture); // Set the airstream depth texture parameter
Expand Down Expand Up @@ -448,6 +448,9 @@ void CreatePartEnvelope(Part part)
// check for layers
if (Utils.CheckLayerModel(model.transform)) continue;

// check for objects attached to cameras
if (Utils.IsCameraAttachment(model.transform)) continue;

// is skinned
bool isSkinnedRenderer = model.TryGetComponent(out SkinnedMeshRenderer _);

Expand Down Expand Up @@ -923,6 +926,7 @@ bool CalculateVesselBounds(AtmoFxVessel fxVessel, Vessel vsl, bool doChecks)
for (int r = 0; r < renderers.Count; r++)
{
if (!renderers[r].gameObject.activeInHierarchy) continue;
if (Utils.IsCameraAttachment(renderers[r].transform)) continue;

// try getting the mesh filter
bool hasFilter = renderers[r].TryGetComponent(out MeshFilter meshFilter);
Expand Down
15 changes: 15 additions & 0 deletions Source/Firefly/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ public static bool CheckLayerModel(Transform model)
);
}

/// <summary>
/// Check if a model is attached to a camera or to the flight camera rig (this targets hullcam-style cameras or helper objects)
/// Those are not part of the vessel, and thus shouldn't count towards vessel bounds or fx envelopes!
/// </summary>
public static bool IsCameraAttachment(Transform model)
{
for (Transform t = model; t != null; t = t.parent)
{
if (t.TryGetComponent(out Camera _) || t.TryGetComponent(out FlightCamera _)) return true;
if (t.TryGetComponent(out Part _)) return false;
}

return false;
}

public static Vector3 VectorDivide(Vector3 a, Vector3 b)
{
return new Vector3(a.x / b.x, a.y / b.y, a.z / b.z);
Expand Down