mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Add size calculation modes
This commit is contained in:
parent
a386281fb2
commit
e27267c862
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -6,6 +6,15 @@ using UnityEngine;
|
||||
|
||||
namespace ConformalDecals {
|
||||
public class ModuleConformalDecal : PartModule {
|
||||
public enum DecalScaleMode {
|
||||
HEIGHT,
|
||||
WIDTH,
|
||||
AVERAGE,
|
||||
AREA,
|
||||
MINIMUM,
|
||||
MAXIMUM
|
||||
}
|
||||
|
||||
// CONFIGURABLE VALUES
|
||||
|
||||
/// <summary>
|
||||
@ -44,6 +53,7 @@ namespace ConformalDecals {
|
||||
[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);
|
||||
|
Loading…
Reference in New Issue
Block a user