mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Update ModuleRestockHeatEffects to fix instantiation issues
Untested (will test when I get home)
This commit is contained in:
parent
38ecd498b0
commit
6cd78839ae
Binary file not shown.
@ -13,11 +13,11 @@ namespace Restock
|
|||||||
[KSPField] public string shaderProperty = "_EmissiveColor";
|
[KSPField] public string shaderProperty = "_EmissiveColor";
|
||||||
|
|
||||||
// animation curve for the red channel
|
// animation curve for the red channel
|
||||||
[KSPField] public FloatCurve redCurve= new FloatCurve();
|
[KSPField] public FloatCurve redCurve = new FloatCurve();
|
||||||
|
|
||||||
// animation curve for the green channel
|
// animation curve for the green channel
|
||||||
[KSPField] public FloatCurve greenCurve = new FloatCurve();
|
[KSPField] public FloatCurve greenCurve = new FloatCurve();
|
||||||
|
|
||||||
// animation curve for the blue channel
|
// animation curve for the blue channel
|
||||||
[KSPField] public FloatCurve blueCurve = new FloatCurve();
|
[KSPField] public FloatCurve blueCurve = new FloatCurve();
|
||||||
|
|
||||||
@ -26,41 +26,44 @@ namespace Restock
|
|||||||
|
|
||||||
// draper point, the temperature in Kelvin where materials start glowing
|
// draper point, the temperature in Kelvin where materials start glowing
|
||||||
[KSPField] public double draperPoint = 798.0;
|
[KSPField] public double draperPoint = 798.0;
|
||||||
|
|
||||||
// temperature where the animation is at its maximum
|
// temperature where the animation is at its maximum
|
||||||
[KSPField] public double lerpMax = double.NaN;
|
[KSPField] public double lerpMax = double.NaN;
|
||||||
|
|
||||||
// temperature where the animation is at its minimum, added with draperPoint
|
// temperature where the animation is at its minimum, added with draperPoint
|
||||||
[KSPField] public double lerpMin = 0.0;
|
[KSPField] public double lerpMin = 0.0;
|
||||||
|
|
||||||
// use the part's core temperature? (overrides useSkinTemp)
|
// use the part's core temperature? (overrides useSkinTemp)
|
||||||
[KSPField] public bool useCoreTemp = false;
|
[KSPField] public bool useCoreTemp = false;
|
||||||
|
|
||||||
// use the part's skin temperature?
|
// use the part's skin temperature?
|
||||||
[KSPField] public bool useSkinTemp = false;
|
[KSPField] public bool useSkinTemp = false;
|
||||||
|
|
||||||
// should the module disable the stock blackbody glow effect on the included renderers?
|
// should the module disable the stock blackbody glow effect on the included renderers?
|
||||||
[KSPField] public bool disableBlackbody = false;
|
[KSPField] public bool disableBlackbody = false;
|
||||||
|
|
||||||
[KSPField] public List<Renderer> renderers = new List<Renderer>();
|
public List<Renderer> renderers = new List<Renderer>();
|
||||||
|
|
||||||
private readonly string _shaderBlackbody = "_TemperatureColor";
|
private readonly string _shaderBlackbody = "_TemperatureColor";
|
||||||
|
|
||||||
private ModuleCoreHeat _coreHeatModule = null;
|
private ModuleCoreHeat _coreHeatModule = null;
|
||||||
|
|
||||||
private int _shaderPropertyID;
|
private int _shaderPropertyID;
|
||||||
|
|
||||||
private int _shaderBlackbodyID;
|
private int _shaderBlackbodyID;
|
||||||
|
|
||||||
private double _lerpRange;
|
private double _lerpRange;
|
||||||
|
|
||||||
private Color _emissiveColor = new Color();
|
private Color _emissiveColor;
|
||||||
private MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock();
|
private MaterialPropertyBlock _propertyBlock;
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
if (base.vessel == null) return;
|
if (base.vessel == null) return;
|
||||||
|
|
||||||
|
_emissiveColor = new Color();
|
||||||
|
_propertyBlock = new MaterialPropertyBlock();
|
||||||
|
|
||||||
if (enableHeatEmissive)
|
if (enableHeatEmissive)
|
||||||
{
|
{
|
||||||
if (useCoreTemp)
|
if (useCoreTemp)
|
||||||
@ -72,7 +75,7 @@ namespace Restock
|
|||||||
useCoreTemp = false;
|
useCoreTemp = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (double.IsNaN(lerpMax))
|
if (double.IsNaN(lerpMax))
|
||||||
{
|
{
|
||||||
if (useCoreTemp)
|
if (useCoreTemp)
|
||||||
@ -95,17 +98,17 @@ namespace Restock
|
|||||||
_shaderBlackbodyID = Shader.PropertyToID(_shaderBlackbody);
|
_shaderBlackbodyID = Shader.PropertyToID(_shaderBlackbody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnLoad(ConfigNode node)
|
public override void OnLoad(ConfigNode node)
|
||||||
{
|
{
|
||||||
if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return;
|
if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return;
|
||||||
|
|
||||||
renderers = base.part.FindModelComponents<Renderer>();
|
renderers = base.part.FindModelComponents<Renderer>();
|
||||||
|
|
||||||
if (node.HasValue("excludedRenderer"))
|
if (node.HasValue("excludedRenderer"))
|
||||||
{
|
{
|
||||||
var excludedRenderers = new List<string>();
|
var excludedRenderers = new List<string>();
|
||||||
|
|
||||||
excludedRenderers.AddRange(node.GetValues("excludedRenderer"));
|
excludedRenderers.AddRange(node.GetValues("excludedRenderer"));
|
||||||
|
|
||||||
for (int i = renderers.Count - 1; i >= 0; i--)
|
for (int i = renderers.Count - 1; i >= 0; i--)
|
||||||
@ -121,7 +124,7 @@ namespace Restock
|
|||||||
public void LateUpdate()
|
public void LateUpdate()
|
||||||
{
|
{
|
||||||
if (!HighLogic.LoadedSceneIsFlight) return;
|
if (!HighLogic.LoadedSceneIsFlight) return;
|
||||||
if (renderers == null) return;
|
if (renderers == null) return;
|
||||||
//when switching to the flight scene LateUpdate gets called AFTER OnLoad for some reason
|
//when switching to the flight scene LateUpdate gets called AFTER OnLoad for some reason
|
||||||
// so renderers should hopefully only be null for one frame
|
// so renderers should hopefully only be null for one frame
|
||||||
|
|
||||||
@ -136,10 +139,10 @@ namespace Restock
|
|||||||
{
|
{
|
||||||
temp = useSkinTemp ? base.part.skinTemperature : base.part.temperature;
|
temp = useSkinTemp ? base.part.skinTemperature : base.part.temperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
var temp2 = (float) ((temp - draperPoint) / _lerpRange);
|
var temp2 = (float) ((temp - draperPoint) / _lerpRange);
|
||||||
temp2 = Mathf.Clamp01(temp2);
|
temp2 = Mathf.Clamp01(temp2);
|
||||||
|
|
||||||
_emissiveColor.r = redCurve.Evaluate(temp2);
|
_emissiveColor.r = redCurve.Evaluate(temp2);
|
||||||
_emissiveColor.g = greenCurve.Evaluate(temp2);
|
_emissiveColor.g = greenCurve.Evaluate(temp2);
|
||||||
_emissiveColor.b = blueCurve.Evaluate(temp2);
|
_emissiveColor.b = blueCurve.Evaluate(temp2);
|
||||||
|
Loading…
Reference in New Issue
Block a user