diff --git a/Source/Firefly/AtmoFxModule.cs b/Source/Firefly/AtmoFxModule.cs index e98aa2d..34b4bb7 100644 --- a/Source/Firefly/AtmoFxModule.cs +++ b/Source/Firefly/AtmoFxModule.cs @@ -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) @@ -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 @@ -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 _); @@ -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); diff --git a/Source/Firefly/Utils.cs b/Source/Firefly/Utils.cs index 0a286f5..923b0e2 100644 --- a/Source/Firefly/Utils.cs +++ b/Source/Firefly/Utils.cs @@ -314,6 +314,21 @@ public static bool CheckLayerModel(Transform model) ); } + /// + /// 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! + /// + 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);