diff --git a/Assets/CineboxAndrew b/Assets/CineboxAndrew index 50bf72ec..d7bd2843 160000 --- a/Assets/CineboxAndrew +++ b/Assets/CineboxAndrew @@ -1 +1 @@ -Subproject commit 50bf72ec7b753e46212a7a8a152eb4d3a69df8f9 +Subproject commit d7bd2843df00322a0974a09d74c40d6aff9c9085 diff --git a/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-coneintake-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-coneintake-mask.mu new file mode 100644 index 00000000..8fd41a5a Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-coneintake-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-fanintake-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-fanintake-mask.mu new file mode 100644 index 00000000..2f25c688 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-fanintake-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-inlineintake-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-inlineintake-mask.mu new file mode 100644 index 00000000..a4e30547 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-inlineintake-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-longintake-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-longintake-mask.mu new file mode 100644 index 00000000..51224b6c Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-longintake-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-miniintake-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-miniintake-mask.mu new file mode 100644 index 00000000..d273ddc5 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-miniintake-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-radialintake-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-radialintake-mask.mu new file mode 100644 index 00000000..ea0a7782 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-radialintake-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-rampintake-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-rampintake-mask.mu new file mode 100644 index 00000000..98b48a7a Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Aero/DepthMasks/restock-rampintake-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-1x6-shrouded.mu b/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-1x6-shrouded.mu index 5226ed91..46ad5191 100644 Binary files a/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-1x6-shrouded.mu and b/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-1x6-shrouded.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-3x2-shrouded.mu b/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-3x2-shrouded.mu index 36186da8..9316036d 100644 Binary files a/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-3x2-shrouded.mu and b/Distribution/Restock/GameData/ReStock/Assets/Electrical/restock-solarpanel-3x2-shrouded.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-basicjet-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-basicjet-mask.mu new file mode 100644 index 00000000..0f048276 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-basicjet-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-minijet-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-minijet-mask.mu new file mode 100644 index 00000000..19e562a2 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-minijet-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-ramjet-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-ramjet-mask.mu new file mode 100644 index 00000000..91c30f44 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-ramjet-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-turbojet-mask.mu b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-turbojet-mask.mu new file mode 100644 index 00000000..e494f543 Binary files /dev/null and b/Distribution/Restock/GameData/ReStock/Assets/Engine/DepthMasks/restock-turbojet-mask.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Assets/Science/restock-materialbay-radial-1.mu b/Distribution/Restock/GameData/ReStock/Assets/Science/restock-materialbay-radial-1.mu index 17bfc81e..8e1befed 100644 Binary files a/Distribution/Restock/GameData/ReStock/Assets/Science/restock-materialbay-radial-1.mu and b/Distribution/Restock/GameData/ReStock/Assets/Science/restock-materialbay-radial-1.mu differ diff --git a/Distribution/Restock/GameData/ReStock/Patches/Aerodynamic/restock-intakes-depthmasks.cfg b/Distribution/Restock/GameData/ReStock/Patches/Aerodynamic/restock-intakes-depthmasks.cfg new file mode 100644 index 00000000..53407259 --- /dev/null +++ b/Distribution/Restock/GameData/ReStock/Patches/Aerodynamic/restock-intakes-depthmasks.cfg @@ -0,0 +1,149 @@ +// Patches adding depth masks to air intakes +// Contents: +// Circular Intake (CircularIntake) +// Small Circular Intake (miniIntake) +// Shock Cone Intake (shockConeIntake) +// Adjustable Ramp Intake (ramAirIntake) +// Adjustable Ramp Intake Radial (IntakeRadialLong) +// XM-G50 Radial Air Intake (airScoop) +// Mk1 Diverterless Supersonic Intake (MK1IntakeFuselage) + +// Circular Intake +@PART[CircularIntake] +{ + !mesh = DELETE + + MODEL + { + model = Squad/Parts/Aero/circularIntake/CircularIntake + } + + MODEL + { + model = ReStock/Assets/Aero/DepthMasks/restock-fanintake-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = fanintake_mask + } +} + +// Small Circular Intake +@PART[miniIntake] +{ + !mesh = DELETE + + MODEL + { + model = Squad/Parts/Aero/miniIntake/SmallIntake + } + + MODEL + { + model = ReStock/Assets/Aero/DepthMasks/restock-miniintake-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = miniintake_mask + } +} + +// Shock Cone Intake +@PART[shockConeIntake] +{ + MODEL + { + model = ReStock/Assets/Aero/DepthMasks/restock-coneintake-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = coneintake_mask + } +} + +// Adjustable Ramp Intake +@PART[ramAirIntake] +{ + !mesh = DELETE + + MODEL + { + model = Squad/Parts/Aero/ramAirIntake/RampIntake + } + + MODEL + { + model = ReStock/Assets/Aero/DepthMasks/restock-rampintake-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = rampintake_mask + } +} + +// Adjustable Ramp Intake Radial +@PART[IntakeRadialLong] +{ + !mesh = DELETE + + MODEL + { + model = Squad/Parts/Aero/intakeRadialLong/IntakeRadial + } + + MODEL + { + model = ReStock/Assets/Aero/DepthMasks/restock-longintake-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = longintake_mask + } +} + +// XM-G50 Radial Air Intake +@PART[airScoop] +{ + !mesh = DELETE + + MODEL + { + model = Squad/Parts/Aero/airIntakeRadialXM-G50/RadialIntake + } + + MODEL + { + model = ReStock/Assets/Aero/DepthMasks/restock-radialintake-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = radialintake_mask + } +} + +// Mk1 Diverterless Supersonic Intake +@PART[MK1IntakeFuselage] +{ + MODEL + { + model = ReStock/Assets/Aero/DepthMasks/restock-inlineintake-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = inlineintake_mask + } +} \ No newline at end of file diff --git a/Distribution/Restock/GameData/ReStock/Patches/Electrical/restock-solarpanels.cfg b/Distribution/Restock/GameData/ReStock/Patches/Electrical/restock-solarpanels.cfg index c0858b57..4d4383c4 100644 --- a/Distribution/Restock/GameData/ReStock/Patches/Electrical/restock-solarpanels.cfg +++ b/Distribution/Restock/GameData/ReStock/Patches/Electrical/restock-solarpanels.cfg @@ -44,6 +44,12 @@ { @secondaryTransformName = panel6 } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = solarshroud_mask + } } // 3x2 @@ -82,6 +88,12 @@ { @secondaryTransformName = solar6 } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = solarshroud_mask + } } // Gigantor diff --git a/Distribution/Restock/GameData/ReStock/Patches/Engine/restock-engines-jet-depthmasks.cfg b/Distribution/Restock/GameData/ReStock/Patches/Engine/restock-engines-jet-depthmasks.cfg new file mode 100644 index 00000000..f1e2bb1f --- /dev/null +++ b/Distribution/Restock/GameData/ReStock/Patches/Engine/restock-engines-jet-depthmasks.cfg @@ -0,0 +1,67 @@ +// Patches adding depth masks to the jet engines +// Contents: +// J-33 "Wheesley" Turbofan Engine (JetEngine) +// J-404 "Panther" Afterburning Turbofan (turboJet) +// J-X4 "Whiplash" Turbo Ramjet Engine (turboFanEngine) +// J-20 "Juno" Basic Jet Engine (miniJetEngine) + + +// J-33 "Wheesley" Turbofan Engine +@PART[JetEngine] +{ + MODEL + { + model = ReStock/Assets/Engine/DepthMasks/restock-basicjet-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = basicjet_mask + } +} + +// J-404 "Panther" Afterburning Turbofan +@PART[turboJet] +{ + MODEL + { + model = ReStock/Assets/Engine/DepthMasks/restock-turbojet-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = turbojet_mask + } +} + +// J-X4 "Whiplash" Turbo Ramjet Engine +@PART[turboFanEngine] +{ + MODEL + { + model = ReStock/Assets/Engine/DepthMasks/restock-ramjet-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = ramjet_mask + } +} + +// J-20 "Juno" Basic Jet Engine +@PART[miniJetEngine] +{ + MODEL + { + model = ReStock/Assets/Engine/DepthMasks/restock-minijet-mask + } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = minijet_mask + } +} diff --git a/Distribution/RestockPlus/GameData/ReStockPlus/Parts/Science/restock-materialbay-radial-1.cfg b/Distribution/RestockPlus/GameData/ReStockPlus/Parts/Science/restock-materialbay-radial-1.cfg index 23125fed..3f72c990 100644 --- a/Distribution/RestockPlus/GameData/ReStockPlus/Parts/Science/restock-materialbay-radial-1.cfg +++ b/Distribution/RestockPlus/GameData/ReStockPlus/Parts/Science/restock-materialbay-radial-1.cfg @@ -95,4 +95,10 @@ PART } } } + + MODULE + { + name = ModuleRestockDepthMask + maskTransform = mask + } } diff --git a/Source/Restock/ModuleRestockDepthMask.cs b/Source/Restock/ModuleRestockDepthMask.cs new file mode 100644 index 00000000..fe5f4303 --- /dev/null +++ b/Source/Restock/ModuleRestockDepthMask.cs @@ -0,0 +1,125 @@ +using UnityEngine; +using UnityEngine.Serialization; + +namespace Restock +{ + public class ModuleRestockDepthMask : PartModule + { + // The name of the transform that has your mask mesh. The only strictly required property + [KSPField] + public string maskTransform = ""; + + [KSPField] + public string bodyTransform = ""; + + // The name of the depth mask shader + [KSPField] + public string shaderName = "DepthMask"; + + // The render queue value for the mesh, should be less than maskRenderQueue + [KSPField] + public int meshRenderQueue = 1000; + + // the render queue value for the mask, should be less than 2000 + [KSPField] + public int maskRenderQueue = 1999; + + + // depth mask object transform + public Transform maskTransformObject; + + // body object transform + public Transform bodyTransformObject; + + // depth mask shader object + public Shader depthShader; + + + public override void OnStart(StartState state) + { + base.OnStart(state); + UpdatematerialQueue(); + + // the part variant system is implemented extremely stupidly + // so we have to make this whole module more complicated as a result + GameEvents.onVariantApplied.Add(OnVariantApplied); + } + + + private void OnDestroy() + { + GameEvents.onVariantApplied.Remove(OnVariantApplied); + } + + + public override void OnLoad(ConfigNode node) + { + base.OnLoad(node); + + if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return; + + this.maskTransformObject = base.part.FindModelTransform(maskTransform); + if (this.maskTransformObject == null) + { + this.LogError($"Can't find transform {maskTransform}"); + return; + } + + if (bodyTransform == "") + { + this.bodyTransformObject = base.part.partTransform; + } + else + { + this.bodyTransformObject = base.part.FindModelTransform(bodyTransform); + if (this.bodyTransformObject == null) + { + this.LogError($"Can't find transform {bodyTransform}"); + this.bodyTransformObject = base.part.partTransform; + } + } + + this.depthShader = Shader.Find(shaderName); + if (this.depthShader == null) + { + this.LogError($"Can't find shader {shaderName}"); + return; + } + } + + + public void OnVariantApplied(Part appliedPart, PartVariant variant) + { + // I dont know why changing part variants resets all the materials to their as-loaded state, but it does + if (appliedPart == this.part) UpdatematerialQueue(); + } + + + private void UpdatematerialQueue() + { + var windowRenderer = maskTransformObject.GetComponent(); + + windowRenderer.material.shader = depthShader; + windowRenderer.material.renderQueue = maskRenderQueue; + + var meshRenderers = bodyTransformObject.GetComponentsInChildren(true); + var skinnedMeshRenderers = bodyTransformObject.GetComponentsInChildren(true); + + foreach (var renderer in meshRenderers) + { + if (renderer == windowRenderer) continue; + var queue = renderer.material.renderQueue; + queue = meshRenderQueue + ((queue - 2000) / 2); + renderer.material.renderQueue = queue; + } + + foreach (var renderer in skinnedMeshRenderers) + { + if (renderer == windowRenderer) continue; + var queue = renderer.material.renderQueue; + queue = meshRenderQueue + ((queue - 2000) / 2); + renderer.material.renderQueue = queue; + } + } + } +} \ No newline at end of file diff --git a/Source/Restock/Restock.csproj b/Source/Restock/Restock.csproj index ac7aa686..d1904a8c 100644 --- a/Source/Restock/Restock.csproj +++ b/Source/Restock/Restock.csproj @@ -48,6 +48,7 @@ +