From 47fb58a6b0785db4faf6b4823d72661167003180 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 17:49:14 +0900 Subject: [PATCH 01/11] refactor: move many submodule to another assembly (WIP) --- Editor/AnimatorParserV2/AnimatorParser.cs | 2 +- Editor/ContextExtensions.cs | 9 --- .../SkinnedMeshes/RemoveMeshInBoxProcessor.cs | 2 +- .../Utils.VRCSDKWeightChanges.cs} | 4 +- .../Utils.VRCSDKWeightChanges.cs.meta} | 0 ...m.anatawa12.avatar-optimizer.editor.asmdef | 3 + .../AnimatorOptimizer.meta | 0 .../AnimatorOptimizer/AnimOptPassBase.cs | 0 .../AnimatorOptimizer/AnimOptPassBase.cs.meta | 0 .../AnimatorOptimizer/EntryExitToBlendTree.cs | 0 .../EntryExitToBlendTree.cs.meta | 0 .../AnimatorOptimizer/KnownAnimatorValues.cs | 0 .../KnownAnimatorValues.cs.meta | 0 .../AnimatorOptimizer/MergeDirectBlendTree.cs | 0 .../MergeDirectBlendTree.cs.meta | 0 .../RemoveInvalidProperties.cs | 0 .../RemoveInvalidProperties.cs.meta | 0 .../RemoveMeaninglessLayer.cs | 0 .../RemoveMeaninglessLayer.cs.meta | 0 .../AnimatorOptimizer/Wrappers.cs | 0 .../AnimatorOptimizer/Wrappers.cs.meta | 0 ...timizer.internal.animator-optimizer.asmdef | 68 +++++++++++++++++++ ...er.internal.animator-optimizer.asmdef.meta | 3 + Internal/AnimatorOptimizer/csc.rsp | 1 + Internal/AnimatorOptimizer/csc.rsp.meta | 7 ++ .../Localization/Editor}/BuildLog.cs | 2 +- .../Localization/Editor}/BuildLog.cs.meta | 0 Internal/MeshInfo2.meta | 3 + .../MeshInfo2}/MeshInfo2.cs | 14 ++-- .../MeshInfo2}/MeshInfo2.cs.meta | 0 .../MeshInfo2/MeshInfo2ContextExtensions.cs | 22 ++++++ .../MeshInfo2ContextExtensions.cs.meta | 3 + .../MeshInfo2}/MeshInfo2Holder.cs | 6 +- .../MeshInfo2}/MeshInfo2Holder.cs.meta | 0 ...avatar-optimizer.internal.meshinfo2.asmdef | 62 +++++++++++++++++ ...r-optimizer.internal.meshinfo2.asmdef.meta | 3 + Internal/MeshInfo2/csc.rsp | 1 + Internal/MeshInfo2/csc.rsp.meta | 7 ++ Internal/TraceAndOptimizeBase.meta | 3 + .../TraceAndOptimizeProcessor.cs | 8 +-- .../TraceAndOptimizeProcessor.cs.meta | 0 ...er.internal.trace-and-optimize-base.asmdef | 66 ++++++++++++++++++ ...ternal.trace-and-optimize-base.asmdef.meta | 3 + .../ACUtils.GetControllerAndOverrides.cs | 0 .../ACUtils.GetControllerAndOverrides.cs.meta | 0 .../Utils}/ACUtils.cs | 2 +- .../Utils}/ACUtils.cs.meta | 0 .../Utils}/AnimatorWeightChange.cs | 6 +- .../Utils}/AnimatorWeightChange.cs.meta | 0 {Editor => Internal}/Utils/DeepCloneHelper.cs | 2 +- .../Utils/DeepCloneHelper.cs.meta | 0 {Editor => Internal/Utils}/DestroyTracker.cs | 4 +- .../Utils}/DestroyTracker.cs.meta | 0 {Editor/Math => Internal/Utils}/Matrix3x3.cs | 2 +- .../Math => Internal/Utils}/Matrix3x3.cs.meta | 0 {Editor/Math => Internal/Utils}/Matrix4x4.cs | 2 +- .../Math => Internal/Utils}/Matrix4x4.cs.meta | 0 .../Utils/MultiDimensionalNativeArray.cs | 4 +- .../Utils/MultiDimensionalNativeArray.cs.meta | 0 ...a12.avatar-optimizer.internal.utils.asmdef | 5 +- Runtime/AvatarTagComponent.cs | 14 ++-- Runtime/assembly-info.cs | 1 + 62 files changed, 298 insertions(+), 46 deletions(-) rename Editor/{AnimatorController/ACUtils.VRCSDKWeightChanges.cs => Utils/Utils.VRCSDKWeightChanges.cs} (95%) rename Editor/{AnimatorController/ACUtils.VRCSDKWeightChanges.cs.meta => Utils/Utils.VRCSDKWeightChanges.cs.meta} (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer.meta (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/AnimOptPassBase.cs (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/AnimOptPassBase.cs.meta (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/EntryExitToBlendTree.cs (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/EntryExitToBlendTree.cs.meta (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/KnownAnimatorValues.cs (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/KnownAnimatorValues.cs.meta (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/MergeDirectBlendTree.cs (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/MergeDirectBlendTree.cs.meta (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/RemoveInvalidProperties.cs (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/RemoveInvalidProperties.cs.meta (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/RemoveMeaninglessLayer.cs (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/RemoveMeaninglessLayer.cs.meta (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/Wrappers.cs (100%) rename {Editor/Processors => Internal}/AnimatorOptimizer/Wrappers.cs.meta (100%) create mode 100644 Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef create mode 100644 Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef.meta create mode 120000 Internal/AnimatorOptimizer/csc.rsp create mode 100644 Internal/AnimatorOptimizer/csc.rsp.meta rename {Editor => Internal/Localization/Editor}/BuildLog.cs (94%) rename {Editor => Internal/Localization/Editor}/BuildLog.cs.meta (100%) create mode 100644 Internal/MeshInfo2.meta rename {Editor/Processors/SkinnedMeshes => Internal/MeshInfo2}/MeshInfo2.cs (99%) rename {Editor/Processors/SkinnedMeshes => Internal/MeshInfo2}/MeshInfo2.cs.meta (100%) create mode 100644 Internal/MeshInfo2/MeshInfo2ContextExtensions.cs create mode 100644 Internal/MeshInfo2/MeshInfo2ContextExtensions.cs.meta rename {Editor/Processors => Internal/MeshInfo2}/MeshInfo2Holder.cs (93%) rename {Editor/Processors => Internal/MeshInfo2}/MeshInfo2Holder.cs.meta (100%) create mode 100644 Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef create mode 100644 Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef.meta create mode 120000 Internal/MeshInfo2/csc.rsp create mode 100644 Internal/MeshInfo2/csc.rsp.meta create mode 100644 Internal/TraceAndOptimizeBase.meta rename {Editor/Processors/TraceAndOptimize => Internal/TraceAndOptimizeBase}/TraceAndOptimizeProcessor.cs (92%) rename {Editor/Processors/TraceAndOptimize => Internal/TraceAndOptimizeBase}/TraceAndOptimizeProcessor.cs.meta (100%) create mode 100644 Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef create mode 100644 Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef.meta rename {Editor/AnimatorController => Internal/Utils}/ACUtils.GetControllerAndOverrides.cs (100%) rename {Editor/AnimatorController => Internal/Utils}/ACUtils.GetControllerAndOverrides.cs.meta (100%) rename {Editor/AnimatorController => Internal/Utils}/ACUtils.cs (99%) rename {Editor/AnimatorController => Internal/Utils}/ACUtils.cs.meta (100%) rename {Editor/AnimatorController => Internal/Utils}/AnimatorWeightChange.cs (95%) rename {Editor/AnimatorController => Internal/Utils}/AnimatorWeightChange.cs.meta (100%) rename {Editor => Internal}/Utils/DeepCloneHelper.cs (98%) rename {Editor => Internal}/Utils/DeepCloneHelper.cs.meta (100%) rename {Editor => Internal/Utils}/DestroyTracker.cs (95%) rename {Editor => Internal/Utils}/DestroyTracker.cs.meta (100%) rename {Editor/Math => Internal/Utils}/Matrix3x3.cs (99%) rename {Editor/Math => Internal/Utils}/Matrix3x3.cs.meta (100%) rename {Editor/Math => Internal/Utils}/Matrix4x4.cs (99%) rename {Editor/Math => Internal/Utils}/Matrix4x4.cs.meta (100%) rename {Editor => Internal}/Utils/MultiDimensionalNativeArray.cs (93%) rename {Editor => Internal}/Utils/MultiDimensionalNativeArray.cs.meta (100%) diff --git a/Editor/AnimatorParserV2/AnimatorParser.cs b/Editor/AnimatorParserV2/AnimatorParser.cs index 50378396e..e96b64ba1 100644 --- a/Editor/AnimatorParserV2/AnimatorParser.cs +++ b/Editor/AnimatorParserV2/AnimatorParser.cs @@ -224,7 +224,7 @@ private void CollectAvatarDescriptorModifications([NotNull] RootPropModNodeConta new AnimatorWeightChangesList(controllers[layer]?.ComputeLayerCount() ?? 0); var playableWeightChanged = new AnimatorLayerMap(); foreach (var layer in descriptor.baseAnimationLayers) - ACUtils.CollectWeightChangesInController(controllers[layer.type], + VRCSDKUtils.CollectWeightChangesInController(controllers[layer.type], playableWeightChanged, animatorLayerWeightChanged); if (_mmdWorldCompatibility) diff --git a/Editor/ContextExtensions.cs b/Editor/ContextExtensions.cs index 0d47edecd..d8432d674 100644 --- a/Editor/ContextExtensions.cs +++ b/Editor/ContextExtensions.cs @@ -16,15 +16,6 @@ public static T[] GetComponents([NotNull] this BuildContext context) where T return context.AvatarRootObject.GetComponentsInChildren(true); } - private static MeshInfo2Holder GetHolder([NotNull] this BuildContext context) - { - if (context == null) throw new ArgumentNullException(nameof(context)); - return context.Extension().Holder; - } - - public static MeshInfo2 GetMeshInfoFor([NotNull] this BuildContext context, SkinnedMeshRenderer renderer) => - context.GetHolder().GetMeshInfoFor(renderer); - public static ObjectMappingBuilder GetMappingBuilder([NotNull] this BuildContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); diff --git a/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs b/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs index 35d098576..d6e6bdf99 100644 --- a/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/RemoveMeshInBoxProcessor.cs @@ -21,7 +21,7 @@ public override void Process(BuildContext context, MeshInfo2 target) // Vertex.AdditionalTemporal: 0 if in box, 1 if out of box foreach (var vertex in target.Vertices) { - var actualPosition = vertex.ComputeActualPosition(target, originalState, Target.transform.worldToLocalMatrix); + var actualPosition = vertex.ComputeActualPosition(target, originalState.GetOriginalLocalToWorld, Target.transform.worldToLocalMatrix); if (Component.boxes.Any(x => x.ContainsVertex(actualPosition))) inBoxVertices.Add(vertex); } diff --git a/Editor/AnimatorController/ACUtils.VRCSDKWeightChanges.cs b/Editor/Utils/Utils.VRCSDKWeightChanges.cs similarity index 95% rename from Editor/AnimatorController/ACUtils.VRCSDKWeightChanges.cs rename to Editor/Utils/Utils.VRCSDKWeightChanges.cs index 324480702..7cecfc9e2 100644 --- a/Editor/AnimatorController/ACUtils.VRCSDKWeightChanges.cs +++ b/Editor/Utils/Utils.VRCSDKWeightChanges.cs @@ -8,7 +8,7 @@ namespace Anatawa12.AvatarOptimizer { - static partial class ACUtils + partial class VRCSDKUtils { public static void CollectWeightChangesInController([CanBeNull] RuntimeAnimatorController runtimeController, [NotNull] AnimatorLayerMap playableWeightChanged, @@ -17,7 +17,7 @@ public static void CollectWeightChangesInController([CanBeNull] RuntimeAnimatorC if (runtimeController == null) return; using (ErrorReport.WithContextObject(runtimeController)) { - foreach (var behaviour in StateMachineBehaviours(runtimeController)) + foreach (var behaviour in ACUtils.StateMachineBehaviours(runtimeController)) { switch (behaviour) { diff --git a/Editor/AnimatorController/ACUtils.VRCSDKWeightChanges.cs.meta b/Editor/Utils/Utils.VRCSDKWeightChanges.cs.meta similarity index 100% rename from Editor/AnimatorController/ACUtils.VRCSDKWeightChanges.cs.meta rename to Editor/Utils/Utils.VRCSDKWeightChanges.cs.meta diff --git a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef index 855e2ce1b..6d93a80fb 100644 --- a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef +++ b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef @@ -8,6 +8,9 @@ "com.anatawa12.avatar-optimizer.internal.unsafe", "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "com.anatawa12.avatar-optimizer.internal.meshinfo2", "com.anatawa12.avatar-optimizer.internal.utils", "Unity.Burst", "nadena.dev.ndmf", diff --git a/Editor/Processors/AnimatorOptimizer.meta b/Internal/AnimatorOptimizer.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer.meta rename to Internal/AnimatorOptimizer.meta diff --git a/Editor/Processors/AnimatorOptimizer/AnimOptPassBase.cs b/Internal/AnimatorOptimizer/AnimOptPassBase.cs similarity index 100% rename from Editor/Processors/AnimatorOptimizer/AnimOptPassBase.cs rename to Internal/AnimatorOptimizer/AnimOptPassBase.cs diff --git a/Editor/Processors/AnimatorOptimizer/AnimOptPassBase.cs.meta b/Internal/AnimatorOptimizer/AnimOptPassBase.cs.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer/AnimOptPassBase.cs.meta rename to Internal/AnimatorOptimizer/AnimOptPassBase.cs.meta diff --git a/Editor/Processors/AnimatorOptimizer/EntryExitToBlendTree.cs b/Internal/AnimatorOptimizer/EntryExitToBlendTree.cs similarity index 100% rename from Editor/Processors/AnimatorOptimizer/EntryExitToBlendTree.cs rename to Internal/AnimatorOptimizer/EntryExitToBlendTree.cs diff --git a/Editor/Processors/AnimatorOptimizer/EntryExitToBlendTree.cs.meta b/Internal/AnimatorOptimizer/EntryExitToBlendTree.cs.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer/EntryExitToBlendTree.cs.meta rename to Internal/AnimatorOptimizer/EntryExitToBlendTree.cs.meta diff --git a/Editor/Processors/AnimatorOptimizer/KnownAnimatorValues.cs b/Internal/AnimatorOptimizer/KnownAnimatorValues.cs similarity index 100% rename from Editor/Processors/AnimatorOptimizer/KnownAnimatorValues.cs rename to Internal/AnimatorOptimizer/KnownAnimatorValues.cs diff --git a/Editor/Processors/AnimatorOptimizer/KnownAnimatorValues.cs.meta b/Internal/AnimatorOptimizer/KnownAnimatorValues.cs.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer/KnownAnimatorValues.cs.meta rename to Internal/AnimatorOptimizer/KnownAnimatorValues.cs.meta diff --git a/Editor/Processors/AnimatorOptimizer/MergeDirectBlendTree.cs b/Internal/AnimatorOptimizer/MergeDirectBlendTree.cs similarity index 100% rename from Editor/Processors/AnimatorOptimizer/MergeDirectBlendTree.cs rename to Internal/AnimatorOptimizer/MergeDirectBlendTree.cs diff --git a/Editor/Processors/AnimatorOptimizer/MergeDirectBlendTree.cs.meta b/Internal/AnimatorOptimizer/MergeDirectBlendTree.cs.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer/MergeDirectBlendTree.cs.meta rename to Internal/AnimatorOptimizer/MergeDirectBlendTree.cs.meta diff --git a/Editor/Processors/AnimatorOptimizer/RemoveInvalidProperties.cs b/Internal/AnimatorOptimizer/RemoveInvalidProperties.cs similarity index 100% rename from Editor/Processors/AnimatorOptimizer/RemoveInvalidProperties.cs rename to Internal/AnimatorOptimizer/RemoveInvalidProperties.cs diff --git a/Editor/Processors/AnimatorOptimizer/RemoveInvalidProperties.cs.meta b/Internal/AnimatorOptimizer/RemoveInvalidProperties.cs.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer/RemoveInvalidProperties.cs.meta rename to Internal/AnimatorOptimizer/RemoveInvalidProperties.cs.meta diff --git a/Editor/Processors/AnimatorOptimizer/RemoveMeaninglessLayer.cs b/Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs similarity index 100% rename from Editor/Processors/AnimatorOptimizer/RemoveMeaninglessLayer.cs rename to Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs diff --git a/Editor/Processors/AnimatorOptimizer/RemoveMeaninglessLayer.cs.meta b/Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer/RemoveMeaninglessLayer.cs.meta rename to Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs.meta diff --git a/Editor/Processors/AnimatorOptimizer/Wrappers.cs b/Internal/AnimatorOptimizer/Wrappers.cs similarity index 100% rename from Editor/Processors/AnimatorOptimizer/Wrappers.cs rename to Internal/AnimatorOptimizer/Wrappers.cs diff --git a/Editor/Processors/AnimatorOptimizer/Wrappers.cs.meta b/Internal/AnimatorOptimizer/Wrappers.cs.meta similarity index 100% rename from Editor/Processors/AnimatorOptimizer/Wrappers.cs.meta rename to Internal/AnimatorOptimizer/Wrappers.cs.meta diff --git a/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef new file mode 100644 index 000000000..33e8520db --- /dev/null +++ b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef @@ -0,0 +1,68 @@ +{ + "name": "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "rootNamespace": "Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer", + "references": [ + "com.anatawa12.avatar-optimizer.internal.localization.editor", + "com.anatawa12.avatar-optimizer.internal.localization.runtime", + "com.anatawa12.avatar-optimizer.runtime", + "com.anatawa12.avatar-optimizer.internal.unsafe", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "com.anatawa12.avatar-optimizer.internal.meshinfo2", + "com.anatawa12.avatar-optimizer.internal.utils", + "nadena.dev.ndmf", + "com.anatawa12.avatar-optimizer.api.editor", + "VRC.SDKBase", + "UniHumanoid", + "VRM", + "VRM10" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "VRC.Dynamics.dll", + "VRC.SDK3.Dynamics.PhysBone.dll", + "VRC.SDK3.Dynamics.Contact.dll", + "VRCCore-Editor.dll", + "VRCSDK3A-Editor.dll", + "VRCSDK3A.dll", + "VRCSDKBase-Editor.dll", + "VRCSDKBase.dll", + "System.Memory.dll" + ], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "AAO_VRCSDK3_AVATARS" + }, + { + "name": "com.vrchat.avatars", + "expression": "3.5.1", + "define": "AAO_VRCSDK3_AVATARS_IMPOSTER_SETTINGS" + }, + { + "name": "com.vrchat.avatars", + "expression": "3.5.2-beta.1", + "define": "AAO_VRCSDK3_AVATARS_3_5_2" + }, + { + "name": "com.vrmc.univrm", + "expression": "", + "define": "AAO_VRM0" + }, + { + "name": "com.vrmc.vrm", + "expression": "", + "define": "AAO_VRM1" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef.meta b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef.meta new file mode 100644 index 000000000..a19300545 --- /dev/null +++ b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1890e87c756140c98e40c10cfd540485 +timeCreated: 1711007398 \ No newline at end of file diff --git a/Internal/AnimatorOptimizer/csc.rsp b/Internal/AnimatorOptimizer/csc.rsp new file mode 120000 index 000000000..c6acf2e0a --- /dev/null +++ b/Internal/AnimatorOptimizer/csc.rsp @@ -0,0 +1 @@ +../../Editor/csc.rsp \ No newline at end of file diff --git a/Internal/AnimatorOptimizer/csc.rsp.meta b/Internal/AnimatorOptimizer/csc.rsp.meta new file mode 100644 index 000000000..3bfb60ec6 --- /dev/null +++ b/Internal/AnimatorOptimizer/csc.rsp.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3af2bb4b3344c465593860e8a31f6b4f +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/BuildLog.cs b/Internal/Localization/Editor/BuildLog.cs similarity index 94% rename from Editor/BuildLog.cs rename to Internal/Localization/Editor/BuildLog.cs index 83cb07514..18c14d7f0 100644 --- a/Editor/BuildLog.cs +++ b/Internal/Localization/Editor/BuildLog.cs @@ -2,7 +2,7 @@ namespace Anatawa12.AvatarOptimizer { - internal static class BuildLog + public static class BuildLog { public static void LogInfo(string code, params object[] args) => ErrorReport.ReportError(AAOL10N.Localizer, ErrorSeverity.Information, code, args); diff --git a/Editor/BuildLog.cs.meta b/Internal/Localization/Editor/BuildLog.cs.meta similarity index 100% rename from Editor/BuildLog.cs.meta rename to Internal/Localization/Editor/BuildLog.cs.meta diff --git a/Internal/MeshInfo2.meta b/Internal/MeshInfo2.meta new file mode 100644 index 000000000..d0d101337 --- /dev/null +++ b/Internal/MeshInfo2.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bd2df1f1b84a48ddae91de7e196eaebf +timeCreated: 1711008922 \ No newline at end of file diff --git a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs b/Internal/MeshInfo2/MeshInfo2.cs similarity index 99% rename from Editor/Processors/SkinnedMeshes/MeshInfo2.cs rename to Internal/MeshInfo2/MeshInfo2.cs index a055f6dc6..b612ca115 100644 --- a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs +++ b/Internal/MeshInfo2/MeshInfo2.cs @@ -16,7 +16,7 @@ namespace Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes { - internal class MeshInfo2 + public class MeshInfo2 { [NotNull] public readonly Renderer SourceRenderer; [NotNull] public Transform RootBone; @@ -690,7 +690,7 @@ public void WriteToMeshRenderer(MeshRenderer targetRenderer) } } - internal class SubMesh + public class SubMesh { public readonly MeshTopology Topology = MeshTopology.Triangles; @@ -788,7 +788,7 @@ public void RemovePrimitives(string component, Func condition) } } - internal class Vertex + public class Vertex { public Vector3 Position { get; set; } public Vector3 Normal { get; set; } @@ -988,7 +988,7 @@ private Vertex(Vertex vertex) public Vertex Clone() => new Vertex(this); - public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2, OriginalState originalState, Matrix4x4 rendererWorldToLocalMatrix) + public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2, Func getLocalToWorld, Matrix4x4 rendererWorldToLocalMatrix) { var position = Position; @@ -1002,7 +1002,7 @@ public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2, OriginalState original foreach (var (bone, weight) in BoneWeights) { var transformMat = bone.Transform - ? originalState.GetOriginalLocalToWorld(bone.Transform) + ? getLocalToWorld(bone.Transform) : Matrix4x4.identity; var boneMat = transformMat * bone.Bindpose; matrix += boneMat * weight; @@ -1013,7 +1013,7 @@ public Vector3 ComputeActualPosition(MeshInfo2 meshInfo2, OriginalState original } } - internal class Bone + public class Bone { public Matrix4x4 Bindpose; public Transform Transform; @@ -1022,7 +1022,7 @@ public Bone(Matrix4x4 bindPose) : this(bindPose, null) {} public Bone(Matrix4x4 bindPose, Transform transform) => (Bindpose, Transform) = (bindPose, transform); } - internal enum TexCoordStatus + public enum TexCoordStatus { NotDefined = 0, Vector2 = 1, diff --git a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs.meta b/Internal/MeshInfo2/MeshInfo2.cs.meta similarity index 100% rename from Editor/Processors/SkinnedMeshes/MeshInfo2.cs.meta rename to Internal/MeshInfo2/MeshInfo2.cs.meta diff --git a/Internal/MeshInfo2/MeshInfo2ContextExtensions.cs b/Internal/MeshInfo2/MeshInfo2ContextExtensions.cs new file mode 100644 index 000000000..a7e4dd734 --- /dev/null +++ b/Internal/MeshInfo2/MeshInfo2ContextExtensions.cs @@ -0,0 +1,22 @@ +using System; +using Anatawa12.AvatarOptimizer.Processors; +using Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes; +using JetBrains.Annotations; +using nadena.dev.ndmf; +using UnityEngine; + +namespace Anatawa12.AvatarOptimizer +{ + public static class MeshInfo2ContextExtensions + { + [NotNull] + private static MeshInfo2Holder GetHolder([NotNull] this BuildContext context) + { + if (context == null) throw new ArgumentNullException(nameof(context)); + return context.Extension().Holder; + } + + public static MeshInfo2 GetMeshInfoFor([NotNull] this BuildContext context, SkinnedMeshRenderer renderer) => + context.GetHolder().GetMeshInfoFor(renderer); + } +} \ No newline at end of file diff --git a/Internal/MeshInfo2/MeshInfo2ContextExtensions.cs.meta b/Internal/MeshInfo2/MeshInfo2ContextExtensions.cs.meta new file mode 100644 index 000000000..e0f40d592 --- /dev/null +++ b/Internal/MeshInfo2/MeshInfo2ContextExtensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8da0d2fdff4a4cf29ef5ff999413e22a +timeCreated: 1711010081 \ No newline at end of file diff --git a/Editor/Processors/MeshInfo2Holder.cs b/Internal/MeshInfo2/MeshInfo2Holder.cs similarity index 93% rename from Editor/Processors/MeshInfo2Holder.cs rename to Internal/MeshInfo2/MeshInfo2Holder.cs index 5eeb9a027..c8d777f39 100644 --- a/Editor/Processors/MeshInfo2Holder.cs +++ b/Internal/MeshInfo2/MeshInfo2Holder.cs @@ -10,9 +10,9 @@ namespace Anatawa12.AvatarOptimizer.Processors { - internal class MeshInfo2Context : IExtensionContext + public class MeshInfo2Context : IExtensionContext { - [CanBeNull] public MeshInfo2Holder Holder { get; private set; } + internal MeshInfo2Holder Holder { get; private set; } public void OnActivate(BuildContext context) { Holder = new MeshInfo2Holder(context.AvatarRootObject); @@ -39,7 +39,7 @@ internal struct EvacuateAnimatorController : IDisposable public EvacuateAnimatorController(BuildContext context) { - _controllers = context.GetComponents() + _controllers = context.AvatarRootObject.GetComponentsInChildren() .ToDictionary(a => a, a => a.runtimeAnimatorController); foreach (var animator in _controllers.Keys) diff --git a/Editor/Processors/MeshInfo2Holder.cs.meta b/Internal/MeshInfo2/MeshInfo2Holder.cs.meta similarity index 100% rename from Editor/Processors/MeshInfo2Holder.cs.meta rename to Internal/MeshInfo2/MeshInfo2Holder.cs.meta diff --git a/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef b/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef new file mode 100644 index 000000000..527c7c6a5 --- /dev/null +++ b/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef @@ -0,0 +1,62 @@ +{ + "name": "com.anatawa12.avatar-optimizer.internal.meshinfo2", + "rootNamespace": "Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes", + "references": [ + "com.anatawa12.avatar-optimizer.runtime", + "Unity.Burst", + "nadena.dev.ndmf", + "com.anatawa12.avatar-optimizer.internal.utils", + "com.anatawa12.avatar-optimizer.internal.localization.editor", + "VRC.SDKBase", + "UniHumanoid", + "VRM", + "VRM10" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "VRC.Dynamics.dll", + "VRC.SDK3.Dynamics.PhysBone.dll", + "VRC.SDK3.Dynamics.Contact.dll", + "VRCCore-Editor.dll", + "VRCSDK3A-Editor.dll", + "VRCSDK3A.dll", + "VRCSDKBase-Editor.dll", + "VRCSDKBase.dll", + "System.Memory.dll" + ], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "AAO_VRCSDK3_AVATARS" + }, + { + "name": "com.vrchat.avatars", + "expression": "3.5.1", + "define": "AAO_VRCSDK3_AVATARS_IMPOSTER_SETTINGS" + }, + { + "name": "com.vrchat.avatars", + "expression": "3.5.2-beta.1", + "define": "AAO_VRCSDK3_AVATARS_3_5_2" + }, + { + "name": "com.vrmc.univrm", + "expression": "", + "define": "AAO_VRM0" + }, + { + "name": "com.vrmc.vrm", + "expression": "", + "define": "AAO_VRM1" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef.meta b/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef.meta new file mode 100644 index 000000000..58b37b1a8 --- /dev/null +++ b/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 373f79c9b8574e7aa9e3830bcd634d65 +timeCreated: 1711009013 \ No newline at end of file diff --git a/Internal/MeshInfo2/csc.rsp b/Internal/MeshInfo2/csc.rsp new file mode 120000 index 000000000..c6acf2e0a --- /dev/null +++ b/Internal/MeshInfo2/csc.rsp @@ -0,0 +1 @@ +../../Editor/csc.rsp \ No newline at end of file diff --git a/Internal/MeshInfo2/csc.rsp.meta b/Internal/MeshInfo2/csc.rsp.meta new file mode 100644 index 000000000..411abbfd9 --- /dev/null +++ b/Internal/MeshInfo2/csc.rsp.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 19ffc81ded9b04b7f8fb10c53d859f1c +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Internal/TraceAndOptimizeBase.meta b/Internal/TraceAndOptimizeBase.meta new file mode 100644 index 000000000..14719dfa6 --- /dev/null +++ b/Internal/TraceAndOptimizeBase.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fd7ddefc914b4d80853d718ac3887efc +timeCreated: 1711008185 \ No newline at end of file diff --git a/Editor/Processors/TraceAndOptimize/TraceAndOptimizeProcessor.cs b/Internal/TraceAndOptimizeBase/TraceAndOptimizeProcessor.cs similarity index 92% rename from Editor/Processors/TraceAndOptimize/TraceAndOptimizeProcessor.cs rename to Internal/TraceAndOptimizeBase/TraceAndOptimizeProcessor.cs index b7d5f7f48..a93a91b51 100644 --- a/Editor/Processors/TraceAndOptimize/TraceAndOptimizeProcessor.cs +++ b/Internal/TraceAndOptimizeBase/TraceAndOptimizeProcessor.cs @@ -4,7 +4,7 @@ namespace Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes { - class TraceAndOptimizeState + public class TraceAndOptimizeState { public bool Enabled; public bool FreezeBlendShape; @@ -31,7 +31,7 @@ class TraceAndOptimizeState public Dictionary> PreserveBlendShapes = new Dictionary>(); - public void Initialize(TraceAndOptimize config) + internal void Initialize(TraceAndOptimize config) { FreezeBlendShape = config.freezeBlendShape; RemoveUnusedObjects = config.removeUnusedObjects; @@ -59,7 +59,7 @@ public void Initialize(TraceAndOptimize config) } } - internal class LoadTraceAndOptimizeConfiguration : Pass + public class LoadTraceAndOptimizeConfiguration : Pass { public override string DisplayName => "T&O: Load Configuration"; @@ -72,7 +72,7 @@ protected override void Execute(BuildContext context) } } - internal abstract class TraceAndOptimizePass : Pass where T : TraceAndOptimizePass, new() + public abstract class TraceAndOptimizePass : Pass where T : TraceAndOptimizePass, new() { protected sealed override void Execute(BuildContext context) { diff --git a/Editor/Processors/TraceAndOptimize/TraceAndOptimizeProcessor.cs.meta b/Internal/TraceAndOptimizeBase/TraceAndOptimizeProcessor.cs.meta similarity index 100% rename from Editor/Processors/TraceAndOptimize/TraceAndOptimizeProcessor.cs.meta rename to Internal/TraceAndOptimizeBase/TraceAndOptimizeProcessor.cs.meta diff --git a/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef b/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef new file mode 100644 index 000000000..e618ca145 --- /dev/null +++ b/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef @@ -0,0 +1,66 @@ +{ + "name": "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "rootNamespace": "Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes", + "references": [ + "com.anatawa12.avatar-optimizer.internal.localization.editor", + "com.anatawa12.avatar-optimizer.internal.localization.runtime", + "com.anatawa12.avatar-optimizer.runtime", + "com.anatawa12.avatar-optimizer.internal.unsafe", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.utils", + "nadena.dev.ndmf", + "com.anatawa12.avatar-optimizer.api.editor", + "VRC.SDKBase", + "UniHumanoid", + "VRM", + "VRM10" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "VRC.Dynamics.dll", + "VRC.SDK3.Dynamics.PhysBone.dll", + "VRC.SDK3.Dynamics.Contact.dll", + "VRCCore-Editor.dll", + "VRCSDK3A-Editor.dll", + "VRCSDK3A.dll", + "VRCSDKBase-Editor.dll", + "VRCSDKBase.dll", + "System.Memory.dll" + ], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "AAO_VRCSDK3_AVATARS" + }, + { + "name": "com.vrchat.avatars", + "expression": "3.5.1", + "define": "AAO_VRCSDK3_AVATARS_IMPOSTER_SETTINGS" + }, + { + "name": "com.vrchat.avatars", + "expression": "3.5.2-beta.1", + "define": "AAO_VRCSDK3_AVATARS_3_5_2" + }, + { + "name": "com.vrmc.univrm", + "expression": "", + "define": "AAO_VRM0" + }, + { + "name": "com.vrmc.vrm", + "expression": "", + "define": "AAO_VRM1" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef.meta b/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef.meta new file mode 100644 index 000000000..e415762ac --- /dev/null +++ b/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cd09d5d7ad254d8eb43735f4df623490 +timeCreated: 1711008342 \ No newline at end of file diff --git a/Editor/AnimatorController/ACUtils.GetControllerAndOverrides.cs b/Internal/Utils/ACUtils.GetControllerAndOverrides.cs similarity index 100% rename from Editor/AnimatorController/ACUtils.GetControllerAndOverrides.cs rename to Internal/Utils/ACUtils.GetControllerAndOverrides.cs diff --git a/Editor/AnimatorController/ACUtils.GetControllerAndOverrides.cs.meta b/Internal/Utils/ACUtils.GetControllerAndOverrides.cs.meta similarity index 100% rename from Editor/AnimatorController/ACUtils.GetControllerAndOverrides.cs.meta rename to Internal/Utils/ACUtils.GetControllerAndOverrides.cs.meta diff --git a/Editor/AnimatorController/ACUtils.cs b/Internal/Utils/ACUtils.cs similarity index 99% rename from Editor/AnimatorController/ACUtils.cs rename to Internal/Utils/ACUtils.cs index e5aee1881..e0c18eb79 100644 --- a/Editor/AnimatorController/ACUtils.cs +++ b/Internal/Utils/ACUtils.cs @@ -5,7 +5,7 @@ namespace Anatawa12.AvatarOptimizer { - static partial class ACUtils + public static partial class ACUtils { [ItemNotNull] [NotNull] diff --git a/Editor/AnimatorController/ACUtils.cs.meta b/Internal/Utils/ACUtils.cs.meta similarity index 100% rename from Editor/AnimatorController/ACUtils.cs.meta rename to Internal/Utils/ACUtils.cs.meta diff --git a/Editor/AnimatorController/AnimatorWeightChange.cs b/Internal/Utils/AnimatorWeightChange.cs similarity index 95% rename from Editor/AnimatorController/AnimatorWeightChange.cs rename to Internal/Utils/AnimatorWeightChange.cs index 379820c76..0f497384b 100644 --- a/Editor/AnimatorController/AnimatorWeightChange.cs +++ b/Internal/Utils/AnimatorWeightChange.cs @@ -2,7 +2,7 @@ namespace Anatawa12.AvatarOptimizer { - static class AnimatorWeightChanges + public static class AnimatorWeightChanges { public static AnimatorWeightChange ForDurationAndWeight(float duration, float weight) => duration != 0 ? AnimatorWeightChange.Variable : ForWeight(weight); @@ -50,7 +50,7 @@ public static AnimatorWeightChange Merge(this AnimatorWeightChange a, AnimatorWe } } - class AnimatorWeightChangesList + public class AnimatorWeightChangesList { private readonly AnimatorWeightChange[] _changes; @@ -72,7 +72,7 @@ public AnimatorWeightChange this[int index] public AnimatorWeightChange Get(int i) => this[i]; } - internal enum AnimatorWeightChange + public enum AnimatorWeightChange { NotChanged, AlwaysZero, diff --git a/Editor/AnimatorController/AnimatorWeightChange.cs.meta b/Internal/Utils/AnimatorWeightChange.cs.meta similarity index 100% rename from Editor/AnimatorController/AnimatorWeightChange.cs.meta rename to Internal/Utils/AnimatorWeightChange.cs.meta diff --git a/Editor/Utils/DeepCloneHelper.cs b/Internal/Utils/DeepCloneHelper.cs similarity index 98% rename from Editor/Utils/DeepCloneHelper.cs rename to Internal/Utils/DeepCloneHelper.cs index 4a0c5cf73..bbee53d8f 100644 --- a/Editor/Utils/DeepCloneHelper.cs +++ b/Internal/Utils/DeepCloneHelper.cs @@ -7,7 +7,7 @@ namespace Anatawa12.AvatarOptimizer { - abstract class DeepCloneHelper + public abstract class DeepCloneHelper { private readonly Dictionary _cache = new Dictionary(); private bool _mapped = false; diff --git a/Editor/Utils/DeepCloneHelper.cs.meta b/Internal/Utils/DeepCloneHelper.cs.meta similarity index 100% rename from Editor/Utils/DeepCloneHelper.cs.meta rename to Internal/Utils/DeepCloneHelper.cs.meta diff --git a/Editor/DestroyTracker.cs b/Internal/Utils/DestroyTracker.cs similarity index 95% rename from Editor/DestroyTracker.cs rename to Internal/Utils/DestroyTracker.cs index 528ffb069..e4bc1c7d2 100644 --- a/Editor/DestroyTracker.cs +++ b/Internal/Utils/DestroyTracker.cs @@ -9,7 +9,7 @@ namespace Anatawa12.AvatarOptimizer /// /// This class allows users to track destroyed objects /// - internal class DestroyTracker + public class DestroyTracker { [CanBeNull] private static DestroyTracker _tracker; @@ -53,7 +53,7 @@ public static void DestroyImmediate(Object obj) } } - internal class ExtensionContext : IExtensionContext + public class ExtensionContext : IExtensionContext { public void OnActivate(BuildContext context) => _tracker = new DestroyTracker(); diff --git a/Editor/DestroyTracker.cs.meta b/Internal/Utils/DestroyTracker.cs.meta similarity index 100% rename from Editor/DestroyTracker.cs.meta rename to Internal/Utils/DestroyTracker.cs.meta diff --git a/Editor/Math/Matrix3x3.cs b/Internal/Utils/Matrix3x3.cs similarity index 99% rename from Editor/Math/Matrix3x3.cs rename to Internal/Utils/Matrix3x3.cs index f593bd25e..9fde67e0e 100644 --- a/Editor/Math/Matrix3x3.cs +++ b/Internal/Utils/Matrix3x3.cs @@ -7,7 +7,7 @@ namespace Anatawa12.AvatarOptimizer /// AAO internal replacement for UnityEngine.Matrix3x3 for more math operations /// // ReSharper disable once InconsistentNaming - struct Matrix3x3 : IEquatable + public struct Matrix3x3 : IEquatable { // ReSharper disable InconsistentNaming public static Matrix3x3 zero = new Matrix3x3(0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/Editor/Math/Matrix3x3.cs.meta b/Internal/Utils/Matrix3x3.cs.meta similarity index 100% rename from Editor/Math/Matrix3x3.cs.meta rename to Internal/Utils/Matrix3x3.cs.meta diff --git a/Editor/Math/Matrix4x4.cs b/Internal/Utils/Matrix4x4.cs similarity index 99% rename from Editor/Math/Matrix4x4.cs rename to Internal/Utils/Matrix4x4.cs index aab123f87..e05c4490f 100644 --- a/Editor/Math/Matrix4x4.cs +++ b/Internal/Utils/Matrix4x4.cs @@ -8,7 +8,7 @@ namespace Anatawa12.AvatarOptimizer /// AAO internal replacement for UnityEngine.Matrix4x4 for more math operations /// // ReSharper disable once InconsistentNaming - struct Matrix4x4 : IEquatable + public struct Matrix4x4 : IEquatable { // ReSharper disable InconsistentNaming public static readonly Matrix4x4 zero = new Matrix4x4(UnityMatrix4x4.zero); diff --git a/Editor/Math/Matrix4x4.cs.meta b/Internal/Utils/Matrix4x4.cs.meta similarity index 100% rename from Editor/Math/Matrix4x4.cs.meta rename to Internal/Utils/Matrix4x4.cs.meta diff --git a/Editor/Utils/MultiDimensionalNativeArray.cs b/Internal/Utils/MultiDimensionalNativeArray.cs similarity index 93% rename from Editor/Utils/MultiDimensionalNativeArray.cs rename to Internal/Utils/MultiDimensionalNativeArray.cs index 803771d10..ef50b8afb 100644 --- a/Editor/Utils/MultiDimensionalNativeArray.cs +++ b/Internal/Utils/MultiDimensionalNativeArray.cs @@ -5,7 +5,7 @@ namespace Anatawa12.AvatarOptimizer { [BurstCompile] - struct NativeArray2 : IDisposable where T : unmanaged + public struct NativeArray2 : IDisposable where T : unmanaged { private NativeArray _array; private readonly int _firstDimension; @@ -28,7 +28,7 @@ public NativeArray2(int firstDimension, int secondDimension, Allocator allocator } [BurstCompile] - struct NativeArray3 : IDisposable where T : unmanaged + public struct NativeArray3 : IDisposable where T : unmanaged { private NativeArray _array; private readonly int _firstDimension; diff --git a/Editor/Utils/MultiDimensionalNativeArray.cs.meta b/Internal/Utils/MultiDimensionalNativeArray.cs.meta similarity index 100% rename from Editor/Utils/MultiDimensionalNativeArray.cs.meta rename to Internal/Utils/MultiDimensionalNativeArray.cs.meta diff --git a/Internal/Utils/com.anatawa12.avatar-optimizer.internal.utils.asmdef b/Internal/Utils/com.anatawa12.avatar-optimizer.internal.utils.asmdef index ceeae9668..afe6a9e3e 100644 --- a/Internal/Utils/com.anatawa12.avatar-optimizer.internal.utils.asmdef +++ b/Internal/Utils/com.anatawa12.avatar-optimizer.internal.utils.asmdef @@ -1,7 +1,10 @@ { "name": "com.anatawa12.avatar-optimizer.internal.utils", "rootNamespace": "Anatawa12.AvatarOptimizer", - "references": [], + "references": [ + "Unity.Burst", + "nadena.dev.ndmf" + ], "includePlatforms": [ "Editor" ], diff --git a/Runtime/AvatarTagComponent.cs b/Runtime/AvatarTagComponent.cs index dd2406a82..4dda85e85 100644 --- a/Runtime/AvatarTagComponent.cs +++ b/Runtime/AvatarTagComponent.cs @@ -1,20 +1,22 @@ -using nadena.dev.ndmf.runtime; +using JetBrains.Annotations; using UnityEngine; namespace Anatawa12.AvatarOptimizer { - // https://github.com/bdunderscore/modular-avatar/blob/db49e2e210bc070671af963ff89df853ae4514a5/Packages/nadena.dev.modular-avatar/Runtime/AvatarTagComponent.cs - // Originally under MIT License - // Copyright (c) 2022 bd_ /** - * This abstract base class is injected into the VRCSDK avatar component allowlist to avoid + * This class is the base class for most components in Avatar Optimizer. + * When you found instance of this class, you can assume that it's a part of Avatar Optimizer. */ [DefaultExecutionOrder(-9990)] // run before av3emu [ExecuteAlways] - internal abstract class AvatarTagComponent : MonoBehaviour + [PublicAPI] + public abstract class AvatarTagComponent : MonoBehaviour #if AAO_VRCSDK3_AVATARS , VRC.SDKBase.IEditorOnly #endif { + private protected AvatarTagComponent() + { + } } } \ No newline at end of file diff --git a/Runtime/assembly-info.cs b/Runtime/assembly-info.cs index 1abdbcf68..b65f8ec0e 100644 --- a/Runtime/assembly-info.cs +++ b/Runtime/assembly-info.cs @@ -1,4 +1,5 @@ using System.Runtime.CompilerServices; [assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.editor")] +[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base")] [assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test")] From 2f2b7477f5dd29a27b8834a0e311b05d26da6db7 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 18:24:33 +0900 Subject: [PATCH 02/11] refactor: separate AnimatorParsersV2 dependency of ObjectMappingBuilder to another struct --- Editor/ObjectMapping/ObjectMappingBuilder.cs | 133 +++------------ Editor/ObjectMapping/PropertyInfo.cs | 151 ++++++++++++++++++ Editor/ObjectMapping/PropertyInfo.cs.meta | 3 + .../MergeSkinnedMeshProcessor.cs | 2 +- 4 files changed, 178 insertions(+), 111 deletions(-) create mode 100644 Editor/ObjectMapping/PropertyInfo.cs create mode 100644 Editor/ObjectMapping/PropertyInfo.cs.meta diff --git a/Editor/ObjectMapping/ObjectMappingBuilder.cs b/Editor/ObjectMapping/ObjectMappingBuilder.cs index 1285dd637..1a3bf4e6e 100644 --- a/Editor/ObjectMapping/ObjectMappingBuilder.cs +++ b/Editor/ObjectMapping/ObjectMappingBuilder.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using Anatawa12.AvatarOptimizer.AnimatorParsersV2; using JetBrains.Annotations; using UnityEditor; using UnityEngine; -using Object = UnityEngine.Object; namespace Anatawa12.AvatarOptimizer { @@ -95,17 +93,6 @@ private BuildingComponentInfo GetComponentInfo(ComponentOrGameObject component) return info; } - public void ImportModifications( - RootPropModNodeContainer modifications - ) - { - foreach (var ((target, prop), value) in modifications.FloatNodes) - GetComponentInfo(target).ImportProperty(prop, value); - - foreach (var ((target, prop), value) in modifications.ObjectNodes) - GetComponentInfo(target).ImportProperty(prop, value); - } - public ObjectMapping BuildObjectMapping() { return new ObjectMapping( @@ -119,12 +106,10 @@ class AnimationPropertyInfo [CanBeNull] public readonly string Name; [CanBeNull] public AnimationPropertyInfo MergedTo { get; private set; } private MappedPropertyInfo? _mappedPropertyInfo; - [CanBeNull] private RootPropModNode _floatNode; - [CanBeNull] private RootPropModNode _objectNode; + + public PropertyInfo PropertyInfo; + [CanBeNull] public List CopiedTo { get; private set; } - [CanBeNull] - public RootPropModNode FloatNode => _floatNode?.Normalize(); - public RootPropModNode ObjectNode => _objectNode?.Normalize(); public AnimationPropertyInfo([NotNull] BuildingComponentInfo component, [NotNull] string name) { @@ -141,7 +126,7 @@ private AnimationPropertyInfo() public void MergeTo(AnimationPropertyInfo property) { MergedTo = property; - MergeNode(ref property._floatNode, ref _floatNode); + PropertyInfo.MergeTo(ref property.PropertyInfo); } public void CopyTo(AnimationPropertyInfo property) @@ -149,7 +134,7 @@ public void CopyTo(AnimationPropertyInfo property) if (CopiedTo == null) CopiedTo = new List(); CopiedTo.Add(property); - MergeNode(ref property._floatNode, ref _floatNode); + PropertyInfo.CopyTo(ref property.PropertyInfo); } public MappedPropertyInfo GetMappedInfo() @@ -195,45 +180,6 @@ private MappedPropertyInfo ComputeMappedInfo() return new MappedPropertyInfo(descriptor, copied.ToArray()); } } - - private static void MergeNode([CanBeNull] ref RootPropModNode mergeTo, - [CanBeNull] ref RootPropModNode merge) - { - if (merge == null || merge.IsEmpty) return; - if (mergeTo == null || merge.IsEmpty) - { - mergeTo = merge; - return; - } - - mergeTo.Add(merge); - merge.Invalidate(); - merge = null; - } - - public void ImportProperty(RootPropModNode node) - { - if (FloatNode != null) throw new InvalidOperationException(); - _floatNode = node; - } - - public void ImportProperty(RootPropModNode node) - { - if (ObjectNode != null) throw new InvalidOperationException(); - _objectNode = node; - } - - public void AddModification(ComponentPropModNodeBase node, bool alwaysApplied) - { - if (_floatNode == null) _floatNode = new RootPropModNode(); - _floatNode.Add(node, alwaysApplied); - } - - public void AddModification(ComponentPropModNodeBase node, bool alwaysApplied) - { - if (_objectNode == null) _objectNode = new RootPropModNode(); - _objectNode.Add(node, alwaysApplied); - } } class BuildingComponentInfo : AnimationComponentInfo @@ -347,68 +293,35 @@ public override ComponentOrGameObject TargetComponent public override string[] Properties => _afterPropertyIds.Keys.ToArray(); - public override bool ContainsFloat(string property) => - _afterPropertyIds.TryGetValue(property, out var info) && info.FloatNode != null; - - public override bool TryGetFloat(string propertyName, out RootPropModNode animation) - { - animation = default; - if (!_afterPropertyIds.TryGetValue(propertyName, out var info)) - return false; - animation = info.FloatNode; - return animation != null; - } - - public override void AddModification(string prop, ComponentPropModNodeBase node, bool alwaysApplied) => - GetProperty(prop).AddModification(node, alwaysApplied); - - public void ImportProperty(string prop, RootPropModNode node) => - GetProperty(prop).ImportProperty(node); - - public void ImportProperty(string prop, RootPropModNode node) => - GetProperty(prop).ImportProperty(node); - - public override IEnumerable<(string, RootPropModNode)> AllFloatProperties => - _afterPropertyIds - .Where(x => x.Value.FloatNode != null) - .Select(x => (x.Key, x.Value.FloatNode)); - - public override bool ContainsObject(string property) => - _afterPropertyIds.TryGetValue(property, out var info) && info.ObjectNode != null; - - public override bool TryGetObject(string propertyName, out RootPropModNode animation) + public override ref PropertyInfo GetPropertyInfo(string property) => ref GetProperty(property).PropertyInfo; + public override PropertyInfo TryGetPropertyInfo(string property) { - animation = default; - if (!_afterPropertyIds.TryGetValue(propertyName, out var info)) - return false; - animation = info.ObjectNode; - return animation != null; + if (_afterPropertyIds.TryGetValue(property, out var info)) + return info.PropertyInfo; + return default; } - public override void AddModification(string prop, ComponentPropModNodeBase node, bool alwaysApplied) => - GetProperty(prop).AddModification(node, alwaysApplied); - - public override IEnumerable<(string, RootPropModNode)> AllObjectProperties => - _afterPropertyIds - .Where(x => x.Value.ObjectNode != null) - .Select(x => (x.Key, x.Value.ObjectNode)); + public override IEnumerable<(string, PropertyInfo)> GetAllPropertyInfo => + _afterPropertyIds.Select((x) => (x.Key, x.Value.PropertyInfo)); } } + internal interface IPropertyInfo + where T : struct, IPropertyInfo + { + void MergeTo(ref T property); + void CopyTo(ref T property); + } + internal abstract class AnimationComponentInfo { public abstract string[] Properties { get; } public abstract ComponentOrGameObject TargetComponent { get; } public abstract void RemoveProperty(string property); - public abstract bool ContainsFloat(string property); - public abstract bool TryGetFloat(string propertyName, out RootPropModNode animation); - public abstract void AddModification(string prop, ComponentPropModNodeBase node, bool alwaysApplied); - public abstract IEnumerable<(string, RootPropModNode)> AllFloatProperties { get; } - - public abstract bool ContainsObject(string property); - public abstract bool TryGetObject(string propertyName, out RootPropModNode animation); - public abstract void AddModification(string prop, ComponentPropModNodeBase node, bool alwaysApplied); - public abstract IEnumerable<(string, RootPropModNode)> AllObjectProperties { get; } + + public abstract ref PropertyInfo GetPropertyInfo(string property); + public abstract PropertyInfo TryGetPropertyInfo(string property); + public abstract IEnumerable<(string name, PropertyInfo info)> GetAllPropertyInfo { get; } } } diff --git a/Editor/ObjectMapping/PropertyInfo.cs b/Editor/ObjectMapping/PropertyInfo.cs new file mode 100644 index 000000000..f0e148d85 --- /dev/null +++ b/Editor/ObjectMapping/PropertyInfo.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Anatawa12.AvatarOptimizer.AnimatorParsersV2; +using JetBrains.Annotations; +using Object = UnityEngine.Object; + +namespace Anatawa12.AvatarOptimizer +{ + internal struct PropertyInfo : IPropertyInfo + { + [CanBeNull] private RootPropModNode _floatNode; + [CanBeNull] private RootPropModNode _objectNode; + + [CanBeNull] public RootPropModNode FloatNode => _floatNode?.Normalize(); + [CanBeNull] public RootPropModNode ObjectNode => _objectNode?.Normalize(); + + public void MergeTo(ref PropertyInfo property) + { + MergeNode(ref property._floatNode, ref _floatNode); + MergeNode(ref property._objectNode, ref _objectNode); + } + + private static void MergeNode([CanBeNull] ref RootPropModNode mergeTo, + [CanBeNull] ref RootPropModNode merge) + { + if (merge == null || merge.IsEmpty) return; + if (mergeTo == null || merge.IsEmpty) + { + mergeTo = merge; + return; + } + + mergeTo.Add(merge); + merge.Invalidate(); + merge = null; + } + + public void CopyTo(ref PropertyInfo property) + { + CopyNode(ref property._floatNode, _floatNode); + CopyNode(ref property._objectNode, _objectNode); + } + + private static void CopyNode([CanBeNull] ref RootPropModNode mergeTo, + [CanBeNull] RootPropModNode merge) + { + if (merge == null || merge.IsEmpty) return; + if (mergeTo == null || merge.IsEmpty) + { + mergeTo = merge; + return; + } + + mergeTo.Add(merge); + } + + public void ImportProperty(RootPropModNode node) + { + if (FloatNode != null) throw new InvalidOperationException(); + _floatNode = node; + } + + public void ImportProperty(RootPropModNode node) + { + if (ObjectNode != null) throw new InvalidOperationException(); + _objectNode = node; + } + + public void AddModification(ComponentPropModNodeBase node, bool alwaysApplied) + { + if (_floatNode == null) _floatNode = new RootPropModNode(); + _floatNode.Add(node, alwaysApplied); + } + + public void AddModification(ComponentPropModNodeBase node, bool alwaysApplied) + { + if (_objectNode == null) _objectNode = new RootPropModNode(); + _objectNode.Add(node, alwaysApplied); + } + } + + internal static class AnimationComponentInfoExtensions + { + public static void ImportModifications([NotNull] this ObjectMappingBuilder builder, + RootPropModNodeContainer modifications) + { + foreach (var ((target, prop), value) in modifications.FloatNodes) + builder.GetAnimationComponent(target).GetPropertyInfo(prop).ImportProperty(value); + + foreach (var ((target, prop), value) in modifications.ObjectNodes) + builder.GetAnimationComponent(target).GetPropertyInfo(prop).ImportProperty(value); + } + + public static bool ContainsFloat([NotNull] this AnimationComponentInfo info, string property) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + return info.TryGetPropertyInfo(property).FloatNode != null; + } + + public static bool TryGetFloat([NotNull] this AnimationComponentInfo info, string property, + [CanBeNull] out RootPropModNode animation) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + animation = info.TryGetPropertyInfo(property).FloatNode; + return animation != null; + } + + public static void AddModification([NotNull] this AnimationComponentInfo info, string property, + ComponentPropModNodeBase node, bool alwaysApplied) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + info.GetPropertyInfo(property).AddModification(node, alwaysApplied); + } + + public static bool ContainsObject([NotNull] this AnimationComponentInfo info, string property) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + return info.TryGetPropertyInfo(property).ObjectNode != null; + } + + public static bool TryGetObject([NotNull] this AnimationComponentInfo info, string property, + out RootPropModNode animation) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + animation = info.TryGetPropertyInfo(property).ObjectNode; + return animation != null; + } + + public static void AddModification([NotNull] this AnimationComponentInfo info, string property, + ComponentPropModNodeBase node, bool alwaysApplied) + { + if (info == null) throw new ArgumentNullException(nameof(info)); + info.GetPropertyInfo(property).AddModification(node, alwaysApplied); + } + + public static IEnumerable<(string, RootPropModNode)> GetAllFloatProperties( + [NotNull] this AnimationComponentInfo info) + { + return info.GetAllPropertyInfo.Where(x => x.info.FloatNode != null) + .Select(x => (x.name, x.info.FloatNode)); + } + + public static IEnumerable<(string, RootPropModNode)> GetAllObjectProperties( + [NotNull] this AnimationComponentInfo info) + { + return info.GetAllPropertyInfo.Where(x => x.info.ObjectNode != null) + .Select(x => (x.name, x.info.ObjectNode)); + } + } +} \ No newline at end of file diff --git a/Editor/ObjectMapping/PropertyInfo.cs.meta b/Editor/ObjectMapping/PropertyInfo.cs.meta new file mode 100644 index 000000000..9b9f04086 --- /dev/null +++ b/Editor/ObjectMapping/PropertyInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ab0936e096e347f8aa8ea10023c1d61a +timeCreated: 1711012329 \ No newline at end of file diff --git a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs index b3fdbb97f..3c8c1f1c3 100644 --- a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs @@ -292,7 +292,7 @@ private void MaterialParameterAnimationWarnings(MeshInfo2[] sourceRenderers, Bui foreach (var meshInfo2 in sourceRenderers) { var component = context.GetAnimationComponent(meshInfo2.SourceRenderer); - foreach (var (name, property) in component.AllFloatProperties) + foreach (var (name, property) in component.GetAllFloatProperties()) { if (!name.StartsWith("material.", StringComparison.Ordinal)) continue; var materialPropertyName = name.Substring("material.".Length); From f16d2c21cfa19c2c8f808d8d72f075b73ed807ea Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 18:33:51 +0900 Subject: [PATCH 03/11] refactor: remove dependency to AnimatorParsersV2 in ObjectMappingBuilder with generics --- Editor/ContextExtensions.cs | 4 +- Editor/ObjectMapping/ObjectMappingBuilder.cs | 26 ++++++------ Editor/ObjectMapping/ObjectMappingContext.cs | 4 +- Editor/ObjectMapping/PropertyInfo.cs | 20 +++++---- .../TraceAndOptimize/OptimizePhysBone.cs | 2 +- Test~/ApplyObjectMappingTest.cs | 6 +-- Test~/ObjectMappingTest.cs | 41 ++++++++++++------- 7 files changed, 59 insertions(+), 44 deletions(-) diff --git a/Editor/ContextExtensions.cs b/Editor/ContextExtensions.cs index d8432d674..1fff440fc 100644 --- a/Editor/ContextExtensions.cs +++ b/Editor/ContextExtensions.cs @@ -16,7 +16,7 @@ public static T[] GetComponents([NotNull] this BuildContext context) where T return context.AvatarRootObject.GetComponentsInChildren(true); } - public static ObjectMappingBuilder GetMappingBuilder([NotNull] this BuildContext context) + public static ObjectMappingBuilder GetMappingBuilder([NotNull] this BuildContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); return context.Extension().MappingBuilder; @@ -37,7 +37,7 @@ public static void RecordMoveProperty([NotNull] this BuildContext context, Compo public static void RecordRemoveProperty([NotNull] this BuildContext context, Component from, string oldProp) => GetMappingBuilder(context).RecordRemoveProperty(from, oldProp); - public static AnimationComponentInfo GetAnimationComponent([NotNull] this BuildContext context, + public static AnimationComponentInfo GetAnimationComponent([NotNull] this BuildContext context, ComponentOrGameObject component) => GetMappingBuilder(context).GetAnimationComponent(component); diff --git a/Editor/ObjectMapping/ObjectMappingBuilder.cs b/Editor/ObjectMapping/ObjectMappingBuilder.cs index 1a3bf4e6e..5d30c7eca 100644 --- a/Editor/ObjectMapping/ObjectMappingBuilder.cs +++ b/Editor/ObjectMapping/ObjectMappingBuilder.cs @@ -10,7 +10,8 @@ namespace Anatawa12.AvatarOptimizer /// /// The class manages Object location mapping /// - internal class ObjectMappingBuilder + internal class ObjectMappingBuilder + where TPropInfo : struct, IPropertyInfo { // Responsibility of this class can be classified to the following parts // - Track moving GameObjects @@ -76,10 +77,10 @@ public void RecordCopyProperty(ComponentOrGameObject fromComponent, string oldPr public void RecordRemoveProperty(ComponentOrGameObject from, string oldProp) => GetComponentInfo(from).RemoveProperty(oldProp); - public AnimationComponentInfo GetAnimationComponent(ComponentOrGameObject component) + public AnimationComponentInfo GetAnimationComponent(ComponentOrGameObject component) => GetComponentInfo(component); - public IEnumerable GetAllAnimationComponents() => + public IEnumerable> GetAllAnimationComponents() => _componentInfos.Values.Where(x => !x.IsMerged); private BuildingComponentInfo GetComponentInfo(ComponentOrGameObject component) @@ -107,7 +108,7 @@ class AnimationPropertyInfo [CanBeNull] public AnimationPropertyInfo MergedTo { get; private set; } private MappedPropertyInfo? _mappedPropertyInfo; - public PropertyInfo PropertyInfo; + public TPropInfo PropertyInfo; [CanBeNull] public List CopiedTo { get; private set; } @@ -182,7 +183,7 @@ private MappedPropertyInfo ComputeMappedInfo() } } - class BuildingComponentInfo : AnimationComponentInfo + class BuildingComponentInfo : AnimationComponentInfo { internal readonly int InstanceId; internal readonly Type Type; @@ -293,15 +294,15 @@ public override ComponentOrGameObject TargetComponent public override string[] Properties => _afterPropertyIds.Keys.ToArray(); - public override ref PropertyInfo GetPropertyInfo(string property) => ref GetProperty(property).PropertyInfo; - public override PropertyInfo TryGetPropertyInfo(string property) + public override ref TPropInfo GetPropertyInfo(string property) => ref GetProperty(property).PropertyInfo; + public override TPropInfo TryGetPropertyInfo(string property) { if (_afterPropertyIds.TryGetValue(property, out var info)) return info.PropertyInfo; return default; } - public override IEnumerable<(string, PropertyInfo)> GetAllPropertyInfo => + public override IEnumerable<(string name, TPropInfo info)> GetAllPropertyInfo => _afterPropertyIds.Select((x) => (x.Key, x.Value.PropertyInfo)); } } @@ -313,15 +314,16 @@ internal interface IPropertyInfo void CopyTo(ref T property); } - internal abstract class AnimationComponentInfo + internal abstract class AnimationComponentInfo + where TPropInfo : struct, IPropertyInfo { public abstract string[] Properties { get; } public abstract ComponentOrGameObject TargetComponent { get; } public abstract void RemoveProperty(string property); - public abstract ref PropertyInfo GetPropertyInfo(string property); - public abstract PropertyInfo TryGetPropertyInfo(string property); - public abstract IEnumerable<(string name, PropertyInfo info)> GetAllPropertyInfo { get; } + public abstract ref TPropInfo GetPropertyInfo(string property); + public abstract TPropInfo TryGetPropertyInfo(string property); + public abstract IEnumerable<(string name, TPropInfo info)> GetAllPropertyInfo { get; } } } diff --git a/Editor/ObjectMapping/ObjectMappingContext.cs b/Editor/ObjectMapping/ObjectMappingContext.cs index 4af5da600..89b6de39d 100644 --- a/Editor/ObjectMapping/ObjectMappingContext.cs +++ b/Editor/ObjectMapping/ObjectMappingContext.cs @@ -13,11 +13,11 @@ namespace Anatawa12.AvatarOptimizer { internal class ObjectMappingContext : IExtensionContext { - public ObjectMappingBuilder MappingBuilder { get; private set; } + public ObjectMappingBuilder MappingBuilder { get; private set; } public void OnActivate(BuildContext context) { - MappingBuilder = new ObjectMappingBuilder(context.AvatarRootObject); + MappingBuilder = new ObjectMappingBuilder(context.AvatarRootObject); } public void OnDeactivate(BuildContext context) diff --git a/Editor/ObjectMapping/PropertyInfo.cs b/Editor/ObjectMapping/PropertyInfo.cs index f0e148d85..b4f07030d 100644 --- a/Editor/ObjectMapping/PropertyInfo.cs +++ b/Editor/ObjectMapping/PropertyInfo.cs @@ -82,7 +82,7 @@ public void AddModification(ComponentPropModNodeBase node, bool alwaysAp internal static class AnimationComponentInfoExtensions { - public static void ImportModifications([NotNull] this ObjectMappingBuilder builder, + public static void ImportModifications([NotNull] this ObjectMappingBuilder builder, RootPropModNodeContainer modifications) { foreach (var ((target, prop), value) in modifications.FloatNodes) @@ -92,13 +92,15 @@ public static void ImportModifications([NotNull] this ObjectMappingBuilder build builder.GetAnimationComponent(target).GetPropertyInfo(prop).ImportProperty(value); } - public static bool ContainsFloat([NotNull] this AnimationComponentInfo info, string property) + public static bool ContainsFloat([NotNull] this AnimationComponentInfo info, string property) { if (info == null) throw new ArgumentNullException(nameof(info)); return info.TryGetPropertyInfo(property).FloatNode != null; } - public static bool TryGetFloat([NotNull] this AnimationComponentInfo info, string property, + [Pure] + [ContractAnnotation("=> true, animation: notnull; => false, animation: null")] + public static bool TryGetFloat([NotNull] this AnimationComponentInfo info, string property, [CanBeNull] out RootPropModNode animation) { if (info == null) throw new ArgumentNullException(nameof(info)); @@ -106,20 +108,20 @@ public static bool TryGetFloat([NotNull] this AnimationComponentInfo info, strin return animation != null; } - public static void AddModification([NotNull] this AnimationComponentInfo info, string property, + public static void AddModification([NotNull] this AnimationComponentInfo info, string property, ComponentPropModNodeBase node, bool alwaysApplied) { if (info == null) throw new ArgumentNullException(nameof(info)); info.GetPropertyInfo(property).AddModification(node, alwaysApplied); } - public static bool ContainsObject([NotNull] this AnimationComponentInfo info, string property) + public static bool ContainsObject([NotNull] this AnimationComponentInfo info, string property) { if (info == null) throw new ArgumentNullException(nameof(info)); return info.TryGetPropertyInfo(property).ObjectNode != null; } - public static bool TryGetObject([NotNull] this AnimationComponentInfo info, string property, + public static bool TryGetObject([NotNull] this AnimationComponentInfo info, string property, out RootPropModNode animation) { if (info == null) throw new ArgumentNullException(nameof(info)); @@ -127,7 +129,7 @@ public static bool TryGetObject([NotNull] this AnimationComponentInfo info, stri return animation != null; } - public static void AddModification([NotNull] this AnimationComponentInfo info, string property, + public static void AddModification([NotNull] this AnimationComponentInfo info, string property, ComponentPropModNodeBase node, bool alwaysApplied) { if (info == null) throw new ArgumentNullException(nameof(info)); @@ -135,14 +137,14 @@ public static void AddModification([NotNull] this AnimationComponentInfo info, s } public static IEnumerable<(string, RootPropModNode)> GetAllFloatProperties( - [NotNull] this AnimationComponentInfo info) + [NotNull] this AnimationComponentInfo info) { return info.GetAllPropertyInfo.Where(x => x.info.FloatNode != null) .Select(x => (x.name, x.info.FloatNode)); } public static IEnumerable<(string, RootPropModNode)> GetAllObjectProperties( - [NotNull] this AnimationComponentInfo info) + [NotNull] this AnimationComponentInfo info) { return info.GetAllPropertyInfo.Where(x => x.info.ObjectNode != null) .Select(x => (x.name, x.info.ObjectNode)); diff --git a/Editor/Processors/TraceAndOptimize/OptimizePhysBone.cs b/Editor/Processors/TraceAndOptimize/OptimizePhysBone.cs index 4757ab6ff..dd6276659 100644 --- a/Editor/Processors/TraceAndOptimize/OptimizePhysBone.cs +++ b/Editor/Processors/TraceAndOptimize/OptimizePhysBone.cs @@ -164,7 +164,7 @@ private void IsAnimatedOptimization(BuildContext context) } } - private static bool IsAnimatedExternally(VRCPhysBoneBase physBone, AnimationComponentInfo animation) + private static bool IsAnimatedExternally(VRCPhysBoneBase physBone, AnimationComponentInfo animation) { foreach (var transformProperty in TransformProperties) { diff --git a/Test~/ApplyObjectMappingTest.cs b/Test~/ApplyObjectMappingTest.cs index c2f6bb80b..a235e9e7c 100644 --- a/Test~/ApplyObjectMappingTest.cs +++ b/Test~/ApplyObjectMappingTest.cs @@ -13,7 +13,7 @@ public void AvatarMask() var root = new GameObject(); var child1 = Utils.NewGameObject("child1", root.transform); var child11 = Utils.NewGameObject("child11", child1.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); child11.name = "child12"; @@ -49,7 +49,7 @@ public void PreserveAnimationLength() var root = new GameObject(); var child1 = Utils.NewGameObject("child1", root.transform); var child11 = Utils.NewGameObject("child11", child1.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); Object.DestroyImmediate(child11); @@ -85,7 +85,7 @@ public void PreserveProxyAnimation() var root = new GameObject(); var child1 = Utils.NewGameObject("child1", root.transform); var child11 = Utils.NewGameObject("child11", child1.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); Object.DestroyImmediate(child11); diff --git a/Test~/ObjectMappingTest.cs b/Test~/ObjectMappingTest.cs index d03c577cb..a9bcd461a 100644 --- a/Test~/ObjectMappingTest.cs +++ b/Test~/ObjectMappingTest.cs @@ -7,6 +7,17 @@ namespace Anatawa12.AvatarOptimizer.Test { + struct DummyPropInfo : IPropertyInfo + { + public void MergeTo(ref DummyPropInfo property) + { + } + + public void CopyTo(ref DummyPropInfo property) + { + } + } + public class ObjectMappingTest { [TestCase("")] @@ -50,7 +61,7 @@ public void PathResolution(string testPath) }), }); - var builder = new ObjectMappingBuilder(root).BuildObjectMapping().GetBeforeGameObjectTree(root); + var builder = new ObjectMappingBuilder(root).BuildObjectMapping().GetBeforeGameObjectTree(root); var transform = (Transform) AnimationUtility.GetAnimatedObject(root, EditorCurveBinding.FloatCurve(testPath, typeof(Transform), "m_LocalPosition.x")); @@ -71,7 +82,7 @@ public void MoveObjectTest() var child111 = Utils.NewGameObject("child111", child11.transform); var child2 = Utils.NewGameObject("child2", root.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); child11.transform.parent = child2.transform; builder.RecordMoveProperty(child111, "m_IsActive", "m_IsActive"); @@ -100,7 +111,7 @@ public void RecordRemoveGameObject() var child11 = Utils.NewGameObject("child11", child1.transform); var child111 = Utils.NewGameObject("child111", child11.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); Object.DestroyImmediate(child11); var built = builder.BuildObjectMapping(); @@ -129,7 +140,7 @@ public void RecordMoveComponentTest() var child2 = Utils.NewGameObject("child2", root.transform); var child2Component = child2.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMergeComponent(child1Component, child2Component); Object.DestroyImmediate(child1Component); var child1ComponentId = child1Component.GetInstanceID(); @@ -159,7 +170,7 @@ public void RecordRemoveComponentTest() var child1 = Utils.NewGameObject("child1", root.transform); var child1Component = child1.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); Object.DestroyImmediate(child1Component); var child1ComponentId = child1Component.GetInstanceID(); @@ -187,7 +198,7 @@ public void RecordMovePropertyTest() var child1 = Utils.NewGameObject("child1", root.transform); var child1Component = child1.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMoveProperty(child1Component, "blendShapes.test", "blendShapes.changed"); var built = builder.BuildObjectMapping(); @@ -211,7 +222,7 @@ public void RecordSwapPropertyTest() var child1 = Utils.NewGameObject("child1", root.transform); var child1Component = child1.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMoveProperties(child1Component, ("blendShapes.first", "blendShapes.second"), ("blendShapes.second", "blendShapes.first")); @@ -237,7 +248,7 @@ public void RecordMovePropertyTwiceTest() var child1 = Utils.NewGameObject("child1", root.transform); var child1Component = child1.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMoveProperty(child1Component, "blendShapes.test", "blendShapes.changed0"); builder.RecordMoveProperty(child1Component, "blendShapes.changed0", "blendShapes.changed"); @@ -260,7 +271,7 @@ public void RecordRemovePropertyTest() var child1 = Utils.NewGameObject("child1", root.transform); var child1Component = child1.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordRemoveProperty(child1Component, "blendShapes.test"); var built = builder.BuildObjectMapping(); @@ -285,7 +296,7 @@ public void RecordMovePropertyThenComponentThenPropertyTest() var child1Component = child1.AddComponent(); var child2Component = child2.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMoveProperty(child2Component, "blendShapes.child2", "blendShapes.child2Changed"); builder.RecordMoveProperty(child1Component, "blendShapes.child1", "blendShapes.child1Changed"); builder.RecordMergeComponent(child1Component, child2Component); @@ -330,7 +341,7 @@ public void RecordMovePropertyThenGameObjectThenPropertyTest() var child11Component = child11.AddComponent(); var child2 = Utils.NewGameObject("child2", root.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMoveProperty(child11Component, "blendShapes.child11", "blendShapes.child11Changed"); child11.transform.parent = child2.transform; builder.RecordMoveProperty(child11Component, "blendShapes.moved", "blendShapes.movedChanged"); @@ -358,7 +369,7 @@ public void RecordRemovePropertyThenMergeComponent() var child2 = Utils.NewGameObject("child2", root.transform); var child2Component = child2.AddComponent(); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordRemoveProperty(child1Component, "m_Enabled"); builder.RecordMergeComponent(child1Component, child2Component); Object.DestroyImmediate(child1Component); @@ -388,7 +399,7 @@ public void RecordMoveProperty() var child11Component = child11.AddComponent(); var child2 = Utils.NewGameObject("child2", root.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMoveProperty(child11Component, "blendShapes.child11", "blendShapes.child11Changed"); child11.transform.parent = child2.transform; builder.RecordMoveProperty(child11Component, "blendShapes.moved", "blendShapes.movedChanged"); @@ -414,7 +425,7 @@ public void MovePropertyOfGameObject() var child1 = Utils.NewGameObject("child1", root.transform); var child11 = Utils.NewGameObject("child11", child1.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordMoveProperty(child11, "m_IsActive", child1, "m_IsActive"); var built = builder.BuildObjectMapping(); @@ -437,7 +448,7 @@ public void CopyProperty() var child13 = Utils.NewGameObject("child13", child1.transform); var child14 = Utils.NewGameObject("child14", child1.transform); - var builder = new ObjectMappingBuilder(root); + var builder = new ObjectMappingBuilder(root); builder.RecordCopyProperty(child11, "m_IsActive", child12, "m_IsActive"); builder.RecordCopyProperty(child11, "m_IsActive", From eeb4c4e69c9a16fa816fb41ed69f67123b8ac59a Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 19:17:33 +0900 Subject: [PATCH 04/11] refactor: separate assembly for animator optimizer --- Editor/AnimatorController.meta | 3 - Editor/Math.meta | 3 - Editor/ObjectMapping/AnimationObjectMapper.cs | 2 - .../Processors/InitializeAnimatorOptimizer.cs | 178 ++++++++++++++++++ .../InitializeAnimatorOptimizer.cs.meta | 3 + .../Processors}/RemoveInvalidProperties.cs | 0 .../RemoveInvalidProperties.cs.meta | 0 ...m.anatawa12.avatar-optimizer.editor.asmdef | 1 + Internal/AnimatorOptimizer/AnimOptPassBase.cs | 175 +---------------- .../AnimatorOptimizer/EntryExitToBlendTree.cs | 4 +- .../AnimatorOptimizer/MergeDirectBlendTree.cs | 4 +- .../RemoveMeaninglessLayer.cs | 4 +- Internal/AnimatorOptimizer/Wrappers.cs | 4 +- ...com.anatawa12.avatar-optimizer.test.asmdef | 3 + 14 files changed, 196 insertions(+), 188 deletions(-) delete mode 100644 Editor/AnimatorController.meta delete mode 100644 Editor/Math.meta create mode 100644 Editor/Processors/InitializeAnimatorOptimizer.cs create mode 100644 Editor/Processors/InitializeAnimatorOptimizer.cs.meta rename {Internal/AnimatorOptimizer => Editor/Processors}/RemoveInvalidProperties.cs (100%) rename {Internal/AnimatorOptimizer => Editor/Processors}/RemoveInvalidProperties.cs.meta (100%) diff --git a/Editor/AnimatorController.meta b/Editor/AnimatorController.meta deleted file mode 100644 index 3eace67a2..000000000 --- a/Editor/AnimatorController.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 81c1ed3fba26461bbf5f43e44ca587d6 -timeCreated: 1706529121 \ No newline at end of file diff --git a/Editor/Math.meta b/Editor/Math.meta deleted file mode 100644 index 184346af0..000000000 --- a/Editor/Math.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b23d60111e714d6984985a989d40d547 -timeCreated: 1692953113 \ No newline at end of file diff --git a/Editor/ObjectMapping/AnimationObjectMapper.cs b/Editor/ObjectMapping/AnimationObjectMapper.cs index cd3f54b39..f874adc76 100644 --- a/Editor/ObjectMapping/AnimationObjectMapper.cs +++ b/Editor/ObjectMapping/AnimationObjectMapper.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes; using JetBrains.Annotations; using UnityEditor; using UnityEngine; diff --git a/Editor/Processors/InitializeAnimatorOptimizer.cs b/Editor/Processors/InitializeAnimatorOptimizer.cs new file mode 100644 index 000000000..de879372b --- /dev/null +++ b/Editor/Processors/InitializeAnimatorOptimizer.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; +using Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes; +using JetBrains.Annotations; +using nadena.dev.ndmf; +using UnityEditor; +using UnityEditor.Animations; +using UnityEngine; +using UnityEngine.Profiling; +using Object = UnityEngine.Object; + +#if AAO_VRCSDK3_AVATARS +using VRC.SDKBase; +using VRC.SDK3.Avatars.Components; +#endif + +namespace Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer +{ + // This pass prepares animator optimizer + // This pass does the following things: + // - Collects all AnimatorController objects and save to state + // - Clones AnimatorController and StateMachines to avoid modifying original AnimatorController if needed + // - If the RuntimeAnimatorController is AnimatorOverrideController, convert it to AnimatorController + class InitializeAnimatorOptimizer : TraceAndOptimizePass + { + public override string DisplayName => "AnimOpt: Initialize"; + + protected override void Execute(BuildContext context, TraceAndOptimizeState state) + { + if (!state.OptimizeAnimator) return; + + var animatorState = context.GetState(); + +#if AAO_VRCSDK3_AVATARS + // According to VRCSDK 3.5.0, default animation controllers doesn't have AnimatorLayerWeightControl so + // we don't have to care about them. + var changerBehaviours = new AnimatorLayerMap>(); + { + changerBehaviours[VRCAvatarDescriptor.AnimLayerType.Action] = new HashSet(); + changerBehaviours[VRCAvatarDescriptor.AnimLayerType.FX] = new HashSet(); + changerBehaviours[VRCAvatarDescriptor.AnimLayerType.Gesture] = new HashSet(); + changerBehaviours[VRCAvatarDescriptor.AnimLayerType.Additive] = new HashSet(); + } +#endif + var clonedToController = new Dictionary(); + + foreach (var component in context.AvatarRootObject.GetComponents()) + { + using (var serializedObject = new SerializedObject(component)) + { + foreach (var property in serializedObject.ObjectReferenceProperties()) + { + if (property.objectReferenceValue is RuntimeAnimatorController runtimeController) + { + var cloned = AnimatorControllerCloner.Clone(context, runtimeController); + var wrapper = new AOAnimatorController(cloned); + animatorState.Add(wrapper); + property.objectReferenceValue = cloned; + clonedToController.Add(cloned, wrapper); + +#if AAO_VRCSDK3_AVATARS + foreach (var behaviour in ACUtils.StateMachineBehaviours(cloned)) + { + switch (behaviour) + { + case VRC_AnimatorLayerControl control: + if (control.playable.ToAnimLayerType() is VRCAvatarDescriptor.AnimLayerType l) + changerBehaviours[l].Add(control); + break; + } + } +#endif + } + } + + serializedObject.ApplyModifiedPropertiesWithoutUndo(); + } + } + +#if AAO_VRCSDK3_AVATARS + { + var descriptor = context.AvatarDescriptor; + if (descriptor && descriptor.customizeAnimationLayers) + { + foreach (var playableLayer in descriptor.baseAnimationLayers) + { + if (playableLayer.isDefault || !playableLayer.animatorController || + changerBehaviours[playableLayer.type] == null) continue; + + var wrapper = clonedToController[(AnimatorController)playableLayer.animatorController]; + + foreach (var control in changerBehaviours[playableLayer.type]) + { + if (control.layer < 0 || wrapper.layers.Length <= control.layer) continue; + + var ourChange = + AnimatorWeightChanges.ForDurationAndWeight(control.blendDuration, control.goalWeight); + + var layer = wrapper.layers[control.layer]; + + layer.WeightChange = layer.WeightChange.Merge(ourChange); + layer.LayerIndexUpdated += index => control.layer = index; + } + + // process MMD world compatibility + if (playableLayer.type == VRCAvatarDescriptor.AnimLayerType.FX && state.MmdWorldCompatibility) + { + for (var i = 1; i <= 2; i++) + { + if (wrapper.layers.Length > i) + { + wrapper.layers[i].MarkUnRemovable(); + wrapper.layers[i].WeightChange = wrapper.layers[i].WeightChange + .Merge(AnimatorWeightChange.EitherZeroOrOne); + } + } + } + } + } + } +#endif + } + } + + class AnimatorControllerCloner : DeepCloneHelper + { + [NotNull] private readonly BuildContext _context; + [CanBeNull] private readonly IReadOnlyDictionary _mapping; + + private AnimatorControllerCloner([NotNull] BuildContext context, + [CanBeNull] IReadOnlyDictionary mapping) + { + _context = context ?? throw new ArgumentNullException(nameof(context)); + _mapping = mapping; + } + + public static AnimatorController Clone([NotNull] BuildContext context, + [NotNull] RuntimeAnimatorController runtimeController) + { + var (controller, mapping) = ACUtils.GetControllerAndOverrides(runtimeController); + + return new AnimatorControllerCloner(context, mapping).MapObject(controller); + } + + protected override Object CustomClone(Object o) + { + if (o is AnimationClip clip) + { + if (_mapping != null && _mapping.TryGetValue(clip, out var mapped)) + return mapped; + return clip; + } + + return null; + } + + protected override ComponentSupport GetComponentSupport(Object o) + { + switch (o) + { + case AnimatorController _: + case AnimatorStateMachine _: + case AnimatorState _: + case AnimatorTransitionBase _: + case StateMachineBehaviour _: + case Motion _ : + return ComponentSupport.Clone; + + // should not reach this case + case RuntimeAnimatorController _: + return ComponentSupport.Unsupported; + + default: + return ComponentSupport.NoClone; + } + } + } +} diff --git a/Editor/Processors/InitializeAnimatorOptimizer.cs.meta b/Editor/Processors/InitializeAnimatorOptimizer.cs.meta new file mode 100644 index 000000000..e34594822 --- /dev/null +++ b/Editor/Processors/InitializeAnimatorOptimizer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 63ad087c73b840ec9c199672031e950f +timeCreated: 1711014835 \ No newline at end of file diff --git a/Internal/AnimatorOptimizer/RemoveInvalidProperties.cs b/Editor/Processors/RemoveInvalidProperties.cs similarity index 100% rename from Internal/AnimatorOptimizer/RemoveInvalidProperties.cs rename to Editor/Processors/RemoveInvalidProperties.cs diff --git a/Internal/AnimatorOptimizer/RemoveInvalidProperties.cs.meta b/Editor/Processors/RemoveInvalidProperties.cs.meta similarity index 100% rename from Internal/AnimatorOptimizer/RemoveInvalidProperties.cs.meta rename to Editor/Processors/RemoveInvalidProperties.cs.meta diff --git a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef index 6d93a80fb..19613e8bb 100644 --- a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef +++ b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef @@ -9,6 +9,7 @@ "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "com.anatawa12.avatar-optimizer.internal.object-mapping", "com.anatawa12.avatar-optimizer.internal.animator-optimizer", "com.anatawa12.avatar-optimizer.internal.meshinfo2", "com.anatawa12.avatar-optimizer.internal.utils", diff --git a/Internal/AnimatorOptimizer/AnimOptPassBase.cs b/Internal/AnimatorOptimizer/AnimOptPassBase.cs index 723a30a9c..7edde9f59 100644 --- a/Internal/AnimatorOptimizer/AnimOptPassBase.cs +++ b/Internal/AnimatorOptimizer/AnimOptPassBase.cs @@ -1,22 +1,13 @@ -using System; using System.Collections.Generic; using Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes; -using JetBrains.Annotations; using nadena.dev.ndmf; using UnityEditor; -using UnityEditor.Animations; using UnityEngine; using UnityEngine.Profiling; -using Object = UnityEngine.Object; - -#if AAO_VRCSDK3_AVATARS -using VRC.SDKBase; -using VRC.SDK3.Avatars.Components; -#endif namespace Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer { - class AnimatorOptimizerState + public class AnimatorOptimizerState { private List _contollers = new List(); public IEnumerable Controllers => _contollers; @@ -58,7 +49,7 @@ private static bool IsTimeDependentClipImpl(AnimationClip clip) } } - abstract class AnimOptPassBase : TraceAndOptimizePass where T : TraceAndOptimizePass, new() + public abstract class AnimOptPassBase : TraceAndOptimizePass where T : TraceAndOptimizePass, new() { public override string DisplayName => "T&O: AnimOpt: " + typeof(T).Name; @@ -73,167 +64,7 @@ protected sealed override void Execute(BuildContext context, TraceAndOptimizeSta } } - protected abstract void Execute(BuildContext context, AOAnimatorController controller, + private protected abstract void Execute(BuildContext context, AOAnimatorController controller, TraceAndOptimizeState settings); } - - // This pass prepares animator optimizer - // This pass does the following things: - // - Collects all AnimatorController objects and save to state - // - Clones AnimatorController and StateMachines to avoid modifying original AnimatorController if needed - // - If the RuntimeAnimatorController is AnimatorOverrideController, convert it to AnimatorController - class InitializeAnimatorOptimizer : TraceAndOptimizePass - { - public override string DisplayName => "AnimOpt: Initialize"; - - protected override void Execute(BuildContext context, TraceAndOptimizeState state) - { - if (!state.OptimizeAnimator) return; - - var animatorState = context.GetState(); - -#if AAO_VRCSDK3_AVATARS - // According to VRCSDK 3.5.0, default animation controllers doesn't have AnimatorLayerWeightControl so - // we don't have to care about them. - var changerBehaviours = new AnimatorLayerMap>(); - { - changerBehaviours[VRCAvatarDescriptor.AnimLayerType.Action] = new HashSet(); - changerBehaviours[VRCAvatarDescriptor.AnimLayerType.FX] = new HashSet(); - changerBehaviours[VRCAvatarDescriptor.AnimLayerType.Gesture] = new HashSet(); - changerBehaviours[VRCAvatarDescriptor.AnimLayerType.Additive] = new HashSet(); - } -#endif - var clonedToController = new Dictionary(); - - foreach (var component in context.AvatarRootObject.GetComponents()) - { - using (var serializedObject = new SerializedObject(component)) - { - foreach (var property in serializedObject.ObjectReferenceProperties()) - { - if (property.objectReferenceValue is RuntimeAnimatorController runtimeController) - { - var cloned = AnimatorControllerCloner.Clone(context, runtimeController); - var wrapper = new AOAnimatorController(cloned); - animatorState.Add(wrapper); - property.objectReferenceValue = cloned; - clonedToController.Add(cloned, wrapper); - -#if AAO_VRCSDK3_AVATARS - foreach (var behaviour in ACUtils.StateMachineBehaviours(cloned)) - { - switch (behaviour) - { - case VRC_AnimatorLayerControl control: - if (control.playable.ToAnimLayerType() is VRCAvatarDescriptor.AnimLayerType l) - changerBehaviours[l].Add(control); - break; - } - } -#endif - } - } - - serializedObject.ApplyModifiedPropertiesWithoutUndo(); - } - } - -#if AAO_VRCSDK3_AVATARS - { - var descriptor = context.AvatarDescriptor; - if (descriptor && descriptor.customizeAnimationLayers) - { - foreach (var playableLayer in descriptor.baseAnimationLayers) - { - if (playableLayer.isDefault || !playableLayer.animatorController || - changerBehaviours[playableLayer.type] == null) continue; - - var wrapper = clonedToController[(AnimatorController)playableLayer.animatorController]; - - foreach (var control in changerBehaviours[playableLayer.type]) - { - if (control.layer < 0 || wrapper.layers.Length <= control.layer) continue; - - var ourChange = - AnimatorWeightChanges.ForDurationAndWeight(control.blendDuration, control.goalWeight); - - var layer = wrapper.layers[control.layer]; - - layer.WeightChange = layer.WeightChange.Merge(ourChange); - layer.LayerIndexUpdated += index => control.layer = index; - } - - // process MMD world compatibility - if (playableLayer.type == VRCAvatarDescriptor.AnimLayerType.FX && state.MmdWorldCompatibility) - { - for (var i = 1; i <= 2; i++) - { - if (wrapper.layers.Length > i) - { - wrapper.layers[i].MarkUnRemovable(); - wrapper.layers[i].WeightChange = wrapper.layers[i].WeightChange - .Merge(AnimatorWeightChange.EitherZeroOrOne); - } - } - } - } - } - } -#endif - } - } - - class AnimatorControllerCloner : DeepCloneHelper - { - [NotNull] private readonly BuildContext _context; - [CanBeNull] private readonly IReadOnlyDictionary _mapping; - - private AnimatorControllerCloner([NotNull] BuildContext context, - [CanBeNull] IReadOnlyDictionary mapping) - { - _context = context ?? throw new ArgumentNullException(nameof(context)); - _mapping = mapping; - } - - public static AnimatorController Clone([NotNull] BuildContext context, - [NotNull] RuntimeAnimatorController runtimeController) - { - var (controller, mapping) = ACUtils.GetControllerAndOverrides(runtimeController); - - return new AnimatorControllerCloner(context, mapping).MapObject(controller); - } - - protected override Object CustomClone(Object o) - { - if (o is AnimationClip clip) - { - if (_mapping != null && _mapping.TryGetValue(clip, out var mapped)) - return mapped; - return clip; - } - - return null; - } - - protected override ComponentSupport GetComponentSupport(Object o) - { - switch (o) - { - case AnimatorController _: - case AnimatorStateMachine _: - case AnimatorState _: - case AnimatorTransitionBase _: - case StateMachineBehaviour _: - case Motion _ : - return ComponentSupport.Clone; - - // should not reach this case - case RuntimeAnimatorController _: - return ComponentSupport.Unsupported; - - default: - return ComponentSupport.NoClone; - } - } - } } diff --git a/Internal/AnimatorOptimizer/EntryExitToBlendTree.cs b/Internal/AnimatorOptimizer/EntryExitToBlendTree.cs index 28ddccac0..d1e10881e 100644 --- a/Internal/AnimatorOptimizer/EntryExitToBlendTree.cs +++ b/Internal/AnimatorOptimizer/EntryExitToBlendTree.cs @@ -34,9 +34,9 @@ namespace Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer // - all states have same write defaults value // - if write defaults is off, all states have same animating properties // - all states must not have motion time. you have to use 1d blend tree for gesture weight. - class EntryExitToBlendTree : AnimOptPassBase + public class EntryExitToBlendTree : AnimOptPassBase { - protected override void Execute(BuildContext context, AOAnimatorController controller, + private protected override void Execute(BuildContext context, AOAnimatorController controller, TraceAndOptimizeState settings) { if (settings.SkipEntryExitToBlendTree) return; // feature disabled diff --git a/Internal/AnimatorOptimizer/MergeDirectBlendTree.cs b/Internal/AnimatorOptimizer/MergeDirectBlendTree.cs index 553bd5f17..ed3f94b43 100644 --- a/Internal/AnimatorOptimizer/MergeDirectBlendTree.cs +++ b/Internal/AnimatorOptimizer/MergeDirectBlendTree.cs @@ -9,9 +9,9 @@ namespace Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer { - internal class MergeDirectBlendTree : AnimOptPassBase + public class MergeDirectBlendTree : AnimOptPassBase { - protected override void Execute(BuildContext context, AOAnimatorController controller, + private protected override void Execute(BuildContext context, AOAnimatorController controller, TraceAndOptimizeState settings) { if (!settings.SkipMergeDirectBlendTreeLayers) return; diff --git a/Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs b/Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs index 1f2dce6e4..39100e75d 100644 --- a/Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs +++ b/Internal/AnimatorOptimizer/RemoveMeaninglessLayer.cs @@ -4,9 +4,9 @@ namespace Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer { - class RemoveMeaninglessLayer : AnimOptPassBase + public class RemoveMeaninglessLayer : AnimOptPassBase { - protected override void Execute(BuildContext context, AOAnimatorController controller, TraceAndOptimizeState settings) + private protected override void Execute(BuildContext context, AOAnimatorController controller, TraceAndOptimizeState settings) { if (settings.SkipRemoveMeaninglessAnimatorLayer) return; Execute(controller); diff --git a/Internal/AnimatorOptimizer/Wrappers.cs b/Internal/AnimatorOptimizer/Wrappers.cs index a474a833c..978b45f3a 100644 --- a/Internal/AnimatorOptimizer/Wrappers.cs +++ b/Internal/AnimatorOptimizer/Wrappers.cs @@ -10,7 +10,7 @@ namespace Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer { - class AOAnimatorController + public class AOAnimatorController { private AnimatorController _animatorController; @@ -79,7 +79,7 @@ public void UpdateLayers() } } - class AOAnimatorControllerLayer + public class AOAnimatorControllerLayer { public readonly AnimatorControllerLayer Layer; private readonly AOAnimatorController _parent; diff --git a/Test~/com.anatawa12.avatar-optimizer.test.asmdef b/Test~/com.anatawa12.avatar-optimizer.test.asmdef index a961a7d81..56d2d25ed 100644 --- a/Test~/com.anatawa12.avatar-optimizer.test.asmdef +++ b/Test~/com.anatawa12.avatar-optimizer.test.asmdef @@ -9,6 +9,9 @@ "com.anatawa12.avatar-optimizer.runtime", "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", + "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "com.anatawa12.avatar-optimizer.internal.meshinfo2", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", "com.anatawa12.avatar-optimizer.internal.utils", "com.anatawa12.avatar-optimizer.api.editor", "UnityEngine.TestRunner", From 6d1117b7f2e5fe5af59175a9a26646327b612bc3 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 20:18:20 +0900 Subject: [PATCH 05/11] chore: make main parts of AnimatorOptimizer requires 2021 --- Editor/OptimizerPlugin.cs | 3 +++ ...a12.avatar-optimizer.internal.animator-optimizer.asmdef | 4 +++- Internal/AnimatorOptimizer/csc.rsp | 1 - Internal/AnimatorOptimizer/csc.rsp.meta | 7 ------- 4 files changed, 6 insertions(+), 9 deletions(-) delete mode 120000 Internal/AnimatorOptimizer/csc.rsp delete mode 100644 Internal/AnimatorOptimizer/csc.rsp.meta diff --git a/Editor/OptimizerPlugin.cs b/Editor/OptimizerPlugin.cs index 1b765d425..f87e98156 100644 --- a/Editor/OptimizerPlugin.cs +++ b/Editor/OptimizerPlugin.cs @@ -75,6 +75,8 @@ protected override void Configure() ; }); +#if UNITY_2021_3_OR_NEWER + // animator optimizer is written in newer C# so requires 2021.3 or newer mainSequence.Run(Processors.AnimatorOptimizer.InitializeAnimatorOptimizer.Instance) #if AAO_VRCSDK3_AVATARS // EntryExit to BlendTree optimization heavily depends on VRChat's behavior @@ -83,6 +85,7 @@ protected override void Configure() .Then.Run(Processors.AnimatorOptimizer.MergeDirectBlendTree.Instance) .Then.Run(Processors.AnimatorOptimizer.RemoveMeaninglessLayer.Instance) ; +#endif } protected override void OnUnhandledException(Exception e) diff --git a/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef index 33e8520db..ba8be12a4 100644 --- a/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef +++ b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef @@ -36,7 +36,9 @@ "System.Memory.dll" ], "autoReferenced": false, - "defineConstraints": [], + "defineConstraints": [ + "UNITY_2021_3_OR_NEWER" + ], "versionDefines": [ { "name": "com.vrchat.avatars", diff --git a/Internal/AnimatorOptimizer/csc.rsp b/Internal/AnimatorOptimizer/csc.rsp deleted file mode 120000 index c6acf2e0a..000000000 --- a/Internal/AnimatorOptimizer/csc.rsp +++ /dev/null @@ -1 +0,0 @@ -../../Editor/csc.rsp \ No newline at end of file diff --git a/Internal/AnimatorOptimizer/csc.rsp.meta b/Internal/AnimatorOptimizer/csc.rsp.meta deleted file mode 100644 index 3bfb60ec6..000000000 --- a/Internal/AnimatorOptimizer/csc.rsp.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 3af2bb4b3344c465593860e8a31f6b4f -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 1ed8cedcfcf552dc9bae0543ce837f8802ec2805 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 20:30:57 +0900 Subject: [PATCH 06/11] chore: note that most features of OptimizeAnimator is not supported in 2019 --- Editor/Inspector/TraceAndOptimizeEditor.cs | 5 +++++ Localization/en.po | 3 +++ Localization/ja.po | 3 +++ 3 files changed, 11 insertions(+) diff --git a/Editor/Inspector/TraceAndOptimizeEditor.cs b/Editor/Inspector/TraceAndOptimizeEditor.cs index 45847559d..3ec3600a5 100644 --- a/Editor/Inspector/TraceAndOptimizeEditor.cs +++ b/Editor/Inspector/TraceAndOptimizeEditor.cs @@ -50,6 +50,11 @@ protected override void OnInspectorGUIInner() EditorGUILayout.PropertyField(_optimizePhysBone); EditorGUILayout.PropertyField(_optimizeAnimator); +#if !UNITY_2021_3_OR_NEWER + if (_optimizeAnimator.boolValue) + EditorGUILayout.HelpBox(AAOL10N.Tr("TraceAndOptimize:OptimizeAnimator:Unity2019"), MessageType.Info); +#endif + _advancedSettingsLabel.text = AAOL10N.Tr("TraceAndOptimize:prop:advancedSettings"); if (EditorGUILayout.PropertyField(_advancedSettings, _advancedSettingsLabel, false)) { diff --git a/Localization/en.po b/Localization/en.po index 293eddb7a..0ab968ac3 100644 --- a/Localization/en.po +++ b/Localization/en.po @@ -512,6 +512,9 @@ msgstr "Automatically Remove Zero Sized Polygons" msgid "TraceAndOptimize:OptimizePhysBone:UnknownPhysBoneColliderShape" msgstr "Unknown PhysBone Collider Shape '{0}' is specified." +msgid "TraceAndOptimize:OptimizeAnimator:Unity2019" +msgstr "Most features of Optimize Animator is not supported on Unity 2019. Please consider use Unity 2021 or later." + # endregion #region ApplyObjectMapping diff --git a/Localization/ja.po b/Localization/ja.po index 5f6e38491..99ba8ee39 100644 --- a/Localization/ja.po +++ b/Localization/ja.po @@ -421,6 +421,9 @@ msgstr "面積がゼロのポリゴンを自動的に削除する" msgid "TraceAndOptimize:OptimizePhysBone:UnknownPhysBoneColliderShape" msgstr "未知のPhysBone Collider形状'{0}'が指定されています。" +msgid "TraceAndOptimize:OptimizeAnimator:Unity2019" +msgstr "Unity 2019では、Optimize Animatorの多くの機能がサポートされていません。Unity 2021以降に更新するのをご検討ください。" + # endregion #region ApplyObjectMapping From 3a86e17368e75b34691d2cb3fdfbdfe5389e9a74 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 21:11:35 +0900 Subject: [PATCH 07/11] chore: optimize reference assemblies --- ...timizer.internal.animator-optimizer.asmdef | 49 ++--------------- ...avatar-optimizer.internal.meshinfo2.asmdef | 41 +-------------- ...er.internal.trace-and-optimize-base.asmdef | 52 ++----------------- Internal/TraceAndOptimizeBase/csc.rsp | 1 + Internal/TraceAndOptimizeBase/csc.rsp.meta | 7 +++ 5 files changed, 16 insertions(+), 134 deletions(-) create mode 120000 Internal/TraceAndOptimizeBase/csc.rsp create mode 100644 Internal/TraceAndOptimizeBase/csc.rsp.meta diff --git a/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef index ba8be12a4..50bbe10dc 100644 --- a/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef +++ b/Internal/AnimatorOptimizer/com.anatawa12.avatar-optimizer.internal.animator-optimizer.asmdef @@ -2,21 +2,12 @@ "name": "com.anatawa12.avatar-optimizer.internal.animator-optimizer", "rootNamespace": "Anatawa12.AvatarOptimizer.Processors.AnimatorOptimizer", "references": [ - "com.anatawa12.avatar-optimizer.internal.localization.editor", - "com.anatawa12.avatar-optimizer.internal.localization.runtime", "com.anatawa12.avatar-optimizer.runtime", - "com.anatawa12.avatar-optimizer.internal.unsafe", - "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", - "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.localization.editor", "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", "com.anatawa12.avatar-optimizer.internal.meshinfo2", "com.anatawa12.avatar-optimizer.internal.utils", - "nadena.dev.ndmf", - "com.anatawa12.avatar-optimizer.api.editor", - "VRC.SDKBase", - "UniHumanoid", - "VRM", - "VRM10" + "nadena.dev.ndmf" ], "includePlatforms": [ "Editor" @@ -25,46 +16,12 @@ "allowUnsafeCode": false, "overrideReferences": true, "precompiledReferences": [ - "VRC.Dynamics.dll", - "VRC.SDK3.Dynamics.PhysBone.dll", - "VRC.SDK3.Dynamics.Contact.dll", - "VRCCore-Editor.dll", - "VRCSDK3A-Editor.dll", - "VRCSDK3A.dll", - "VRCSDKBase-Editor.dll", - "VRCSDKBase.dll", "System.Memory.dll" ], "autoReferenced": false, "defineConstraints": [ "UNITY_2021_3_OR_NEWER" ], - "versionDefines": [ - { - "name": "com.vrchat.avatars", - "expression": "", - "define": "AAO_VRCSDK3_AVATARS" - }, - { - "name": "com.vrchat.avatars", - "expression": "3.5.1", - "define": "AAO_VRCSDK3_AVATARS_IMPOSTER_SETTINGS" - }, - { - "name": "com.vrchat.avatars", - "expression": "3.5.2-beta.1", - "define": "AAO_VRCSDK3_AVATARS_3_5_2" - }, - { - "name": "com.vrmc.univrm", - "expression": "", - "define": "AAO_VRM0" - }, - { - "name": "com.vrmc.vrm", - "expression": "", - "define": "AAO_VRM1" - } - ], + "versionDefines": [], "noEngineReferences": false } \ No newline at end of file diff --git a/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef b/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef index 527c7c6a5..2c34c40ee 100644 --- a/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef +++ b/Internal/MeshInfo2/com.anatawa12.avatar-optimizer.internal.meshinfo2.asmdef @@ -7,10 +7,7 @@ "nadena.dev.ndmf", "com.anatawa12.avatar-optimizer.internal.utils", "com.anatawa12.avatar-optimizer.internal.localization.editor", - "VRC.SDKBase", - "UniHumanoid", - "VRM", - "VRM10" + "com.anatawa12.avatar-optimizer.internal.unsafe" ], "includePlatforms": [ "Editor" @@ -19,44 +16,10 @@ "allowUnsafeCode": false, "overrideReferences": true, "precompiledReferences": [ - "VRC.Dynamics.dll", - "VRC.SDK3.Dynamics.PhysBone.dll", - "VRC.SDK3.Dynamics.Contact.dll", - "VRCCore-Editor.dll", - "VRCSDK3A-Editor.dll", - "VRCSDK3A.dll", - "VRCSDKBase-Editor.dll", - "VRCSDKBase.dll", "System.Memory.dll" ], "autoReferenced": false, "defineConstraints": [], - "versionDefines": [ - { - "name": "com.vrchat.avatars", - "expression": "", - "define": "AAO_VRCSDK3_AVATARS" - }, - { - "name": "com.vrchat.avatars", - "expression": "3.5.1", - "define": "AAO_VRCSDK3_AVATARS_IMPOSTER_SETTINGS" - }, - { - "name": "com.vrchat.avatars", - "expression": "3.5.2-beta.1", - "define": "AAO_VRCSDK3_AVATARS_3_5_2" - }, - { - "name": "com.vrmc.univrm", - "expression": "", - "define": "AAO_VRM0" - }, - { - "name": "com.vrmc.vrm", - "expression": "", - "define": "AAO_VRM1" - } - ], + "versionDefines": [], "noEngineReferences": false } \ No newline at end of file diff --git a/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef b/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef index e618ca145..d9144a82f 100644 --- a/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef +++ b/Internal/TraceAndOptimizeBase/com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base.asmdef @@ -2,19 +2,9 @@ "name": "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", "rootNamespace": "Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes", "references": [ - "com.anatawa12.avatar-optimizer.internal.localization.editor", - "com.anatawa12.avatar-optimizer.internal.localization.runtime", "com.anatawa12.avatar-optimizer.runtime", - "com.anatawa12.avatar-optimizer.internal.unsafe", - "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", - "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", "com.anatawa12.avatar-optimizer.internal.utils", - "nadena.dev.ndmf", - "com.anatawa12.avatar-optimizer.api.editor", - "VRC.SDKBase", - "UniHumanoid", - "VRM", - "VRM10" + "nadena.dev.ndmf" ], "includePlatforms": [ "Editor" @@ -22,45 +12,9 @@ "excludePlatforms": [], "allowUnsafeCode": false, "overrideReferences": true, - "precompiledReferences": [ - "VRC.Dynamics.dll", - "VRC.SDK3.Dynamics.PhysBone.dll", - "VRC.SDK3.Dynamics.Contact.dll", - "VRCCore-Editor.dll", - "VRCSDK3A-Editor.dll", - "VRCSDK3A.dll", - "VRCSDKBase-Editor.dll", - "VRCSDKBase.dll", - "System.Memory.dll" - ], + "precompiledReferences": [], "autoReferenced": false, "defineConstraints": [], - "versionDefines": [ - { - "name": "com.vrchat.avatars", - "expression": "", - "define": "AAO_VRCSDK3_AVATARS" - }, - { - "name": "com.vrchat.avatars", - "expression": "3.5.1", - "define": "AAO_VRCSDK3_AVATARS_IMPOSTER_SETTINGS" - }, - { - "name": "com.vrchat.avatars", - "expression": "3.5.2-beta.1", - "define": "AAO_VRCSDK3_AVATARS_3_5_2" - }, - { - "name": "com.vrmc.univrm", - "expression": "", - "define": "AAO_VRM0" - }, - { - "name": "com.vrmc.vrm", - "expression": "", - "define": "AAO_VRM1" - } - ], + "versionDefines": [], "noEngineReferences": false } \ No newline at end of file diff --git a/Internal/TraceAndOptimizeBase/csc.rsp b/Internal/TraceAndOptimizeBase/csc.rsp new file mode 120000 index 000000000..c6acf2e0a --- /dev/null +++ b/Internal/TraceAndOptimizeBase/csc.rsp @@ -0,0 +1 @@ +../../Editor/csc.rsp \ No newline at end of file diff --git a/Internal/TraceAndOptimizeBase/csc.rsp.meta b/Internal/TraceAndOptimizeBase/csc.rsp.meta new file mode 100644 index 000000000..4072b7b8d --- /dev/null +++ b/Internal/TraceAndOptimizeBase/csc.rsp.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: a3acb1a8dec9f4ca3a329230acabaab4 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From d8c27539027c90dc716a39fc30f8eb20f3ce6484 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 21:13:13 +0900 Subject: [PATCH 08/11] docs(changelog): Most features of Animator Optimizer is not available in Unity 2019 --- CHANGELOG-PRERELEASE.md | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 36feb3b39..9889a05c6 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Added - Animator Optimizer `#854` + - Most features of Animator Optimizer is not available in Unity 2019. - Animator Optimizer optimizes your Animator Controller without behaviour Changes - Current Optimizer includes the following optimization - Remove meaningless properties `#854` diff --git a/CHANGELOG.md b/CHANGELOG.md index 446dfea12..0535a44a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog]. ### Added - Support for VRCSDK 3.5.2-beta.1 `#926` - Animator Optimizer `#854` + - Most features of Animator Optimizer is not available in Unity 2019. - Animator Optimizer optimizes your Animator Controller without behaviour Changes - Current Optimizer includes the following optimization - Remove meaningless properties `#854` From a81b09c71cdb708e3d1f0c56eb7140abc6465325 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 21:18:05 +0900 Subject: [PATCH 09/11] chore: make UtilsUsingUnsafe public (but it's still internal) --- Internal/UnsafeUtils/UtilsUsingUnsafe.cs | 2 +- Internal/UnsafeUtils/assembly-info.cs | 3 --- Internal/UnsafeUtils/assembly-info.cs.meta | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 Internal/UnsafeUtils/assembly-info.cs delete mode 100644 Internal/UnsafeUtils/assembly-info.cs.meta diff --git a/Internal/UnsafeUtils/UtilsUsingUnsafe.cs b/Internal/UnsafeUtils/UtilsUsingUnsafe.cs index adbbb9bbe..9722cb350 100644 --- a/Internal/UnsafeUtils/UtilsUsingUnsafe.cs +++ b/Internal/UnsafeUtils/UtilsUsingUnsafe.cs @@ -4,7 +4,7 @@ namespace Anatawa12.AvatarOptimizer { - internal static class UtilsUsingUnsafe + public static class UtilsUsingUnsafe { public static unsafe Span AsSpan(this NativeArray self) where T : unmanaged => new Span(self.GetUnsafePtr(), self.Length); diff --git a/Internal/UnsafeUtils/assembly-info.cs b/Internal/UnsafeUtils/assembly-info.cs deleted file mode 100644 index 9bbe4ea76..000000000 --- a/Internal/UnsafeUtils/assembly-info.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.editor")] diff --git a/Internal/UnsafeUtils/assembly-info.cs.meta b/Internal/UnsafeUtils/assembly-info.cs.meta deleted file mode 100644 index 9072c90a6..000000000 --- a/Internal/UnsafeUtils/assembly-info.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 44fbb356e477420d8fafcc324636a02e -timeCreated: 1673596545 \ No newline at end of file From f7d415c054ecc8ec3da73eedf36f9a378353f369 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 21:24:04 +0900 Subject: [PATCH 10/11] fix: InitializeAnimatorOptimizer is not disabled in 2021.2 or older --- Editor/Processors/InitializeAnimatorOptimizer.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Editor/Processors/InitializeAnimatorOptimizer.cs b/Editor/Processors/InitializeAnimatorOptimizer.cs index de879372b..8444e4065 100644 --- a/Editor/Processors/InitializeAnimatorOptimizer.cs +++ b/Editor/Processors/InitializeAnimatorOptimizer.cs @@ -1,3 +1,5 @@ +#if UNITY_2021_3_OR_NEWER + using System; using System.Collections.Generic; using Anatawa12.AvatarOptimizer.Processors.TraceAndOptimizes; @@ -176,3 +178,5 @@ protected override ComponentSupport GetComponentSupport(Object o) } } } + +#endif From 329d677beb8e3448f90e34d14fa5fb3fa4a9976a Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Mar 2024 22:31:24 +0900 Subject: [PATCH 11/11] fix: tests for animator optimizer is executed on 2019 --- Editor/asssembly-info.cs | 3 +- .../PrefabSafeSet/Runtime/assembly-info.cs | 2 +- Runtime/assembly-info.cs | 2 +- ...r-optimizer.test.animator-optimizer.asmdef | 24 ++++++++ ...imizer.test.animator-optimizer.asmdef.meta | 3 + ...atar-optimizer.test.animator-parser.asmdef | 55 +++++++++++++++++++ ...optimizer.test.animator-parser.asmdef.meta | 3 + Test~/Basic.meta | 3 + Test~/{ => Basic}/ApplyObjectMappingTest.cs | 0 .../ApplyObjectMappingTest.cs.meta | 0 Test~/{ => Basic}/BuildAssetBundle.cs | 2 +- Test~/{ => Basic}/BuildAssetBundle.cs.meta | 0 Test~/{ => Basic}/ComponentSettingsTest.cs | 0 .../{ => Basic}/ComponentSettingsTest.cs.meta | 0 Test~/{ => Basic}/ComponentWhitelistTest.cs | 0 .../ComponentWhitelistTest.cs.meta | 0 Test~/{ => Basic}/Empty.prefab | 0 Test~/{ => Basic}/Empty.prefab.meta | 0 Test~/{ => Basic}/EnumValues.cs | 0 Test~/{ => Basic}/EnumValues.cs.meta | 0 Test~/{ => Basic}/MergeBoneTest.cs | 0 Test~/{ => Basic}/MergeBoneTest.cs.meta | 0 Test~/{ => Basic}/MergePhysBoneTest.cs | 0 Test~/{ => Basic}/MergePhysBoneTest.cs.meta | 0 Test~/{ => Basic}/ObjectMappingTest.cs | 0 Test~/{ => Basic}/ObjectMappingTest.cs.meta | 0 Test~/{ => Basic}/PublicApiCheck.cs | 0 Test~/{ => Basic}/PublicApiCheck.cs.meta | 0 Test~/{ => Basic}/RunTest.cs | 0 Test~/{ => Basic}/RunTest.cs.meta | 0 Test~/{ => Basic}/UtilsTest.cs | 0 Test~/{ => Basic}/UtilsTest.cs.meta | 0 ...atawa12.avatar-optimizer.test.basic.asmdef | 55 +++++++++++++++++++ ...2.avatar-optimizer.test.basic.asmdef.meta} | 0 Test~/Basic/csc.rsp | 1 + Test~/{ => Basic}/csc.rsp.meta | 0 ...atawa12.avatar-optimizer.test.basic.asmdef | 55 +++++++++++++++++++ ...12.avatar-optimizer.test.basic.asmdef.meta | 3 + ...atar-optimizer.test.prefab-safe-set.asmdef | 55 +++++++++++++++++++ ...optimizer.test.prefab-safe-set.asmdef.meta | 3 + Test~/Utils.meta | 3 + Test~/{ => Utils}/TestUtils.cs | 4 +- Test~/{ => Utils}/TestUtils.cs.meta | 0 ...tawa12.avatar-optimizer.test.utils.asmdef} | 2 +- ...12.avatar-optimizer.test.utils.asmdef.meta | 3 + Test~/csc.rsp | 1 - 46 files changed, 274 insertions(+), 8 deletions(-) create mode 100644 Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef create mode 100644 Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef.meta create mode 100644 Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef create mode 100644 Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef.meta create mode 100644 Test~/Basic.meta rename Test~/{ => Basic}/ApplyObjectMappingTest.cs (100%) rename Test~/{ => Basic}/ApplyObjectMappingTest.cs.meta (100%) rename Test~/{ => Basic}/BuildAssetBundle.cs (96%) rename Test~/{ => Basic}/BuildAssetBundle.cs.meta (100%) rename Test~/{ => Basic}/ComponentSettingsTest.cs (100%) rename Test~/{ => Basic}/ComponentSettingsTest.cs.meta (100%) rename Test~/{ => Basic}/ComponentWhitelistTest.cs (100%) rename Test~/{ => Basic}/ComponentWhitelistTest.cs.meta (100%) rename Test~/{ => Basic}/Empty.prefab (100%) rename Test~/{ => Basic}/Empty.prefab.meta (100%) rename Test~/{ => Basic}/EnumValues.cs (100%) rename Test~/{ => Basic}/EnumValues.cs.meta (100%) rename Test~/{ => Basic}/MergeBoneTest.cs (100%) rename Test~/{ => Basic}/MergeBoneTest.cs.meta (100%) rename Test~/{ => Basic}/MergePhysBoneTest.cs (100%) rename Test~/{ => Basic}/MergePhysBoneTest.cs.meta (100%) rename Test~/{ => Basic}/ObjectMappingTest.cs (100%) rename Test~/{ => Basic}/ObjectMappingTest.cs.meta (100%) rename Test~/{ => Basic}/PublicApiCheck.cs (100%) rename Test~/{ => Basic}/PublicApiCheck.cs.meta (100%) rename Test~/{ => Basic}/RunTest.cs (100%) rename Test~/{ => Basic}/RunTest.cs.meta (100%) rename Test~/{ => Basic}/UtilsTest.cs (100%) rename Test~/{ => Basic}/UtilsTest.cs.meta (100%) create mode 100644 Test~/Basic/com.anatawa12.avatar-optimizer.test.basic.asmdef rename Test~/{com.anatawa12.avatar-optimizer.test.asmdef.meta => Basic/com.anatawa12.avatar-optimizer.test.basic.asmdef.meta} (100%) create mode 120000 Test~/Basic/csc.rsp rename Test~/{ => Basic}/csc.rsp.meta (100%) create mode 100644 Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef create mode 100644 Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef.meta create mode 100644 Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef create mode 100644 Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef.meta create mode 100644 Test~/Utils.meta rename Test~/{ => Utils}/TestUtils.cs (88%) rename Test~/{ => Utils}/TestUtils.cs.meta (100%) rename Test~/{com.anatawa12.avatar-optimizer.test.asmdef => Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef} (96%) create mode 100644 Test~/Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef.meta delete mode 120000 Test~/csc.rsp diff --git a/Editor/asssembly-info.cs b/Editor/asssembly-info.cs index e86dff41d..4b299d26d 100644 --- a/Editor/asssembly-info.cs +++ b/Editor/asssembly-info.cs @@ -1,3 +1,4 @@ using System.Runtime.CompilerServices; -[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test")] +[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test.basic")] +[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test.animator-parser")] diff --git a/Internal/PrefabSafeSet/Runtime/assembly-info.cs b/Internal/PrefabSafeSet/Runtime/assembly-info.cs index 51a07a35a..815e3159a 100644 --- a/Internal/PrefabSafeSet/Runtime/assembly-info.cs +++ b/Internal/PrefabSafeSet/Runtime/assembly-info.cs @@ -1,4 +1,4 @@ using System.Runtime.CompilerServices; [assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor")] -[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test")] +[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test.prefab-safe-set")] diff --git a/Runtime/assembly-info.cs b/Runtime/assembly-info.cs index b65f8ec0e..d9f366f32 100644 --- a/Runtime/assembly-info.cs +++ b/Runtime/assembly-info.cs @@ -2,4 +2,4 @@ [assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.editor")] [assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base")] -[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test")] +[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.test.basic")] diff --git a/Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef b/Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef new file mode 100644 index 000000000..94149e5b7 --- /dev/null +++ b/Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef @@ -0,0 +1,24 @@ +{ + "name": "com.anatawa12.avatar-optimizer.test.animator-optimizer", + "rootNamespace": "", + "references": [ + "com.anatawa12.avatar-optimizer.test.utils", + "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "UnityEngine.TestRunner", + "nadena.dev.ndmf" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [], + "autoReferenced": false, + "defineConstraints": [ + "UNITY_2021_3_OR_NEWER" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef.meta b/Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef.meta new file mode 100644 index 000000000..93c8a2127 --- /dev/null +++ b/Test~/AnimatorOptimizer/com.anatawa12.avatar-optimizer.test.animator-optimizer.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2e542296689a4658a3f697919bdf24a4 +timeCreated: 1711026736 \ No newline at end of file diff --git a/Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef b/Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef new file mode 100644 index 000000000..c7a940662 --- /dev/null +++ b/Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef @@ -0,0 +1,55 @@ +{ + "name": "com.anatawa12.avatar-optimizer.test.animator-parser", + "rootNamespace": "", + "references": [ + "VRC.SDK3A", + "VRC.SDKBase", + "com.anatawa12.avatar-optimizer.test.runtime", + "com.anatawa12.avatar-optimizer.test.utils", + "com.anatawa12.avatar-optimizer.editor", + "com.anatawa12.avatar-optimizer.runtime", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", + "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "com.anatawa12.avatar-optimizer.internal.meshinfo2", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "com.anatawa12.avatar-optimizer.internal.utils", + "com.anatawa12.avatar-optimizer.api.editor", + "UnityEngine.TestRunner", + "UnityEditor.TestRunner", + "nadena.dev.ndmf" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "VRC.SDK3.Dynamics.PhysBone.dll", + "VRC.Dynamics.dll", + "VRCSDK3A.dll", + "VRCSDKBase.dll", + "System.Memory.dll" + ], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "AAO_VRCSDK3_AVATARS" + }, + { + "name": "com.vrmc.univrm", + "expression": "", + "define": "AAO_VRM0" + }, + { + "name": "com.vrmc.vrm", + "expression": "", + "define": "AAO_VRM1" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef.meta b/Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef.meta new file mode 100644 index 000000000..693f3d83c --- /dev/null +++ b/Test~/AnimatorParser/com.anatawa12.avatar-optimizer.test.animator-parser.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1a9247bebd7641ea94867ce81608947a +timeCreated: 1711028591 \ No newline at end of file diff --git a/Test~/Basic.meta b/Test~/Basic.meta new file mode 100644 index 000000000..9baaa6d5c --- /dev/null +++ b/Test~/Basic.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d9311d8d6bba432eae20c48d776d5713 +timeCreated: 1711028265 \ No newline at end of file diff --git a/Test~/ApplyObjectMappingTest.cs b/Test~/Basic/ApplyObjectMappingTest.cs similarity index 100% rename from Test~/ApplyObjectMappingTest.cs rename to Test~/Basic/ApplyObjectMappingTest.cs diff --git a/Test~/ApplyObjectMappingTest.cs.meta b/Test~/Basic/ApplyObjectMappingTest.cs.meta similarity index 100% rename from Test~/ApplyObjectMappingTest.cs.meta rename to Test~/Basic/ApplyObjectMappingTest.cs.meta diff --git a/Test~/BuildAssetBundle.cs b/Test~/Basic/BuildAssetBundle.cs similarity index 96% rename from Test~/BuildAssetBundle.cs rename to Test~/Basic/BuildAssetBundle.cs index cfa0c7ffb..f5ecebf77 100644 --- a/Test~/BuildAssetBundle.cs +++ b/Test~/Basic/BuildAssetBundle.cs @@ -17,7 +17,7 @@ public void Build() { new AssetBundleBuild { - assetNames = new[] { TestUtils.GetAssetPath("Empty.prefab") }, + assetNames = new[] { TestUtils.GetAssetPath("Basic/Empty.prefab") }, assetBundleName = "asset.unity3d" } }, diff --git a/Test~/BuildAssetBundle.cs.meta b/Test~/Basic/BuildAssetBundle.cs.meta similarity index 100% rename from Test~/BuildAssetBundle.cs.meta rename to Test~/Basic/BuildAssetBundle.cs.meta diff --git a/Test~/ComponentSettingsTest.cs b/Test~/Basic/ComponentSettingsTest.cs similarity index 100% rename from Test~/ComponentSettingsTest.cs rename to Test~/Basic/ComponentSettingsTest.cs diff --git a/Test~/ComponentSettingsTest.cs.meta b/Test~/Basic/ComponentSettingsTest.cs.meta similarity index 100% rename from Test~/ComponentSettingsTest.cs.meta rename to Test~/Basic/ComponentSettingsTest.cs.meta diff --git a/Test~/ComponentWhitelistTest.cs b/Test~/Basic/ComponentWhitelistTest.cs similarity index 100% rename from Test~/ComponentWhitelistTest.cs rename to Test~/Basic/ComponentWhitelistTest.cs diff --git a/Test~/ComponentWhitelistTest.cs.meta b/Test~/Basic/ComponentWhitelistTest.cs.meta similarity index 100% rename from Test~/ComponentWhitelistTest.cs.meta rename to Test~/Basic/ComponentWhitelistTest.cs.meta diff --git a/Test~/Empty.prefab b/Test~/Basic/Empty.prefab similarity index 100% rename from Test~/Empty.prefab rename to Test~/Basic/Empty.prefab diff --git a/Test~/Empty.prefab.meta b/Test~/Basic/Empty.prefab.meta similarity index 100% rename from Test~/Empty.prefab.meta rename to Test~/Basic/Empty.prefab.meta diff --git a/Test~/EnumValues.cs b/Test~/Basic/EnumValues.cs similarity index 100% rename from Test~/EnumValues.cs rename to Test~/Basic/EnumValues.cs diff --git a/Test~/EnumValues.cs.meta b/Test~/Basic/EnumValues.cs.meta similarity index 100% rename from Test~/EnumValues.cs.meta rename to Test~/Basic/EnumValues.cs.meta diff --git a/Test~/MergeBoneTest.cs b/Test~/Basic/MergeBoneTest.cs similarity index 100% rename from Test~/MergeBoneTest.cs rename to Test~/Basic/MergeBoneTest.cs diff --git a/Test~/MergeBoneTest.cs.meta b/Test~/Basic/MergeBoneTest.cs.meta similarity index 100% rename from Test~/MergeBoneTest.cs.meta rename to Test~/Basic/MergeBoneTest.cs.meta diff --git a/Test~/MergePhysBoneTest.cs b/Test~/Basic/MergePhysBoneTest.cs similarity index 100% rename from Test~/MergePhysBoneTest.cs rename to Test~/Basic/MergePhysBoneTest.cs diff --git a/Test~/MergePhysBoneTest.cs.meta b/Test~/Basic/MergePhysBoneTest.cs.meta similarity index 100% rename from Test~/MergePhysBoneTest.cs.meta rename to Test~/Basic/MergePhysBoneTest.cs.meta diff --git a/Test~/ObjectMappingTest.cs b/Test~/Basic/ObjectMappingTest.cs similarity index 100% rename from Test~/ObjectMappingTest.cs rename to Test~/Basic/ObjectMappingTest.cs diff --git a/Test~/ObjectMappingTest.cs.meta b/Test~/Basic/ObjectMappingTest.cs.meta similarity index 100% rename from Test~/ObjectMappingTest.cs.meta rename to Test~/Basic/ObjectMappingTest.cs.meta diff --git a/Test~/PublicApiCheck.cs b/Test~/Basic/PublicApiCheck.cs similarity index 100% rename from Test~/PublicApiCheck.cs rename to Test~/Basic/PublicApiCheck.cs diff --git a/Test~/PublicApiCheck.cs.meta b/Test~/Basic/PublicApiCheck.cs.meta similarity index 100% rename from Test~/PublicApiCheck.cs.meta rename to Test~/Basic/PublicApiCheck.cs.meta diff --git a/Test~/RunTest.cs b/Test~/Basic/RunTest.cs similarity index 100% rename from Test~/RunTest.cs rename to Test~/Basic/RunTest.cs diff --git a/Test~/RunTest.cs.meta b/Test~/Basic/RunTest.cs.meta similarity index 100% rename from Test~/RunTest.cs.meta rename to Test~/Basic/RunTest.cs.meta diff --git a/Test~/UtilsTest.cs b/Test~/Basic/UtilsTest.cs similarity index 100% rename from Test~/UtilsTest.cs rename to Test~/Basic/UtilsTest.cs diff --git a/Test~/UtilsTest.cs.meta b/Test~/Basic/UtilsTest.cs.meta similarity index 100% rename from Test~/UtilsTest.cs.meta rename to Test~/Basic/UtilsTest.cs.meta diff --git a/Test~/Basic/com.anatawa12.avatar-optimizer.test.basic.asmdef b/Test~/Basic/com.anatawa12.avatar-optimizer.test.basic.asmdef new file mode 100644 index 000000000..5a2ba225c --- /dev/null +++ b/Test~/Basic/com.anatawa12.avatar-optimizer.test.basic.asmdef @@ -0,0 +1,55 @@ +{ + "name": "com.anatawa12.avatar-optimizer.test.basic", + "rootNamespace": "", + "references": [ + "VRC.SDK3A", + "VRC.SDKBase", + "com.anatawa12.avatar-optimizer.test.runtime", + "com.anatawa12.avatar-optimizer.test.utils", + "com.anatawa12.avatar-optimizer.editor", + "com.anatawa12.avatar-optimizer.runtime", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", + "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "com.anatawa12.avatar-optimizer.internal.meshinfo2", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "com.anatawa12.avatar-optimizer.internal.utils", + "com.anatawa12.avatar-optimizer.api.editor", + "UnityEngine.TestRunner", + "UnityEditor.TestRunner", + "nadena.dev.ndmf" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "VRC.SDK3.Dynamics.PhysBone.dll", + "VRC.Dynamics.dll", + "VRCSDK3A.dll", + "VRCSDKBase.dll", + "System.Memory.dll" + ], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "AAO_VRCSDK3_AVATARS" + }, + { + "name": "com.vrmc.univrm", + "expression": "", + "define": "AAO_VRM0" + }, + { + "name": "com.vrmc.vrm", + "expression": "", + "define": "AAO_VRM1" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Test~/com.anatawa12.avatar-optimizer.test.asmdef.meta b/Test~/Basic/com.anatawa12.avatar-optimizer.test.basic.asmdef.meta similarity index 100% rename from Test~/com.anatawa12.avatar-optimizer.test.asmdef.meta rename to Test~/Basic/com.anatawa12.avatar-optimizer.test.basic.asmdef.meta diff --git a/Test~/Basic/csc.rsp b/Test~/Basic/csc.rsp new file mode 120000 index 000000000..c6acf2e0a --- /dev/null +++ b/Test~/Basic/csc.rsp @@ -0,0 +1 @@ +../../Editor/csc.rsp \ No newline at end of file diff --git a/Test~/csc.rsp.meta b/Test~/Basic/csc.rsp.meta similarity index 100% rename from Test~/csc.rsp.meta rename to Test~/Basic/csc.rsp.meta diff --git a/Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef b/Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef new file mode 100644 index 000000000..3712fbd7b --- /dev/null +++ b/Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef @@ -0,0 +1,55 @@ +{ + "name": "com.anatawa12.avatar-optimizer.test.meshinfo2", + "rootNamespace": "", + "references": [ + "VRC.SDK3A", + "VRC.SDKBase", + "com.anatawa12.avatar-optimizer.test.runtime", + "com.anatawa12.avatar-optimizer.test.utils", + "com.anatawa12.avatar-optimizer.editor", + "com.anatawa12.avatar-optimizer.runtime", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", + "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "com.anatawa12.avatar-optimizer.internal.meshinfo2", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "com.anatawa12.avatar-optimizer.internal.utils", + "com.anatawa12.avatar-optimizer.api.editor", + "UnityEngine.TestRunner", + "UnityEditor.TestRunner", + "nadena.dev.ndmf" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "VRC.SDK3.Dynamics.PhysBone.dll", + "VRC.Dynamics.dll", + "VRCSDK3A.dll", + "VRCSDKBase.dll", + "System.Memory.dll" + ], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "AAO_VRCSDK3_AVATARS" + }, + { + "name": "com.vrmc.univrm", + "expression": "", + "define": "AAO_VRM0" + }, + { + "name": "com.vrmc.vrm", + "expression": "", + "define": "AAO_VRM1" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef.meta b/Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef.meta new file mode 100644 index 000000000..b3cc168d9 --- /dev/null +++ b/Test~/MeshInfo2/com.anatawa12.avatar-optimizer.test.basic.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6874cc1d9d544091bcd2de57de5161b0 +timeCreated: 1711028426 \ No newline at end of file diff --git a/Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef b/Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef new file mode 100644 index 000000000..d368a8ca0 --- /dev/null +++ b/Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef @@ -0,0 +1,55 @@ +{ + "name": "com.anatawa12.avatar-optimizer.test.prefab-safe-set", + "rootNamespace": "", + "references": [ + "VRC.SDK3A", + "VRC.SDKBase", + "com.anatawa12.avatar-optimizer.test.runtime", + "com.anatawa12.avatar-optimizer.test.utils", + "com.anatawa12.avatar-optimizer.editor", + "com.anatawa12.avatar-optimizer.runtime", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set", + "com.anatawa12.avatar-optimizer.internal.prefab-safe-set.editor", + "com.anatawa12.avatar-optimizer.internal.animator-optimizer", + "com.anatawa12.avatar-optimizer.internal.meshinfo2", + "com.anatawa12.avatar-optimizer.internal.trace-and-optimize-base", + "com.anatawa12.avatar-optimizer.internal.utils", + "com.anatawa12.avatar-optimizer.api.editor", + "UnityEngine.TestRunner", + "UnityEditor.TestRunner", + "nadena.dev.ndmf" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "VRC.SDK3.Dynamics.PhysBone.dll", + "VRC.Dynamics.dll", + "VRCSDK3A.dll", + "VRCSDKBase.dll", + "System.Memory.dll" + ], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [ + { + "name": "com.vrchat.avatars", + "expression": "", + "define": "AAO_VRCSDK3_AVATARS" + }, + { + "name": "com.vrmc.univrm", + "expression": "", + "define": "AAO_VRM0" + }, + { + "name": "com.vrmc.vrm", + "expression": "", + "define": "AAO_VRM1" + } + ], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef.meta b/Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef.meta new file mode 100644 index 000000000..3f6222c38 --- /dev/null +++ b/Test~/PrefabSafeSet/com.anatawa12.avatar-optimizer.test.prefab-safe-set.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1a8cd9dd02634453bbcad31368e19153 +timeCreated: 1711028447 \ No newline at end of file diff --git a/Test~/Utils.meta b/Test~/Utils.meta new file mode 100644 index 000000000..7ace1ccd8 --- /dev/null +++ b/Test~/Utils.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 801b64144a3842adb8909fd2d209241a +timeCreated: 1711026995 \ No newline at end of file diff --git a/Test~/TestUtils.cs b/Test~/Utils/TestUtils.cs similarity index 88% rename from Test~/TestUtils.cs rename to Test~/Utils/TestUtils.cs index f14f1ab0d..bbc63e33c 100644 --- a/Test~/TestUtils.cs +++ b/Test~/Utils/TestUtils.cs @@ -4,7 +4,7 @@ namespace Anatawa12.AvatarOptimizer.Test { - internal static class TestUtils + public static class TestUtils { public static GameObject NewAvatar(string name = null) { @@ -20,7 +20,7 @@ public static GameObject NewAvatar(string name = null) public static string GetAssetPath(string testRelativePath) { - var path = AssetDatabase.GUIDToAssetPath("fc50cab76afb46348d98df4ce8d84e8b"); + var path = AssetDatabase.GUIDToAssetPath("801b64144a3842adb8909fd2d209241a"); var baseDir = path.Substring(0, path.LastIndexOf('/')); return $"{baseDir}/{testRelativePath}"; } diff --git a/Test~/TestUtils.cs.meta b/Test~/Utils/TestUtils.cs.meta similarity index 100% rename from Test~/TestUtils.cs.meta rename to Test~/Utils/TestUtils.cs.meta diff --git a/Test~/com.anatawa12.avatar-optimizer.test.asmdef b/Test~/Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef similarity index 96% rename from Test~/com.anatawa12.avatar-optimizer.test.asmdef rename to Test~/Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef index 56d2d25ed..f806d8b99 100644 --- a/Test~/com.anatawa12.avatar-optimizer.test.asmdef +++ b/Test~/Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef @@ -1,5 +1,5 @@ { - "name": "com.anatawa12.avatar-optimizer.test", + "name": "com.anatawa12.avatar-optimizer.test.utils", "rootNamespace": "", "references": [ "VRC.SDK3A", diff --git a/Test~/Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef.meta b/Test~/Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef.meta new file mode 100644 index 000000000..7cedf7b3f --- /dev/null +++ b/Test~/Utils/com.anatawa12.avatar-optimizer.test.utils.asmdef.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 20ae37d9c04e471d9a38d23f86deda1d +timeCreated: 1711027073 \ No newline at end of file diff --git a/Test~/csc.rsp b/Test~/csc.rsp deleted file mode 120000 index a31032be9..000000000 --- a/Test~/csc.rsp +++ /dev/null @@ -1 +0,0 @@ -../Editor/csc.rsp \ No newline at end of file