Skip to content

Commit 7d289eb

Browse files
committedMay 13, 2024
Skip missing source blend shapes and tell the user
System.ArgumentException: Blend shape index out of range with multiple blend shapes is only expected if a source blend shape is deleted at some point prior to this tool running. See #54
1 parent 48227b8 commit 7d289eb

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed
 

‎Packages/enitimeago.non-destructive-mmd/Editor/BlendShapeMappingsPass.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,26 @@ internal void Execute(GameObject avatarRootObject)
8282
foreach (var mapping in mappingsComponent.blendShapeMappings)
8383
{
8484
string destBlendShape = mapping.Key;
85+
var sourceBlendShapes = mapping.Value;
86+
87+
// It may be possible for a source blend shape to no longer exist, for example if another tool removes it. Report these to the user.
88+
// TODO: add test.
89+
var missingBlendShapes = sourceBlendShapes.Where(sourceBlendShape => originalMesh.GetBlendShapeIndex(sourceBlendShape.Key) < 0);
90+
if (missingBlendShapes.Any())
91+
{
92+
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:MissingSourceBlendShape", destBlendShape, string.Join(",", missingBlendShapes.Select(x => x.Key)), sourceBlendShapes.Count);
93+
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:SkippingMmdMorph", destBlendShape);
94+
continue;
95+
}
8596

8697
// Run simple copies of single blend shapes. This allows multiple frames.
8798
// TODO add test for scaling.
8899
if (mapping.Value.Count == 1)
89100
{
90-
string sourceBlendShape = mapping.Value.First().Key;
101+
string sourceBlendShape = sourceBlendShapes.First().Key;
91102
int sourceBlendShapeIndex = originalMesh.GetBlendShapeIndex(sourceBlendShape);
92103
int sourceBlendShapeFrames = originalMesh.GetBlendShapeFrameCount(sourceBlendShapeIndex);
93-
float scale = mapping.Value.First().Value.scale;
104+
float scale = sourceBlendShapes.First().Value.scale;
94105
Debug.Log($"Create MMD shape key {destBlendShape} (scale={scale}) as copy of {sourceBlendShape} (found {sourceBlendShape} as index {sourceBlendShapeIndex})");
95106
for (int f = 0; f < sourceBlendShapeFrames; f++)
96107
{
@@ -111,7 +122,6 @@ internal void Execute(GameObject avatarRootObject)
111122
// Multiple blend shapes have their deltas combined.
112123
else
113124
{
114-
var sourceBlendShapes = mapping.Value;
115125
if (sourceBlendShapes
116126
.Select(sourceBlendShape => originalMesh.GetBlendShapeIndex(sourceBlendShape.Key))
117127
.Select(originalMesh.GetBlendShapeFrameCount)
@@ -120,6 +130,7 @@ internal void Execute(GameObject avatarRootObject)
120130
// Do not handle multiple frames for now, as it's not common and interpolation doesn't seem straightforward.
121131
// TODO: show error in the UI as well.
122132
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:CombiningWithMultipleFramesUnsupported");
133+
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:SkippingMmdMorph", destBlendShape);
123134
continue;
124135
}
125136

‎Packages/enitimeago.non-destructive-mmd/Editor/Localization/en-us.po

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ msgstr "English"
88
msgid "BlendShapeMappingsPass:CombiningWithMultipleFramesUnsupported"
99
msgstr "Currently, combining multiple blend shapes with more than one frame is unsupported. Please contact the developer if you would like to request this feature."
1010

11+
msgid "BlendShapeMappingsPass:MissingSourceBlendShapes"
12+
msgstr "MMD morph \"{0}\" references blend shape(s) {1} (when combining {2} blend shapes) that weren't found. These blend shape(s) may have been removed by other tools in your Unity project. If this is unexpected, please report this to the developer along with the tools installed in your project if possible."
13+
14+
msgid "BlendShapeMappingsPass:SkippingMmdMorph"
15+
msgstr "Found error(s) when generating MMD morph \"{0}\". This MMD blend shape will not be generated."
16+
1117
msgid "CommonChecks:NoMMDComponents"
1218
msgstr "No Make It MMD component found in avatar. Nothing to do"
1319

‎Packages/enitimeago.non-destructive-mmd/Editor/Localization/ja-jp.po

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ msgstr "日本語"
88
msgid "BlendShapeMappingsPass:CombiningWithMultipleFramesUnsupported"
99
msgstr "現在、複数のブレンドシェイプを複数フレームで組み合わせることはサポートされていません。この機能をリクエストしたい場合は、本ツールの開発者にお問い合わせしてお願いいたします。"
1010

11+
msgid "BlendShapeMappingsPass:MissingSourceBlendShapes"
12+
msgstr "MMDモーフ「{0}」は、ブレンドシェイプを組み合わせる際({1}個のブレンドシェイプを組み合わせる中)に参照されるブレンドシェイプ {1} を探しましたが、見つかりませんでした。これらのブレンドシェイプは、Unityプロジェクトの他のツールによって削除された可能性があります。これが予期しないものである場合は、可能であればプロジェクトにインストールされているツールと共に、この問題を開発者に報告していただければ幸いです。"
13+
14+
msgid "BlendShapeMappingsPass:SkippingMmdMorph"
15+
msgstr "MMDモーフ「{0}」を生成する際にエラーが発見されました。このMMDブレンドシェイプは生成しません。"
16+
1117
msgid "CommonChecks:NoMMDComponents"
1218
msgstr "アバターにMake It MMDコンポーネントが見つかりません。処理するものがありません"
1319

0 commit comments

Comments
 (0)