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

Weight mismatch warn #359

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog].
### Added

### Changed
- BlendShape Weight mismatch warning is now build-time warning instad of validate time warning `#359`
- Thanks to FreeseBlendShape by TraceAndOptimize, most pre-build this warning is false positive. So this warning is moved to build-time only.

### Deprecated

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- BlendShape Weight mismatch warning is now build-time warning instad of validate time warning `#359`
- Thanks to FreeseBlendShape by TraceAndOptimize, most pre-build this warning is false positive. So this warning is moved to build-time only.

### Changed

Expand Down
13 changes: 0 additions & 13 deletions Editor/MergeSkinnedMeshEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ static MergeSkinnedMeshEditor()
if (component.GetComponent<SkinnedMeshRenderer>().sharedMesh)
err.Add(ErrorLog.Warning("MergeSkinnedMesh:warning:MeshIsNotNone"));

err.AddRange(component.renderersSet.GetAsSet()
.SelectMany(EditSkinnedMeshComponentUtil.GetBlendShapes)
.GroupBy(x => x.name, x => x.weight)
.Where(grouping => grouping.Distinct().Count() != 1)
.Select(grouping => ErrorLog.Warning("MergeSkinnedMesh:warning:blendShapeWeightMismatch", grouping.Key)));

return err;
});
}
Expand Down Expand Up @@ -69,13 +63,6 @@ protected override void OnInspectorGUIInner()
{
EditorGUILayout.HelpBox(CL4EE.Tr("MergeSkinnedMesh:warning:MeshIsNotNone"), MessageType.Warning);
}

foreach (var grouping in component.renderersSet.GetAsSet()
.SelectMany(EditSkinnedMeshComponentUtil.GetBlendShapes)
.GroupBy(x => x.name, x => x.weight)
.Where(grouping => grouping.Distinct().Count() != 1))
EditorGUILayout.HelpBox(string.Format(CL4EE.Tr("MergeSkinnedMesh:warning:blendShapeWeightMismatch"), grouping.Key),
MessageType.Warning);

EditorGUILayout.PropertyField(_renderersSetProp);
EditorGUILayout.PropertyField(_staticRenderersSetProp);
Expand Down
3 changes: 2 additions & 1 deletion Editor/Processors/EditSkinnedMeshComponentProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.ErrorReporting;
using Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes;
using UnityEngine;

Expand All @@ -24,7 +25,7 @@ public void Process(OptimizerSession session)
foreach (var processor in processors.GetSorted())
{
// TODO
processor.Process(session, target, holder);
BuildReport.ReportingObject(processor.Component, () => processor.Process(session, target, holder));
target.AssertInvariantContract(
$"after {processor.GetType().Name} " +
$"for {processor.Target.gameObject.name}");
Expand Down
11 changes: 11 additions & 0 deletions Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Anatawa12.AvatarOptimizer.ErrorReporting;
using UnityEngine;
using Object = UnityEngine.Object;

Expand Down Expand Up @@ -40,6 +41,7 @@ TexCoordStatus TexCoordStatusMax(TexCoordStatus x, TexCoordStatus y) =>
var newBoundMax = Vector3.negativeInfinity;

var mappings = new List<(string, string)>();
var weightMismatchBlendShapes = new HashSet<string>();

for (var i = 0; i < meshInfos.Length; i++)
{
Expand Down Expand Up @@ -72,6 +74,12 @@ TexCoordStatus TexCoordStatusMax(TexCoordStatus x, TexCoordStatus y) =>
newIndex = target.BlendShapes.Count;
target.BlendShapes.Add((name, weight));
}
else
{
// ReSharper disable once CompareOfFloatsByEqualityOperator
if (weight != target.BlendShapes[newIndex].weight)
weightMismatchBlendShapes.Add(name);
}

mappings.Add((VProp.BlendShapeIndex(sourceI), VProp.BlendShapeIndex(newIndex)));
}
Expand Down Expand Up @@ -103,6 +111,9 @@ TexCoordStatus TexCoordStatusMax(TexCoordStatus x, TexCoordStatus y) =>
target.AssertInvariantContract($"processing meshInfo {Target.gameObject.name}");
}

foreach (var weightMismatchBlendShape in weightMismatchBlendShapes)
BuildReport.LogWarning("MergeSkinnedMesh:warning:blendShapeWeightMismatch", weightMismatchBlendShape);

if (updateBounds && newBoundMin != Vector3.positiveInfinity && newBoundMax != Vector3.negativeInfinity)
{
target.Bounds.SetMinMax(newBoundMin, newBoundMax);
Expand Down
15 changes: 12 additions & 3 deletions Internal/ErrorReporter/Editor/BuildReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using UnityEditor;
Expand Down Expand Up @@ -127,11 +128,11 @@ internal AvatarReport Initialize(VRCAvatarDescriptor descriptor)
}

[CanBeNull]
internal static ErrorLog Log(ReportLevel level, string code, params string[] strings)
internal static ErrorLog Log(ReportLevel level, string code, string[] strings, Assembly assembly)
{
for (var i = 0; i < strings.Length; i++)
strings[i] = strings[i] ?? "";
var errorLog = new ErrorLog(level, code, strings);
var errorLog = new ErrorLog(level, code, strings, assembly);

var avatarReport = CurrentReport.CurrentAvatar;
if (avatarReport == null)
Expand All @@ -144,10 +145,18 @@ internal static ErrorLog Log(ReportLevel level, string code, params string[] str
return errorLog;
}

[CanBeNull]
public static ErrorLog LogInfo(string code, params string[] strings) => Log(ReportLevel.Info, code,
strings: strings, assembly: Assembly.GetCallingAssembly());

[CanBeNull]
public static ErrorLog LogWarning(string code, params string[] strings) => Log(ReportLevel.Warning, code,
strings: strings, assembly: Assembly.GetCallingAssembly());

[CanBeNull]
public static ErrorLog LogFatal(string code, params string[] strings)
{
var log = Log(ReportLevel.Error, code, strings: strings);
var log = Log(ReportLevel.Error, code, strings: strings, assembly: Assembly.GetCallingAssembly());
if (CurrentReport.CurrentAvatar != null)
{
CurrentReport.CurrentAvatar.successful = false;
Expand Down