Skip to content

Commit

Permalink
Merge pull request #1235 from anatawa12/fix-error-merge-skinned-mesh
Browse files Browse the repository at this point in the history
fix(optimize-texture): error with merge skinned mesh and animation
  • Loading branch information
anatawa12 authored Oct 6, 2024
2 parents 3bd445b + b57dd02 commit 62aa085
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog].

### Fixed
- maxSquish cannot be configured for mergePB`#1231`
- Error from Optimize Texture if there is Merge Skinned Mesh with material slot animation `#1235`

### Security

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The format is based on [Keep a Changelog].
- We may relax some restriction in the future.
- Because we have to check for each condition if we use AnyState but we can check for only one (in best case) with entry/exit, this generally reduces cost for checking an parameter in a state.
- Combined with Entry / Exit to 1D BlendTree optimization, which is implemented in previous release, your AnyState layer may be optimized to 1D BlendTree.
- Optimize Texture in Trace nad Optimize `#1181` `#1184` `#1193` `#1215` `#1225`
- Optimize Texture in Trace nad Optimize `#1181` `#1184` `#1193` `#1215` `#1225` `#1235`
- Avatar Optimizer will pack texture and tries to reduce the VRAM usage.
- Currently liltoon is only supported.
- `Copy Enablement Animation` to Merge Skinned Mesh `#1173`
Expand Down
2 changes: 1 addition & 1 deletion Editor/Processors/TraceAndOptimize/OptimizeTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ internal void RemapVertexUvs(ICollection<(EqualsHashSet<UVID>, AtlasResult)> atl
if (!component.TryGetObject($"m_Materials.Array.data[{materialSlotIndex}]", out var animation))
return (safeToMerge: true, Array.Empty<Material>());

if (animation.ComponentNodes.SingleOrDefault() is AnimatorPropModNode<ObjectValueInfo> componentNode)
if (animation.ComponentNodes.SingleOrDefaultIfNoneOrMultiple() is AnimatorPropModNode<ObjectValueInfo> componentNode)
{
var possibleValues = componentNode.Value.PossibleValues;

Expand Down
9 changes: 9 additions & 0 deletions Internal/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> key
}
}

public static T? SingleOrDefaultIfNoneOrMultiple<T>(this IEnumerable<T> enumerable)
{
using var enumerator = enumerable.GetEnumerator();
if (!enumerator.MoveNext()) return default;
var found = enumerator.Current;
if (enumerator.MoveNext()) return default;
return found;
}

public static T RemoveLast<T>(this IList<T> list)
{
if (list == null) throw new ArgumentNullException(nameof(list));
Expand Down

0 comments on commit 62aa085

Please sign in to comment.