From a6b61ba24ab0d2e5fae400d5ab9ababce72e30f0 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 13 Nov 2023 13:10:30 +0900 Subject: [PATCH 1/4] feat: add warning for freezing animated BlendShapes --- .../FreezeBlendShapeProcessor.cs | 31 +++++++++++++++++-- Localization/en.po | 6 ++++ Localization/ja.po | 6 ++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Editor/Processors/SkinnedMeshes/FreezeBlendShapeProcessor.cs b/Editor/Processors/SkinnedMeshes/FreezeBlendShapeProcessor.cs index b6f963fe6..9d5a8dc66 100644 --- a/Editor/Processors/SkinnedMeshes/FreezeBlendShapeProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/FreezeBlendShapeProcessor.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using Anatawa12.AvatarOptimizer.ErrorReporting; using nadena.dev.ndmf; using UnityEngine; using UnityEngine.Profiling; @@ -17,16 +18,42 @@ public FreezeBlendShapeProcessor(FreezeBlendShape component) : base(component) public override void Process(BuildContext context, MeshInfo2 target) { - FreezeBlendShapes(Target, context, target, Component.FreezingShapeKeys); + FreezeBlendShapes(Target, context, target, Component.FreezingShapeKeys, true); } public static void FreezeBlendShapes( SkinnedMeshRenderer targetSMR, BuildContext context, MeshInfo2 target, - HashSet freezeNames + HashSet freezeNames, + bool withWarning = false ) { + // Warn for blendShape animation + if (withWarning) { + var modified = new HashSet(); + var sources = new HashSet(); + var animationComponent = context.GetAnimationComponent(targetSMR); + + foreach (var blendShape in freezeNames) + { + if (animationComponent.TryGetFloat($"blendShape.{blendShape}", out var p)) + { + modified.Add(blendShape); + foreach (var source in p.Sources) + sources.Add(source); + } + } + + if (modified.Count != 0) + { + // ReSharper disable once CoVariantArrayConversion + BuildReport.LogWarning("FreezeBlendShape:warning:animation", string.Join(", ", modified)) + ?.WithContext(targetSMR) + ?.WithContext(sources.ToArray()); + } + } + var freezes = new BitArray(target.BlendShapes.Count); for (var i = 0; i < target.BlendShapes.Count; i++) freezes[i] = freezeNames.Contains(target.BlendShapes[i].name); diff --git a/Localization/en.po b/Localization/en.po index e46bd5b42..c260788c8 100644 --- a/Localization/en.po +++ b/Localization/en.po @@ -77,6 +77,12 @@ msgstr "Check All" msgid "FreezeBlendShape:button:Invert All" msgstr "Invert All" +msgid "FreezeBlendShape:warning:animation" +msgstr "" +"You're freezing the following animated blendShapes." +"The animation will not work. This might not be intended, but if it's intended, ignore this warning.\n" +"{0}" + # endregion # region MakeChildren diff --git a/Localization/ja.po b/Localization/ja.po index be917beb0..ae0c6d702 100644 --- a/Localization/ja.po +++ b/Localization/ja.po @@ -80,6 +80,12 @@ msgstr "すべて有効にする" msgid "FreezeBlendShape:button:Invert All" msgstr "すべての有効/無効を入れ替える" +msgid "FreezeBlendShape:warning:animation" +msgstr "" +"以下のアニメーションされてるBlendShapeを固定・削除しています。" +"そのBlendShapeのアニメーションは機能しなくなります。意図的に行っている場合はこの警告を無視してください。\n" +"{0}" + # endregion # region MakeChildren From cd63ba6a15a724b8a2377f2f141b12e99059ae54 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 13 Nov 2023 15:06:59 +0900 Subject: [PATCH 2/4] chore(localization): Apply suggestions from code review Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> --- Localization/en.po | 2 +- Localization/ja.po | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Localization/en.po b/Localization/en.po index c260788c8..a0c97ab4b 100644 --- a/Localization/en.po +++ b/Localization/en.po @@ -79,7 +79,7 @@ msgstr "Invert All" msgid "FreezeBlendShape:warning:animation" msgstr "" -"You're freezing the following animated blendShapes." +"You're freezing the following animated BlendShapes." "The animation will not work. This might not be intended, but if it's intended, ignore this warning.\n" "{0}" diff --git a/Localization/ja.po b/Localization/ja.po index ae0c6d702..0e1b0932b 100644 --- a/Localization/ja.po +++ b/Localization/ja.po @@ -82,8 +82,8 @@ msgstr "すべての有効/無効を入れ替える" msgid "FreezeBlendShape:warning:animation" msgstr "" -"以下のアニメーションされてるBlendShapeを固定・削除しています。" -"そのBlendShapeのアニメーションは機能しなくなります。意図的に行っている場合はこの警告を無視してください。\n" +"固定・除去対象である以下のBlendShapeはアニメーションされています。" +"固定・除去されたBlendShapeはアニメーションで動かせなくなります。意図的に行っている場合はこの警告を無視してください。\n" "{0}" # endregion From 6a08addc0b9a580e90f2c3cf4ddf0229730fabff Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 13 Nov 2023 15:15:54 +0900 Subject: [PATCH 3/4] docs(changelog): Warning for freezing animated BlendShapes --- CHANGELOG-PRERELEASE.md | 1 + CHANGELOG.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 10f9ab1ce..9d5fd1d4d 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Added +- Warning for freezing animated BlendShapes `#719` ### Changed diff --git a/CHANGELOG.md b/CHANGELOG.md index fecf155de..ce123a927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ The format is based on [Keep a Changelog]. - Support for Mesh Topologies other than Triangles `#692` - Skip enablement mismatched Renderers in Merge Skinned Mesh `#670` - This is now enabled by default for newly added Merge Skinned Mesh. +- Warning for conflicts with animation + - Warning for freezing animated BlendShapes `#719` ### Changed - All logs passed to ErrorReport is now shown on the console log `#643` From 40fe037e0616022a3274fd96016b29abf67c82fb Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 13 Nov 2023 15:16:15 +0900 Subject: [PATCH 4/4] docs(changelog): move warning about merge SMR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce123a927..4f2d31035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,13 +20,13 @@ The format is based on [Keep a Changelog]. - This is now enabled by default for newly added Merge Skinned Mesh. - Warning for conflicts with animation - Warning for freezing animated BlendShapes `#719` + - Warning for merging renderers that activeness/enablement animated differently `#675` ### Changed - All logs passed to ErrorReport is now shown on the console log `#643` - Improved Behaviour with multi-material multi pass rendering `#662` - Previously, multi-material multi pass rendering are flattened. - Since 1.6, flattened if component doesn't support that. -- When you're animating activeness/enablement of source renderers, warning is shown since this release `#675` - Remove Unused Objects removes meaningless Animators and Renderers `#709` - Renderers without Mesh and Animators without AnimatorController is meaningless