diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index d00bcc301..c93ccd1e1 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 965a6728b..5186577ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Editor/MergeSkinnedMeshEditor.cs b/Editor/MergeSkinnedMeshEditor.cs index a1bbd9344..8cfe5766e 100644 --- a/Editor/MergeSkinnedMeshEditor.cs +++ b/Editor/MergeSkinnedMeshEditor.cs @@ -34,12 +34,6 @@ static MergeSkinnedMeshEditor() if (component.GetComponent().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; }); } @@ -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); diff --git a/Editor/Processors/EditSkinnedMeshComponentProcessor.cs b/Editor/Processors/EditSkinnedMeshComponentProcessor.cs index cdf6650a8..a3de3876a 100644 --- a/Editor/Processors/EditSkinnedMeshComponentProcessor.cs +++ b/Editor/Processors/EditSkinnedMeshComponentProcessor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Anatawa12.AvatarOptimizer.ErrorReporting; using Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes; using UnityEngine; @@ -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}"); diff --git a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs index a1b91f697..3e353524e 100644 --- a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Anatawa12.AvatarOptimizer.ErrorReporting; using UnityEngine; using Object = UnityEngine.Object; @@ -40,6 +41,7 @@ TexCoordStatus TexCoordStatusMax(TexCoordStatus x, TexCoordStatus y) => var newBoundMax = Vector3.negativeInfinity; var mappings = new List<(string, string)>(); + var weightMismatchBlendShapes = new HashSet(); for (var i = 0; i < meshInfos.Length; i++) { @@ -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))); } @@ -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); diff --git a/Internal/ErrorReporter/Editor/BuildReport.cs b/Internal/ErrorReporter/Editor/BuildReport.cs index e86c47c4a..9da77970b 100644 --- a/Internal/ErrorReporter/Editor/BuildReport.cs +++ b/Internal/ErrorReporter/Editor/BuildReport.cs @@ -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; @@ -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) @@ -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;