From a8d154513c5024b45b553c78dc6fb1bd6ed4240d Mon Sep 17 00:00:00 2001 From: d4rkc0d3r <1735522+d4rkc0d3r@users.noreply.github.com> Date: Sun, 6 Oct 2024 16:28:29 +0200 Subject: [PATCH] Layers with only a off animation no longer block default disabled meshes from using NaNimation. #126 --- CHANGELOG.md | 1 + Editor/d4rkAvatarOptimizer.cs | 28 +++++++++++++--------------- Editor/d4rkAvatarOptimizerEditor.cs | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72042fa..53e8aa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * Shader parser now handles `ColorMask 0` passes with no code block correctly and throws a parse error for other non code block passes. * Fix optimizer not checking all the animator controllers in the avatar descriptor for some things. * Fix special animation layers not getting updated animation clips. +* Layers with only a off animation no longer block default disabled meshes from using NaNimation. [(more)](https://github.com/d4rkc0d3r/d4rkAvatarOptimizer/issues/126) ## v3.8.0 ### Features diff --git a/Editor/d4rkAvatarOptimizer.cs b/Editor/d4rkAvatarOptimizer.cs index 1b8d8f5..d51e85c 100644 --- a/Editor/d4rkAvatarOptimizer.cs +++ b/Editor/d4rkAvatarOptimizer.cs @@ -663,7 +663,7 @@ public long GetPolyCount() private static bool IsMaterialReadyToCombineWithOtherMeshes(Material material) { - return material == null ? false : ShaderAnalyzer.Parse(material.shader).CanMerge(); + return material != null && ShaderAnalyzer.Parse(material.shader).CanMerge(); } private bool IsBasicCombinableRenderer(Renderer candidate) @@ -778,14 +778,14 @@ public bool CanUseNaNimationOnMesh(string path) var renderer = GetTransformFromPath(path)?.GetComponent(); if (renderer == null) return cache_CanUseNaNimationOnMesh[path] = false; - return cache_CanUseNaNimationOnMesh[path] = GetRendererDefaultEnabledState(renderer) || !FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation().Contains(path); + return cache_CanUseNaNimationOnMesh[path] = GetRendererDefaultEnabledState(renderer) || !FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation().Contains(path); } - private HashSet cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation = null; - public HashSet FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation() + private HashSet cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation = null; + public HashSet FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation() { - if (cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation == null) { - cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation = new HashSet(); + if (cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation == null) { + cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation = new HashSet(); var goOffPaths = new HashSet(); var goOnPaths = new HashSet(); var meshOffPaths = new HashSet(); @@ -827,18 +827,16 @@ public HashSet FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation( } } } - cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation.UnionWith(goOffPaths.Except(goOnPaths)); - cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation.UnionWith(goOnPaths.Except(goOffPaths)); - cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation.UnionWith(meshOffPaths.Except(meshOnPaths)); - cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation.UnionWith(meshOnPaths.Except(meshOffPaths)); + cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation.UnionWith(goOnPaths.Except(goOffPaths)); + cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation.UnionWith(meshOnPaths.Except(meshOffPaths)); } - foreach (var path in cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation.ToList()) { + foreach (var path in cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation.ToList()) { var t = GetTransformFromPath(path); if (t == null || (t.GetComponent() == null && t.GetComponent() == null)) - cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation.Remove(path); + cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation.Remove(path); } } - return cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation; + return cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation; } private Dictionary> cache_FindAllAnimationClipsAffectingRenderer = null; @@ -2109,9 +2107,9 @@ private HashSet GetAllUsedAnimationClips() continue; usedClips.UnionWith(controller.animationClips); } - foreach (var clip in avDescriptor.specialAnimationLayers) + foreach (var layer in avDescriptor.specialAnimationLayers) { - var controller = clip.animatorController as AnimatorController; + var controller = layer.animatorController as AnimatorController; if (controller == null) continue; usedClips.UnionWith(controller.animationClips); diff --git a/Editor/d4rkAvatarOptimizerEditor.cs b/Editor/d4rkAvatarOptimizerEditor.cs index 1e105e2..7a69595 100644 --- a/Editor/d4rkAvatarOptimizerEditor.cs +++ b/Editor/d4rkAvatarOptimizerEditor.cs @@ -964,7 +964,7 @@ private Renderer[] CantMergeNaNimationBecauseOfWDONAnimations if (cantMergeNaNimationBecauseOfWDONAnimationsCache != null) return cantMergeNaNimationBecauseOfWDONAnimationsCache; return cantMergeNaNimationBecauseOfWDONAnimationsCache = - optimizer.FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation() + optimizer.FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation() .Select(p => optimizer.GetTransformFromPath(p)) .Where(t => t != null) .Select(t => t.GetComponent())