Skip to content

Commit

Permalink
Skip missing source blend shapes and tell the user
Browse files Browse the repository at this point in the history
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
  • Loading branch information
enitimeago committed May 13, 2024
1 parent 48227b8 commit 7d289eb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,26 @@ internal void Execute(GameObject avatarRootObject)
foreach (var mapping in mappingsComponent.blendShapeMappings)
{
string destBlendShape = mapping.Key;
var sourceBlendShapes = mapping.Value;

// 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.
// TODO: add test.
var missingBlendShapes = sourceBlendShapes.Where(sourceBlendShape => originalMesh.GetBlendShapeIndex(sourceBlendShape.Key) < 0);
if (missingBlendShapes.Any())
{
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:MissingSourceBlendShape", destBlendShape, string.Join(",", missingBlendShapes.Select(x => x.Key)), sourceBlendShapes.Count);
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:SkippingMmdMorph", destBlendShape);
continue;
}

// Run simple copies of single blend shapes. This allows multiple frames.
// TODO add test for scaling.
if (mapping.Value.Count == 1)
{
string sourceBlendShape = mapping.Value.First().Key;
string sourceBlendShape = sourceBlendShapes.First().Key;
int sourceBlendShapeIndex = originalMesh.GetBlendShapeIndex(sourceBlendShape);
int sourceBlendShapeFrames = originalMesh.GetBlendShapeFrameCount(sourceBlendShapeIndex);
float scale = mapping.Value.First().Value.scale;
float scale = sourceBlendShapes.First().Value.scale;
Debug.Log($"Create MMD shape key {destBlendShape} (scale={scale}) as copy of {sourceBlendShape} (found {sourceBlendShape} as index {sourceBlendShapeIndex})");
for (int f = 0; f < sourceBlendShapeFrames; f++)
{
Expand All @@ -111,7 +122,6 @@ internal void Execute(GameObject avatarRootObject)
// Multiple blend shapes have their deltas combined.
else
{
var sourceBlendShapes = mapping.Value;
if (sourceBlendShapes
.Select(sourceBlendShape => originalMesh.GetBlendShapeIndex(sourceBlendShape.Key))
.Select(originalMesh.GetBlendShapeFrameCount)
Expand All @@ -120,6 +130,7 @@ internal void Execute(GameObject avatarRootObject)
// Do not handle multiple frames for now, as it's not common and interpolation doesn't seem straightforward.
// TODO: show error in the UI as well.
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:CombiningWithMultipleFramesUnsupported");
ErrorReport.ReportError(L.Localizer, ErrorSeverity.Information, "BlendShapeMappingsPass:SkippingMmdMorph", destBlendShape);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ msgstr "English"
msgid "BlendShapeMappingsPass:CombiningWithMultipleFramesUnsupported"
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."

msgid "BlendShapeMappingsPass:MissingSourceBlendShapes"
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."

msgid "BlendShapeMappingsPass:SkippingMmdMorph"
msgstr "Found error(s) when generating MMD morph \"{0}\". This MMD blend shape will not be generated."

msgid "CommonChecks:NoMMDComponents"
msgstr "No Make It MMD component found in avatar. Nothing to do"

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

msgid "BlendShapeMappingsPass:MissingSourceBlendShapes"
msgstr "MMDモーフ「{0}」は、ブレンドシェイプを組み合わせる際({1}個のブレンドシェイプを組み合わせる中)に参照されるブレンドシェイプ {1} を探しましたが、見つかりませんでした。これらのブレンドシェイプは、Unityプロジェクトの他のツールによって削除された可能性があります。これが予期しないものである場合は、可能であればプロジェクトにインストールされているツールと共に、この問題を開発者に報告していただければ幸いです。"

msgid "BlendShapeMappingsPass:SkippingMmdMorph"
msgstr "MMDモーフ「{0}」を生成する際にエラーが発見されました。このMMDブレンドシェイプは生成しません。"

msgid "CommonChecks:NoMMDComponents"
msgstr "アバターにMake It MMDコンポーネントが見つかりません。処理するものがありません"

Expand Down

0 comments on commit 7d289eb

Please sign in to comment.