Skip to content

Commit

Permalink
Layers with only a off animation no longer block default disabled mes…
Browse files Browse the repository at this point in the history
…hes from using NaNimation. #126
  • Loading branch information
d4rkc0d3r committed Oct 6, 2024
1 parent 771918a commit a8d1545
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 13 additions & 15 deletions Editor/d4rkAvatarOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -778,14 +778,14 @@ public bool CanUseNaNimationOnMesh(string path)
var renderer = GetTransformFromPath(path)?.GetComponent<Renderer>();
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<string> cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation = null;
public HashSet<string> FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation()
private HashSet<string> cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation = null;
public HashSet<string> FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation()
{
if (cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation == null) {
cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation = new HashSet<string>();
if (cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation == null) {
cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation = new HashSet<string>();
var goOffPaths = new HashSet<string>();
var goOnPaths = new HashSet<string>();
var meshOffPaths = new HashSet<string>();
Expand Down Expand Up @@ -827,18 +827,16 @@ public HashSet<string> 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<MeshRenderer>() == null && t.GetComponent<SkinnedMeshRenderer>() == null))
cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation.Remove(path);
cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation.Remove(path);
}
}
return cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnOrOffAnimation;
return cache_FindAllPathsWhereMeshOrGameObjectHasOnlyOnAnimation;
}

private Dictionary<string, HashSet<AnimationClip>> cache_FindAllAnimationClipsAffectingRenderer = null;
Expand Down Expand Up @@ -2109,9 +2107,9 @@ private HashSet<AnimationClip> 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);
Expand Down
2 changes: 1 addition & 1 deletion Editor/d4rkAvatarOptimizerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Renderer>())
Expand Down

0 comments on commit a8d1545

Please sign in to comment.