Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add warning for freezing animated BlendShapes #719

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions Editor/Processors/SkinnedMeshes/FreezeBlendShapeProcessor.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<string> freezeNames
HashSet<string> freezeNames,
bool withWarning = false
)
{
// Warn for blendShape animation
if (withWarning) {
var modified = new HashSet<string>();
var sources = new HashSet<Object>();
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);
Expand Down
6 changes: 6 additions & 0 deletions Localization/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved
"The animation will not work. This might not be intended, but if it's intended, ignore this warning.\n"
"{0}"

# endregion

# region MakeChildren
Expand Down
6 changes: 6 additions & 0 deletions Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ msgstr "すべて有効にする"
msgid "FreezeBlendShape:button:Invert All"
msgstr "すべての有効/無効を入れ替える"

msgid "FreezeBlendShape:warning:animation"
msgstr ""
"以下のアニメーションされてるBlendShapeを固定・削除しています。"
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved
"そのBlendShapeのアニメーションは機能しなくなります。意図的に行っている場合はこの警告を無視してください。\n"
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved
"{0}"

# endregion

# region MakeChildren
Expand Down