diff --git a/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg b/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg index 56c62b5..2042ada 100644 --- a/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg +++ b/Distribution/GameData/ConformalDecals/Parts/Generic/decal-generic.cfg @@ -69,6 +69,7 @@ PART cutoffAdjustable = false scaleRange = 0.1, 4 + scaleMode = AVERAGE shader = ConformalDecals/Paint/Specular @@ -504,7 +505,7 @@ PART IDENTIFIER { name = ModuleConformalDecal } DATA { shader = ConformalDecals/Paint/SpecularSDF - tile = 670, 456, 48, 48 + tile = 710, 456, 48, 48 } } } diff --git a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll index 6deba2e..d9f3ac9 100644 Binary files a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll and b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll differ diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 810eeae..2a05197 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -6,6 +6,15 @@ using UnityEngine; namespace ConformalDecals { public class ModuleConformalDecal : PartModule { + public enum DecalScaleMode { + HEIGHT, + WIDTH, + AVERAGE, + AREA, + MINIMUM, + MAXIMUM + } + // CONFIGURABLE VALUES /// @@ -41,9 +50,10 @@ namespace ConformalDecals { // Parameters - [KSPField] public bool scaleAdjustable = true; - [KSPField] public float defaultScale = 1; - [KSPField] public Vector2 scaleRange = new Vector2(0, 4); + [KSPField] public bool scaleAdjustable = true; + [KSPField] public float defaultScale = 1; + [KSPField] public Vector2 scaleRange = new Vector2(0, 4); + [KSPField] public DecalScaleMode scaleMode = DecalScaleMode.HEIGHT; [KSPField] public bool depthAdjustable = true; [KSPField] public float defaultDepth = 0.1f; @@ -241,6 +251,7 @@ namespace ConformalDecals { var tileValid = ParseExtensions.TryParseRect(tileString, out tileRect); if (!tileValid) throw new FormatException($"Invalid rect value for tile '{tileString}'"); } + if (tileRect.x >= 0) { materialProperties.UpdateTile(tileRect); } @@ -269,6 +280,7 @@ namespace ConformalDecals { depth = defaultDepth; opacity = defaultOpacity; cutoff = defaultCutoff; + wear = defaultWear; } } @@ -405,7 +417,31 @@ namespace ConformalDecals { protected void UpdateScale() { var aspectRatio = materialProperties.AspectRatio; - var size = new Vector2(scale, scale * aspectRatio); + Vector2 size; + + switch (scaleMode) { + default: + case DecalScaleMode.HEIGHT: + size = new Vector2(scale, scale * aspectRatio); + break; + case DecalScaleMode.WIDTH: + size = new Vector2(scale / aspectRatio, scale); + break; + case DecalScaleMode.AVERAGE: + var width1 = 2 * scale / (1 + aspectRatio); + size = new Vector2(width1, width1 * aspectRatio); + break; + case DecalScaleMode.AREA: + var width2 = Mathf.Sqrt(scale / aspectRatio); + size = new Vector2(width2, width2 * aspectRatio); + break; + case DecalScaleMode.MINIMUM: + if (aspectRatio > 1) goto case DecalScaleMode.WIDTH; + else goto case DecalScaleMode.HEIGHT; + case DecalScaleMode.MAXIMUM: + if (aspectRatio > 1) goto case DecalScaleMode.HEIGHT; + else goto case DecalScaleMode.WIDTH; + } // update material scale materialProperties.UpdateScale(size);