diff --git a/BetterShadowClone/ShadowClone/IShadowClone/SkinnedShadowClone.cs b/BetterShadowClone/ShadowClone/IShadowClone/SkinnedShadowClone.cs index 70fbdc1..71e86a6 100644 --- a/BetterShadowClone/ShadowClone/IShadowClone/SkinnedShadowClone.cs +++ b/BetterShadowClone/ShadowClone/IShadowClone/SkinnedShadowClone.cs @@ -118,14 +118,12 @@ public class SkinnedShadowClone : IShadowClone { // Cleanup instanced Mesh & Materials GameObject shadowMeshObject = _shadowMesh.gameObject; - UnityEngine.Object.Destroy(_shadowMeshFilter.sharedMesh); + UnityEngine.Object.Destroy(_shadowMeshFilter.mesh); UnityEngine.Object.Destroy(_shadowMeshFilter); - - if (!_hasShadowMaterials) - { - var materials = _shadowMesh.sharedMaterials; - foreach (Material mat in materials) UnityEngine.Object.Destroy(mat); - } + + // explain why this works + if (_hasShadowMaterials) _shadowMesh.sharedMaterials = _mainMesh.sharedMaterials; + foreach (Material mat in _shadowMesh.sharedMaterials) UnityEngine.Object.Destroy(mat); UnityEngine.Object.Destroy(_shadowMesh); UnityEngine.Object.Destroy(shadowMeshObject); diff --git a/BetterShadowClone/ShadowCloneHelper.cs b/BetterShadowClone/ShadowCloneHelper.cs index 58d9824..c96b76c 100644 --- a/BetterShadowClone/ShadowCloneHelper.cs +++ b/BetterShadowClone/ShadowCloneHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ABI_RC.Core; +using ABI.CCK.Components; using UnityEngine; using UnityEngine.Rendering; using Object = UnityEngine.Object; @@ -69,6 +70,14 @@ public static class ShadowCloneHelper // add an fpr exclusion to the head bone headBone.gameObject.AddComponent().target = headBone; + // add an FPRExclusion for all target entries on CVRAvatar (Experimental feature) + CVRAvatar avatar = root.GetComponent(); + if (avatar != null) + { + foreach (CVRAvatarFPREntry fprEntry in avatar.fprSettingsList.Where(fprEntry => fprEntry.transform != null)) + fprEntry.transform.gameObject.AddComponent().target = fprEntry.transform; + } + // get all FPRExclusions var fprExclusions = root.GetComponentsInChildren(true).ToList(); @@ -83,7 +92,8 @@ public static class ShadowCloneHelper continue; } - exclusionTargets.Add(exclusion.target, exclusion); + // first to add wins + exclusionTargets.TryAdd(exclusion.target, exclusion); } // process each FPRExclusion (recursive)