From 98777f5448480b69011c80ec8c96a3cf694f35ca Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Fri, 14 Jun 2019 13:54:16 -0700 Subject: [PATCH] Update to 1.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Add support for multiple objects sharing the same name • Add support for multiple Depth Mask modules on the same part • Minor code cleanups --- DepthMask/ModuleDepthMask.cs | 37 +++++++++++++++--------------------- README.md | 12 ++++++------ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/DepthMask/ModuleDepthMask.cs b/DepthMask/ModuleDepthMask.cs index fbe171b..2ec16c2 100644 --- a/DepthMask/ModuleDepthMask.cs +++ b/DepthMask/ModuleDepthMask.cs @@ -25,8 +25,8 @@ namespace Restock public int maskRenderQueue = 1999; - // depth mask object transform - public Transform maskTransformObject; + // depth mask object transforms + public Transform[] maskTransformObjects; // body object transform public Transform bodyTransformObject; @@ -38,7 +38,7 @@ namespace Restock public override void OnStart(StartState state) { base.OnStart(state); - UpdatematerialQueue(); + UpdateAllMaterials(); // the part variant system is implemented extremely stupidly // so we have to make this whole module more complicated as a result @@ -58,14 +58,14 @@ namespace Restock if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return; - this.maskTransformObject = base.part.FindModelTransform(maskTransform); - if (this.maskTransformObject == null) + this.maskTransformObjects = base.part.FindModelTransforms(maskTransform); + if (this.maskTransformObjects.Length == 0 || this.maskTransformObjects == null) { this.LogError($"Can't find transform {maskTransform}"); return; } - if (bodyTransform == "") + if (bodyTransform.Length == 0) { this.bodyTransformObject = base.part.partTransform; } @@ -91,34 +91,27 @@ namespace Restock 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(); + if (appliedPart == this.part) UpdateAllMaterials(); } - private void UpdatematerialQueue() + private void UpdateAllMaterials() { - var windowRenderer = maskTransformObject.GetComponent(); + var renderers = bodyTransformObject.GetComponentsInChildren(true); - windowRenderer.material.shader = depthShader; - windowRenderer.material.renderQueue = maskRenderQueue; - - var meshRenderers = bodyTransformObject.GetComponentsInChildren(true); - var skinnedMeshRenderers = bodyTransformObject.GetComponentsInChildren(true); - - foreach (var renderer in meshRenderers) + foreach (var renderer in renderers) { - if (renderer == windowRenderer) continue; var queue = renderer.material.renderQueue; + if (queue <= maskRenderQueue) continue; queue = meshRenderQueue + ((queue - 2000) / 2); renderer.material.renderQueue = queue; } - foreach (var renderer in skinnedMeshRenderers) + foreach (var maskObject in maskTransformObjects) { - if (renderer == windowRenderer) continue; - var queue = renderer.material.renderQueue; - queue = meshRenderQueue + ((queue - 2000) / 2); - renderer.material.renderQueue = queue; + var renderer = maskObject.GetComponent(); + renderer.material.shader = depthShader; + renderer.material.renderQueue = maskRenderQueue; } } diff --git a/README.md b/README.md index b4af642..6f24fe2 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# ModuleDepthMask +# ModuleDepthMask v1.1.0 This plugin allows for parts to have hollow insets that dont clip into other parts, ideal for engine nozzles, landing gear, air intakes, solar panel bays, and more. It is a standalone version of the depth mask module included in the [Restock](github.com/PorktoberRevolution/ReStocked) dll, which will be included in the next major Restock update along with the additon of depth masks to several stock parts ### Usage -1. Add a depth mask mesh to your part model. It should cover up the hollow area you want to prevent clipping in, without sticking out. -2. Mark the depth mask object with the `Icon_Hidden` tag to prevent it from showing in the VAB part picker -3. Add a new `ModuleDepthMask` to your part config -4. Add the name of your mask object in the `maskTransform` property -5. (Optional) Add the name of the object you want to restrict the mask effect to in the `bodyTransform` property +1. Add a depth mask mesh to your part model. It should cover up the hollow area you want to prevent clipping in, without sticking out. You can have multiple mask objects sharing the same name and they will all be used. +2. Mark the depth mask object with the `Icon_Hidden` tag to prevent it from showing in the VAB part picker. +3. Add a new `ModuleDepthMask` to your part config. +4. Add the name of your mask object in the `maskTransform` property. +5. (Optional) Add the name of the object you want to restrict the mask effect to in the `bodyTransform` property. ##### Creating the depth mask model The depth mask will prevent any other parts from rendering behind it. Because of that, it should not be used on any kind of bay where other parts will be placed, or on any part you can look completely through. It also should "bubble" out above the hole you want to cover, otherwise it would be possible to see through it from the side. Also double check your normal direction, since the depth shader only works one way.