public void Update() { CalculateTotalAeroForce(); AeroVisualizationGUI aeroVizGUI = null; if (FlightGUI.vesselFlightGUI != null && vessel != null && FlightGUI.vesselFlightGUI.TryGetValue(vessel, out FlightGUI flightGUI)) { aeroVizGUI = flightGUI.AeroVizGUI; } if (aeroVizGUI == null) { return; } bool anyActive = aeroVizGUI.AnyVisualizationActive; if (!anyActive && !updateVisualization || !HighLogic.LoadedSceneIsFlight || PhysicsGlobals.ThermalColorsDebug) { return; } Color tintColor = AeroVisualizationTintingCalculation(aeroVizGUI); materialColorUpdater.Update(tintColor); // this will disable visualization if none are active delayed by 1 frame to clean up any tint updateVisualization = anyActive; }
//Returns the tinted color if active; else it returns an alpha 0 color private Color AeroVisualizationTintingCalculation(AeroVisualizationGUI aeroVizGUI) { // Disable tinting for low dynamic pressure to prevent flicker if (vessel.dynamicPressurekPa <= 0.00001) { return(new Color(0, 0, 0, 0)); } // Stall tinting overrides Cl / Cd tinting if (legacyWingModel != null && aeroVizGUI.TintForStall) { return(new Color((float)((legacyWingModel.GetStall() * 100.0) / aeroVizGUI.FullySaturatedStall), 0f, 0f, 0.5f)); } if (!aeroVizGUI.TintForCl && !aeroVizGUI.TintForCd) { return(new Color(0, 0, 0, 0)); } double visualizationCl = 0, visualizationCd = 0; if (projectedArea.totalArea > 0.0) { Vector3 worldVelNorm = partTransform.localToWorldMatrix.MultiplyVector(partLocalVelNorm); Vector3 worldDragArrow = Vector3.Dot(totalWorldSpaceAeroForce, worldVelNorm) * worldVelNorm; Vector3 worldLiftArrow = totalWorldSpaceAeroForce - worldDragArrow; double invAndDynPresArea = legacyWingModel != null ? legacyWingModel.S : projectedArea.totalArea; invAndDynPresArea *= vessel.dynamicPressurekPa; invAndDynPresArea = 1 / invAndDynPresArea; visualizationCl = worldLiftArrow.magnitude * invAndDynPresArea; visualizationCd = worldDragArrow.magnitude * invAndDynPresArea; } double fullSatCl = 0, satCl = 0, fullSatCd = 0, satCd = 0; if (legacyWingModel != null) { fullSatCl = aeroVizGUI.FullySaturatedCl; fullSatCd = aeroVizGUI.FullySaturatedCd; } else { fullSatCl = aeroVizGUI.FullySaturatedClBody; fullSatCd = aeroVizGUI.FullySaturatedCdBody; } if (aeroVizGUI.TintForCl) { satCl = Math.Abs(visualizationCl / fullSatCl); } if (aeroVizGUI.TintForCd) { satCd = Math.Abs(visualizationCd / fullSatCd); } return(new Color((float)satCd, 0.5f * (float)(satCl + satCd), (float)satCl, 0.5f)); }
public void Update() { CalculateTotalAeroForce(); FlightGUI flightGUI; AeroVisualizationGUI aeroVizGUI = null; if (FlightGUI.vesselFlightGUI != null && vessel != null && FlightGUI.vesselFlightGUI.TryGetValue(vessel, out flightGUI)) { aeroVizGUI = flightGUI.AeroVizGUI; } if (aeroVizGUI != null && aeroVizGUI.AnyVisualizationActive && HighLogic.LoadedSceneIsFlight && !PhysicsGlobals.ThermalColorsDebug) { Color tintColor = AeroVisualizationTintingCalculation(aeroVizGUI); materialColorUpdater.Update(tintColor); } }