Skip to content

Commit

Permalink
Merge pull request #719 from anatawa12/warn-freeze-animated-blendshape
Browse files Browse the repository at this point in the history
feat: add warning for freezing animated BlendShapes
  • Loading branch information
anatawa12 authored Nov 13, 2023
2 parents 9a8ee48 + 3ff21ed commit ed22c4a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog].
## [Unreleased]
### Added
- Error for MergeBone on the Avatar Root `#716`
- Warning for freezing animated BlendShapes `#719`

### Changed

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ The format is based on [Keep a Changelog].
- Skip enablement mismatched Renderers in Merge Skinned Mesh `#670`
- This is now enabled by default for newly added Merge Skinned Mesh.
- Error for MergeBone on the Avatar Root `#716`
- 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

Expand Down
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."
"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はアニメーションされています。"
"固定・除去されたBlendShapeはアニメーションで動かせなくなります。意図的に行っている場合はこの警告を無視してください。\n"
"{0}"

# endregion

# region MakeChildren
Expand Down

0 comments on commit ed22c4a

Please sign in to comment.