diff --git a/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu b/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu index 9db198c..30116de 100644 Binary files a/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu and b/Distribution/GameData/ConformalDecals/Assets/decal-blank.mu differ diff --git a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll index 7f86499..c3aa17a 100644 Binary files a/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll and b/Distribution/GameData/ConformalDecals/Plugins/ConformalDecals.dll differ diff --git a/Source/ConformalDecals/ConformalDecals.csproj b/Source/ConformalDecals/ConformalDecals.csproj index 912b4f8..01f2a01 100644 --- a/Source/ConformalDecals/ConformalDecals.csproj +++ b/Source/ConformalDecals/ConformalDecals.csproj @@ -51,6 +51,7 @@ + diff --git a/Source/ConformalDecals/DecalBoundsBehaviour.cs b/Source/ConformalDecals/DecalBoundsBehaviour.cs new file mode 100644 index 0000000..4b6cc0b --- /dev/null +++ b/Source/ConformalDecals/DecalBoundsBehaviour.cs @@ -0,0 +1,12 @@ +using System; +using UnityEngine; + +namespace ConformalDecals { + public class DecalBoundsBehaviour : MonoBehaviour { + public ModuleConformalDecal decalRenderer; + + private void OnWillRenderObject() { + decalRenderer._shouldRender = true; + } + } +} \ No newline at end of file diff --git a/Source/ConformalDecals/ModuleConformalDecal.cs b/Source/ConformalDecals/ModuleConformalDecal.cs index 47d5d1e..3d4f3ae 100644 --- a/Source/ConformalDecals/ModuleConformalDecal.cs +++ b/Source/ConformalDecals/ModuleConformalDecal.cs @@ -48,6 +48,8 @@ namespace ConformalDecals { /// [KSPField] public string decalProjector = "Decal-Projector"; + [KSPField] public string decalBounds = "Decal-Bounds"; + // Parameters [KSPField] public bool scaleAdjustable = true; @@ -124,7 +126,8 @@ namespace ConformalDecals { [KSPField] public Transform decalBackTransform; [KSPField] public Transform decalModelTransform; [KSPField] public Transform decalProjectorTransform; - + [KSPField] public Transform decalBoundsTransform; + [KSPField] public Material backMaterial; [KSPField] public Vector2 backTextureBaseScale; @@ -139,6 +142,8 @@ namespace ConformalDecals { private Material _decalMaterial; private Material _previewMaterial; + + internal bool _shouldRender; private int DecalQueue { get { @@ -203,6 +208,15 @@ namespace ConformalDecals { decalProjectorTransform = part.FindModelTransform(decalProjector); if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'."); } + + // find bounds transform + if (string.IsNullOrEmpty(decalBounds)) { + decalBoundsTransform = part.transform; + } + else { + decalBoundsTransform = part.FindModelTransform(decalBounds); + if (decalBoundsTransform == null) throw new FormatException($"Could not find decalBounds transform: '{decalBounds}'."); + } // get back material if necessary if (updateBackScale) { @@ -303,6 +317,9 @@ namespace ConformalDecals { materialProperties.RenderQueue = DecalQueue; + var boundsBehaviour = decalBoundsTransform.gameObject.AddComponent(); + boundsBehaviour.decalRenderer = this; + UpdateMaterials(); if (HighLogic.LoadedSceneIsGame) { @@ -419,6 +436,10 @@ namespace ConformalDecals { UpdateScale(); } + protected void Update() { + _shouldRender = false; + } + protected void UpdateScale() { var aspectRatio = materialProperties.AspectRatio; Vector2 size; @@ -592,9 +613,9 @@ namespace ConformalDecals { } } - protected void Render(Camera camera) { + public void Render(Camera camera) { if (!_isAttached) return; - + // render on each target object foreach (var target in _targets) { target.Render(_decalMaterial, part.mpb, camera);