mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Merge branch 'develop' into structural-part-2
This commit is contained in:
commit
c21df64865
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,5 +3,7 @@ deploy/
|
||||
build/
|
||||
build-deploy/
|
||||
.vs/
|
||||
.idea/
|
||||
bin/
|
||||
obj/
|
||||
*.swp
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit c40a3155dbfcdcb8d1f37cd6cd9ed4129f703124
|
||||
Subproject commit d7bd2843df00322a0974a09d74c40d6aff9c9085
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
@ -16,6 +16,7 @@ Localization
|
||||
#LOC_Restock_variant-engine_radial = Radial
|
||||
#LOC_Restock_variant-engine_boattail = Boattail
|
||||
|
||||
#LOC_Restock_variant-mounting_classic = Classic
|
||||
#LOC_Restock_variant-mounting_truss = Truss
|
||||
#LOC_Restock_variant-mounting_compact = Compact
|
||||
|
||||
@ -36,6 +37,10 @@ Localization
|
||||
#LOC_Restock_variant-surface_truss = Truss
|
||||
#LOC_Restock_variant-surface_thermalblankets = Insulated
|
||||
|
||||
#LOC_Restock_variant-surface_yellow = Yellow
|
||||
#LOC_Restock_variant-surface_black = Black
|
||||
|
||||
|
||||
#LOC_Restock_variant-service-bay-opaque = Solid Caps
|
||||
#LOC_Restock_variant-service-bay-transparent = Truss Caps
|
||||
#LOC_Restock_variant-service-bay-hollow = No Caps
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
// Patches applying art changes to the fuel line
|
||||
// Contents:
|
||||
// - FTX-2 External Fuel Duct (fuelLine)
|
||||
|
||||
// FTX-2 External Fuel Duct
|
||||
@PART[fuelLine]
|
||||
{
|
||||
@author = Andrew Cassidy
|
||||
|
||||
!mesh = DELETE
|
||||
MODEL
|
||||
{
|
||||
model = ReStock/Assets/CompoundParts/restock-fuelline-1
|
||||
}
|
||||
rescaleFactor = 1.0
|
||||
!scale = DELETE
|
||||
|
||||
!MODULE[CModuleLinkedMesh] {}
|
||||
MODULE
|
||||
{
|
||||
name = ModuleRestockLinkedMesh
|
||||
lineObjName = line
|
||||
mainAnchorName = pipe_main_anchor
|
||||
targetAnchorName = pipe_target_anchor
|
||||
anchorCapName = pipe_main_cap
|
||||
targetCapName = pipe_target_cap
|
||||
targetColliderName = pipe_target_SPHERECOLLIDER
|
||||
stretchAxis = x
|
||||
stretchTextures = _MainTex _BumpMap
|
||||
}
|
||||
|
||||
MODULE
|
||||
{
|
||||
name = ModulePartVariants
|
||||
useMultipleDragCubes = false
|
||||
baseVariant = Yellow
|
||||
VARIANT
|
||||
{
|
||||
name = Yellow
|
||||
displayName = #LOC_Restock_variant-surface_yellow
|
||||
themeName = YellowAndWhite
|
||||
primaryColor = #B08D43
|
||||
secondaryColor = #999999
|
||||
GAMEOBJECTS
|
||||
{
|
||||
line_yellow = true
|
||||
line_black = false
|
||||
line_metal = false
|
||||
line_sofi = false
|
||||
}
|
||||
}
|
||||
|
||||
VARIANT
|
||||
{
|
||||
name = Black
|
||||
displayName = #LOC_Restock_variant-surface_black
|
||||
themeName = Dark
|
||||
primaryColor = #4c4f47
|
||||
secondaryColor = #999999
|
||||
GAMEOBJECTS
|
||||
{
|
||||
line_yellow = false
|
||||
line_black = true
|
||||
line_metal = false
|
||||
line_sofi = false
|
||||
}
|
||||
}
|
||||
|
||||
VARIANT
|
||||
{
|
||||
name = Metal // 🤘
|
||||
displayName = #LOC_Restock_variant-surface_metal
|
||||
themeName = Metal
|
||||
primaryColor = #6f6e6d
|
||||
secondaryColor = #999999
|
||||
GAMEOBJECTS
|
||||
{
|
||||
line_yellow = false
|
||||
line_black = false
|
||||
line_metal = true
|
||||
line_sofi = false
|
||||
}
|
||||
}
|
||||
|
||||
VARIANT
|
||||
{
|
||||
name = Orange
|
||||
displayName = #autoLOC_8007123
|
||||
themeName = Orange
|
||||
primaryColor = #B08D43
|
||||
secondaryColor = #999999
|
||||
GAMEOBJECTS
|
||||
{
|
||||
line_yellow = false
|
||||
line_black = false
|
||||
line_metal = false
|
||||
line_sofi = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
// Patches applying art changes to the strut
|
||||
// Contents:
|
||||
// - EAS-4 Strut Connector (strutConnector)
|
||||
|
||||
// EAS-4 Strut Connector
|
||||
@PART[strutConnector]
|
||||
{
|
||||
@author = Andrew Cassidy
|
||||
|
||||
!mesh = DELETE
|
||||
MODEL
|
||||
{
|
||||
model = ReStock/Assets/CompoundParts/restock-strut-1
|
||||
}
|
||||
rescaleFactor = 1.0
|
||||
!scale = DELETE
|
||||
|
||||
!MODULE[CModuleLinkedMesh] {}
|
||||
MODULE
|
||||
{
|
||||
name = ModuleRestockLinkedMesh
|
||||
lineObjName = strut
|
||||
mainAnchorName = strut_main_anchor
|
||||
targetAnchorName = strut_target_anchor
|
||||
anchorCapName = strut_main_cap
|
||||
targetCapName = strut_target_cap
|
||||
targetColliderName = strut_target_SPHERECOLLIDER
|
||||
stretchAxis = x
|
||||
stretchTextures = _MainTex _BumpMap
|
||||
}
|
||||
|
||||
MODULE
|
||||
{
|
||||
name = ModulePartVariants
|
||||
useMultipleDragCubes = false
|
||||
baseVariant = Classic
|
||||
VARIANT
|
||||
{
|
||||
name = Classic
|
||||
displayName = #LOC_Restock_variant-mounting_classic
|
||||
themeName = White
|
||||
primaryColor = #6f6e6d
|
||||
secondaryColor = #999999
|
||||
GAMEOBJECTS
|
||||
{
|
||||
strut_main_body_classic = true
|
||||
strut_target_body_classic = true
|
||||
strut_main_body_compact = false
|
||||
strut_target_body_compact = false
|
||||
}
|
||||
}
|
||||
|
||||
VARIANT
|
||||
{
|
||||
name = Compact
|
||||
displayName = #LOC_Restock_variant-mounting_compact
|
||||
themeName = White
|
||||
primaryColor = #6f6e6d
|
||||
secondaryColor = #999999
|
||||
GAMEOBJECTS
|
||||
{
|
||||
strut_main_body_classic = false
|
||||
strut_target_body_classic = false
|
||||
strut_main_body_compact = true
|
||||
strut_target_body_compact = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Binary file not shown.
@ -26,6 +26,7 @@ Squad/Parts/Command/probeStackLarge/
|
||||
Squad/Parts/Command/probeStackSmall/
|
||||
Squad/Parts/Command/probeStackSphere_v2/
|
||||
Squad/Parts/Command/probeRoverBody_v2/
|
||||
Squad/Parts/CompoundParts/
|
||||
Squad/Parts/Coupling/Assets/Decoupler_0.mu
|
||||
Squad/Parts/Coupling/Assets/Decoupler_1.mu
|
||||
Squad/Parts/Coupling/Assets/Decoupler_2.mu
|
||||
|
@ -26,6 +26,9 @@ v0.2.0
|
||||
- Pegasus I Mobility Enhancer (Nertea)
|
||||
- Kelus Mobility Enhancer (Nertea)
|
||||
- Kelus-LV Bay Mobility Enhancer (Nertea)
|
||||
- Compound Parts
|
||||
- FTX-2 External Fuel Duct (Andrew)
|
||||
- EAS-4 Strut Connector (Andrew)
|
||||
- Making History parts replaced:
|
||||
- Fuel Tanks
|
||||
- FL-C1000 Fuel Tank (Nertea)
|
||||
@ -40,6 +43,24 @@ v0.2.0
|
||||
- FL-R5 RCS Fuel Tank (Nertea)
|
||||
- Thermal
|
||||
- Heat Shield (1.875m) (Nertea): new Unpainted, Classic, Black variants
|
||||
- New Depth Mask module added
|
||||
- Some parts can now be inset into other parts without visible clipping inside them
|
||||
- Aero
|
||||
- Circular Intake
|
||||
- Small Circular Intake
|
||||
- Shock Cone Intake
|
||||
- Adjustable Ramp Intake
|
||||
- Adjustable Ramp Intake (radial)
|
||||
- Radial Air Intake
|
||||
- Mk1 Inline Air Intake
|
||||
- Engines
|
||||
- J-33 "Wheesley" Turbofan
|
||||
- J-404 "Panther" Afterburning Turbofan
|
||||
- J-X4 "Whiplash" Turbo Ramjet
|
||||
- J-20 "Juno" Basic Jet
|
||||
- Electrical
|
||||
- OX-4L 1x6 Solar Panels
|
||||
- OX-4W 3x2 Solar Panels
|
||||
|
||||
v0.1.4
|
||||
------
|
||||
|
@ -62,9 +62,9 @@ Localization
|
||||
#LOC_RestockPlus_restock-reactionwheel-radial-1_description = Steadler's small radial gyroscope provides a small amount of torque but with greater power efficiency, allowing even large stations to maintain attitude with minimal power. We're still not entirely sure how gyroscopes work, but this one allows torque on all three axes.
|
||||
#LOC_RestockPlus_restock-reactionwheel-radial-1_tags = cmg command control fly gyro moment react stab steer torque magic_spinny_thing restock
|
||||
|
||||
#LOC_RestockPlus_reactionwheel-1875-1_title = Medium Reaction Wheel Assembly
|
||||
#LOC_RestockPlus_reactionwheel-1875-1_description = We purchased several of these gyroscope modules to ensure we could accurately control our medium sized rockets in all phases of flight.
|
||||
#LOC_RestockPlus_reactionwheel-1875-1_tags = restock cmg command control fly gyro moment react stab steer torque magic_spinny_thing
|
||||
#LOC_RestockPlus_restock-reactionwheel-1875-1_title = Medium Reaction Wheel Assembly
|
||||
#LOC_RestockPlus_restock-reactionwheel-1875-1_description = We purchased several of these gyroscope modules to ensure we could accurately control our medium sized rockets in all phases of flight.
|
||||
#LOC_RestockPlus_restock-reactionwheel-1875-1_tags = restock cmg command control fly gyro moment react stab steer torque magic_spinny_thing
|
||||
|
||||
// RCS
|
||||
#LOC_RestockPlus_restock-rcs-block-dual-1_title = RV-102 RCS Thruster Block
|
||||
|
@ -95,4 +95,10 @@ PART
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MODULE
|
||||
{
|
||||
name = ModuleRestockDepthMask
|
||||
maskTransform = mask
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,11 @@ v0.2.0
|
||||
- New Resources parts
|
||||
- Jumbo Holding Tank (Andrew Cassidy): 3.75m ore tank
|
||||
- Medium Holding Tank (Andrew Cassidy): 1.875m ore tank
|
||||
New Utility parts
|
||||
- New Utility parts
|
||||
- Pegasus II Mobility Enhancer (Nertea): 2x size static ladder
|
||||
- Pegasus III Mobility Enhancer (Nertea): 4x size static ladder
|
||||
- Updated parts
|
||||
- Depth mask added to radial material bay
|
||||
|
||||
v0.1.4
|
||||
------
|
||||
|
125
Source/Restock/ModuleRestockDepthMask.cs
Normal file
125
Source/Restock/ModuleRestockDepthMask.cs
Normal file
@ -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<MeshRenderer>();
|
||||
|
||||
windowRenderer.material.shader = depthShader;
|
||||
windowRenderer.material.renderQueue = maskRenderQueue;
|
||||
|
||||
var meshRenderers = bodyTransformObject.GetComponentsInChildren<MeshRenderer>(true);
|
||||
var skinnedMeshRenderers = bodyTransformObject.GetComponentsInChildren<SkinnedMeshRenderer>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
Source/Restock/ModuleRestockLinkedMesh.cs
Normal file
113
Source/Restock/ModuleRestockLinkedMesh.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using UnityEngine;
|
||||
using CompoundParts;
|
||||
|
||||
namespace Restock
|
||||
{
|
||||
/* Extends the stock CModuleLinkedMesh used on struts and pipes to make pipe textures repeat instead of stretch when
|
||||
a pipe is extended beyond its default length */
|
||||
|
||||
public class ModuleRestockLinkedMesh : CModuleLinkedMesh
|
||||
{
|
||||
// the direction along the texture that the pipe points. set to "x" or "y"
|
||||
[KSPField]
|
||||
public string stretchAxis = "x";
|
||||
|
||||
// space-seperated list of textures to be effected by the length, preferably all of the ones on the material
|
||||
// Unity has no good way to get all the texture names attached to a material so it has to be set manually, unfortunately
|
||||
[KSPField]
|
||||
public string stretchTextures = "_MainTex";
|
||||
|
||||
|
||||
// reference to the material we will be modifying
|
||||
private Material[] pipeMaterials;
|
||||
|
||||
// array of property IDs corresponding to the textures
|
||||
private int[] pipeMaterialIDs;
|
||||
|
||||
// index of the texture scale vector, 0 for x, 1 for y
|
||||
private int pipeStretchIndex;
|
||||
|
||||
// initial scale of the pipe object, may not be 1
|
||||
private float baseStretch;
|
||||
|
||||
// scale vector for the material
|
||||
private Vector2 texScale = Vector2.one;
|
||||
|
||||
// offset vector for the material
|
||||
private Vector2 texOffset = Vector2.zero;
|
||||
|
||||
|
||||
public override void OnStart(StartState state)
|
||||
{
|
||||
base.OnStart(state);
|
||||
|
||||
// get all materials on the line object, including disabled ones
|
||||
var renderers = line.GetComponentsInChildren<MeshRenderer>(true);
|
||||
pipeMaterials = new Material[renderers.Length];
|
||||
for (int i = 0; i < renderers.Length; i++)
|
||||
{
|
||||
pipeMaterials[i] = renderers[i].material;
|
||||
}
|
||||
|
||||
// split texture list and convert to property IDs for easy access
|
||||
var texNames = stretchTextures.Split(' ');
|
||||
pipeMaterialIDs = new int[texNames.Length];
|
||||
for (int i = 0; i < texNames.Length; i++)
|
||||
{
|
||||
pipeMaterialIDs[i] = Shader.PropertyToID(texNames[i]);
|
||||
}
|
||||
|
||||
// default to 'x' if an invalid value is used
|
||||
pipeStretchIndex = stretchAxis != "y" ? 0 : 1;
|
||||
baseStretch = part.scaleFactor;
|
||||
|
||||
GameEvents.onEditorVariantApplied.Add(OnVariantApplied);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
GameEvents.onEditorVariantApplied.Remove(OnVariantApplied);
|
||||
}
|
||||
|
||||
public override void OnTargetSet(Part newTarget)
|
||||
{
|
||||
base.OnTargetSet(newTarget);
|
||||
UpdateStretch();
|
||||
}
|
||||
|
||||
public override void OnTargetUpdate()
|
||||
{
|
||||
base.OnTargetUpdate();
|
||||
UpdateStretch();
|
||||
}
|
||||
|
||||
public override void OnPreviewAttachment(Vector3 rDir, Vector3 rPos, Quaternion rRot)
|
||||
{
|
||||
base.OnPreviewAttachment(rDir, rPos, rRot);
|
||||
UpdateStretch();
|
||||
}
|
||||
|
||||
public void OnVariantApplied(Part appliedPart, PartVariant variant)
|
||||
{
|
||||
if (appliedPart == part) UpdateStretch();
|
||||
}
|
||||
|
||||
// updates the texture stretch to match the pipe object's local scale
|
||||
private void UpdateStretch()
|
||||
{
|
||||
var stretch = line.localScale.z / baseStretch;
|
||||
|
||||
texScale[pipeStretchIndex] = stretch;
|
||||
texOffset[pipeStretchIndex] = (1 - stretch) / 2;
|
||||
|
||||
foreach (var material in pipeMaterials)
|
||||
{
|
||||
foreach (var id in pipeMaterialIDs)
|
||||
{
|
||||
material.SetTextureScale(id, texScale);
|
||||
material.SetTextureOffset(id, texOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -47,6 +47,8 @@
|
||||
<Compile Include="MaterialModifiers\IMaterialModifier.cs" />
|
||||
<Compile Include="MaterialModifiers\MaterialModifierParser.cs" />
|
||||
<Compile Include="MaterialModifiers\TexturePropertyMaterialModifier.cs" />
|
||||
<Compile Include="ModuleRestockLinkedMesh.cs" />
|
||||
<Compile Include="ModuleRestockDepthMask.cs" />
|
||||
<Compile Include="ModuleRestockModifyFairingMaterials.cs" />
|
||||
<Compile Include="ModuleRestockModifyMaterials.cs" />
|
||||
<Compile Include="PartModuleExtensions.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user