Skip to content

Commit

Permalink
Ensure VehicleOcclusion or FARAeroPartModule Setup Completed
Browse files Browse the repository at this point in the history
Default to stock drag cube handling until either of these systems is ready, ie voxelization has completed.
  • Loading branch information
DRVeyl committed Apr 11, 2021
1 parent e267cfd commit 46b68db
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ private void UpdateConduction(ModularFlightIntegrator fi)
private static void SetSkinProperties(ModularFlightIntegrator fi, PartThermalData ptd)
{
Part part = ptd.part;
VehicleOcclusion occlusion = fi.Vessel.GetComponent<VehicleOcclusion>();
FARAeroPartModule aeroModule = part.Modules.Contains<FARAeroPartModule>() ? part.Modules.GetModule<FARAeroPartModule>() : null;

if (occlusion == null || aeroModule == null)
//if (occlusion == null || occlusion.state == VehicleOcclusion.State.Invalid || aeroModule == null)
if (!(fi.Vessel.GetComponent<VehicleOcclusion>() is VehicleOcclusion occlusion &&
part.Modules.GetModule<FARAeroPartModule>() is FARAeroPartModule aeroModule &&
occlusion.state != VehicleOcclusion.State.Invalid))
{
fi.BaseFIetSkinPropertie(ptd);
return;
Expand Down Expand Up @@ -193,7 +194,8 @@ private static void StockSkinTemperatureHandling(PartThermalData ptd, double are

private static void UpdateOcclusion(ModularFlightIntegrator fi, bool all)
{
if (fi.Vessel.GetComponent<VehicleOcclusion>() is VehicleOcclusion occlusion)
if (fi.Vessel.GetComponent<VehicleOcclusion>() is VehicleOcclusion occlusion
&& occlusion.state != VehicleOcclusion.State.Invalid)
{
foreach (Part p in fi.Vessel.Parts)
{
Expand All @@ -217,8 +219,7 @@ private static void UpdateThermodynamicsPre(ModularFlightIntegrator fi)
{
PartThermalData ptd = fi.partThermalDataList[i];
Part part = ptd.part;
FARAeroPartModule aeroModule = part.Modules.GetModule<FARAeroPartModule>();
if (aeroModule is null)
if (!(part.Modules.GetModule<FARAeroPartModule>() is FARAeroPartModule aeroModule))
continue;

// make sure drag cube areas are correct based on voxelization
Expand Down Expand Up @@ -335,7 +336,7 @@ private static double CalculateAreaRadiative(
FARAeroPartModule aeroModule
)
{
if (aeroModule is null)
if (aeroModule is null || !FARAPI.VesselVoxelizationCompletedEver(part.vessel))
return fi.BaseFICalculateAreaRadiative(part);
double radArea = aeroModule.ProjectedAreas.totalArea;

Expand All @@ -350,7 +351,7 @@ private static double CalculateAreaExposed(ModularFlightIntegrator fi, Part part

private static double CalculateAreaExposed(ModularFlightIntegrator fi, Part part, FARAeroPartModule aeroModule)
{
if (aeroModule is null)
if (aeroModule is null || !FARAPI.VesselVoxelizationCompletedEver(part.vessel))
return fi.BaseFICalculateAreaExposed(part);

// Apparently stock exposed area is actually weighted by some function of mach number...
Expand All @@ -369,7 +370,7 @@ private static double CalculateSunArea(ModularFlightIntegrator fi, PartThermalDa
{
sunArea = occlusion.SunArea(ptd.part, fi.sunVector);
}
else if (ptd.part.Modules.GetModule<FARAeroPartModule>() is FARAeroPartModule module)
else if (ptd.part.Modules.GetModule<FARAeroPartModule>() is FARAeroPartModule module && FARAPI.VesselVoxelizationCompletedEver(ptd.part.vessel))
{
sunArea = module.ProjectedAreaWorld(fi.sunVector) * ptd.sunAreaMultiplier;
}
Expand All @@ -380,11 +381,11 @@ private static double CalculateBodyArea(ModularFlightIntegrator fi, PartThermalD
{
double bodyArea = 0;
Vector3 bodyVec = fi.Vessel.transform.worldToLocalMatrix * (Vector3)(fi.Vessel.mainBody.position - fi.Vessel.transform.position);
if (fi.Vessel.GetComponent<VehicleOcclusion>() is VehicleOcclusion occlusion)
if (fi.Vessel.GetComponent<VehicleOcclusion>() is VehicleOcclusion occlusion && occlusion.state != VehicleOcclusion.State.Invalid)
{
bodyArea = occlusion.BodyArea(ptd.part, bodyVec.normalized);
}
else if (ptd.part.Modules.GetModule<FARAeroPartModule>() is FARAeroPartModule module)
else if (ptd.part.Modules.GetModule<FARAeroPartModule>() is FARAeroPartModule module && FARAPI.VesselVoxelizationCompletedEver(ptd.part.vessel))
{
bodyArea = module.ProjectedAreaWorld(bodyVec.normalized) * ptd.bodyAreaMultiplier;
}
Expand Down

0 comments on commit 46b68db

Please sign in to comment.