From ad0881a6214084383b89f51fcdd31abe11a8c80b Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sat, 16 Nov 2024 10:15:30 +0900 Subject: [PATCH 1/6] fix: surround lilToon dependant code by preprocessor token --- Editor/Transform/Environment/LilToon/LilToonHandler.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Editor/Transform/Environment/LilToon/LilToonHandler.cs b/Editor/Transform/Environment/LilToon/LilToonHandler.cs index c5f37fc..8f7ee2a 100644 --- a/Editor/Transform/Environment/LilToon/LilToonHandler.cs +++ b/Editor/Transform/Environment/LilToon/LilToonHandler.cs @@ -148,7 +148,7 @@ private static var h = new HarmonyLib.Harmony( "io.github.kisaragieffective.resonite-import-helper.liltoon.headless-bake"); Profiler.EndSample(); - +#if RIH_HAS_LILTOON Profiler.BeginSample("Mute warnings"); Profiler.BeginSample("Get Method"); var warningDialogMethod = typeof(EditorUtility) @@ -182,9 +182,11 @@ private static ); Profiler.EndSample(); Profiler.EndSample(); - +#else + Debug.LogWarning("This project does not have lilToon as an Unity-managed package."); +#endif // RIH_HAS_LILTOON return h; -#endif +#endif // RIH_HAS_HARMONY } private static bool SkipDisplayDialogFromLilInspector() From f1f9f9de558a31df748a14900ca2fa3278ff86b6 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sun, 17 Nov 2024 07:06:35 +0900 Subject: [PATCH 2/6] refactor: refer PackageManagerProxy.SupportedUniGLTF version to consider appropriate URL --- Editor/Bootstrap/Logic/PackageManagerProxy.cs | 2 +- Editor/UI/Component/UniGltfInstallPrompt.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/Bootstrap/Logic/PackageManagerProxy.cs b/Editor/Bootstrap/Logic/PackageManagerProxy.cs index b5e9bd8..d12622e 100644 --- a/Editor/Bootstrap/Logic/PackageManagerProxy.cs +++ b/Editor/Bootstrap/Logic/PackageManagerProxy.cs @@ -18,7 +18,7 @@ namespace ResoniteImportHelper.Bootstrap.Logic public static class PackageManagerProxy { // ReSharper disable once InconsistentNaming - private const string SupportedUniGLTFVersion = "0.128.0"; + public const string SupportedUniGLTFVersion = "0.128.0"; private const string UnmanagedArchiveInstallSource = "https://github.com/vrm-c/UniVRM/releases/download/v0.128.0/VRM-0.128.0_264a.unitypackage"; diff --git a/Editor/UI/Component/UniGltfInstallPrompt.cs b/Editor/UI/Component/UniGltfInstallPrompt.cs index d7563bb..552f9b1 100644 --- a/Editor/UI/Component/UniGltfInstallPrompt.cs +++ b/Editor/UI/Component/UniGltfInstallPrompt.cs @@ -29,7 +29,7 @@ internal UniGltfInstallPrompt([UsedImplicitly] ILocalizedTexts lang) { var button = new Button(() => { - Application.OpenURL("https://github.com/vrm-c/UniVRM/releases/tag/v0.128.0"); + Application.OpenURL($"https://github.com/vrm-c/UniVRM/releases/tag/v{PackageManagerProxy.SupportedUniGLTFVersion}"); }); button.Add(new Label(lang.OpenInstallationPageForUniGLTF())); rootVisualElement.Add(button); From 313f8a869bfd0d08bdca30509e3242c26c1f3221 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sun, 17 Nov 2024 07:06:51 +0900 Subject: [PATCH 3/6] docs: gather duplicated link --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 07d9896..0111ad1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Bake and Import. ## Requirement and recommended tools -* UniGLTF 0.128.0 is required to run. Download it from their [GitHub repository](https://github.com/vrm-c/UniVRM/releases/tag/v0.128.0). +* UniGLTF 0.128.0 is required to run. Download it from their [GitHub repository][unigltf-release]. * Git or VPM-compatible client is required to install. * Git: Download it from [git-scm.com](https://git-scm.com/downloads) * VPM-compatible client: You may use [ALCOM](https://vcc.docs.vrchat.com/guides/getting-started) or [VRChat Creator Companion](https://vcc.docs.vrchat.com/guides/getting-started). @@ -14,6 +14,7 @@ Following tools are optional. This tool can invoke their hooks. * AAO: Avatar Optimizer ([Download](https://vpm.anatawa12.com/avatar-optimizer/en/)) * Modular Avatar ([Download](https://modular-avatar.nadena.dev/)) +[unigltf-release]: https://github.com/vrm-c/UniVRM/releases/tag/v0.128.0 ## What this does and does not ### Does * Flag non-Rig bone as [``][NOIK] @@ -37,7 +38,7 @@ RIH can download and configure it automatically, so you may skip this step: ![Bootstrapper UI](./Doc~/AutomatedInstallationUI.png) -This method is equivalent to install from their [GitHub release](https://github.com/vrm-c/UniVRM/releases/tag/v0.128.0) page. +This method is equivalent to install from their [GitHub release][unigltf-release] page. #### RIH itself Install can be done either: From fd9571bf030b9df0f4c0e24b40383fd7b78b135a Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sun, 17 Nov 2024 07:13:20 +0900 Subject: [PATCH 4/6] refactor: avoid warnings --- Editor/Bootstrap/Logic/PackageManagerProxy.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Editor/Bootstrap/Logic/PackageManagerProxy.cs b/Editor/Bootstrap/Logic/PackageManagerProxy.cs index d12622e..2acc587 100644 --- a/Editor/Bootstrap/Logic/PackageManagerProxy.cs +++ b/Editor/Bootstrap/Logic/PackageManagerProxy.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -23,7 +24,7 @@ public static class PackageManagerProxy private const string UnmanagedArchiveInstallSource = "https://github.com/vrm-c/UniVRM/releases/download/v0.128.0/VRM-0.128.0_264a.unitypackage"; - private static HttpClient _httpClient; + private static HttpClient? _httpClient; // ReSharper disable once InconsistentNaming public static void InstallUniGLTF() { @@ -37,8 +38,13 @@ public static void InstallUniGLTF() var json = File.ReadAllText(lowLevelPath); var depUrl = $"https://github.com/vrm-c/UniVRM.git?path=/Assets/UniGLTF#v{SupportedUniGLTFVersion}"; // this implements dynamic field selector. - dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json); - jsonObj!["dependencies"]["com.vrmc.gltf"] = depUrl; + dynamic? jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json); + if (jsonObj is null) + { + throw new Exception("Unity's package manifest is corrupted"); + } + + jsonObj["dependencies"]["com.vrmc.gltf"] = depUrl; string outcome = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(lowLevelPath, outcome); @@ -49,7 +55,7 @@ public static void InstallUniGLTF() { Debug.Log("Bootstrap: using UnityPackage."); - _httpClient ??= new System.Net.Http.HttpClient(); + _httpClient ??= new HttpClient(); string path; { var t = Task.Run(DownloadUnmanagedArchive); @@ -97,7 +103,7 @@ public static void InstallUniGLTF() private static async Task DownloadUnmanagedArchive() { - var r = await _httpClient.GetAsync(UnmanagedArchiveInstallSource); + var r = await _httpClient!.GetAsync(UnmanagedArchiveInstallSource); var content = r.Content; var temp = Path.GetTempFileName(); From baeff9a03c462af4ca20fa33ccc7976581643882 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sun, 17 Nov 2024 10:19:56 +0900 Subject: [PATCH 5/6] feat: apply root scale to armature --- Editor/TransFront/Entry.cs | 12 ++++--- Editor/Transform/AvatarTransformService.cs | 32 +++++++++++++++++-- Editor/UI/Component/Body.cs | 1 + .../Component/ExperimentalSettingsFoldout.cs | 15 +++++++-- Editor/UI/Localize/English.cs | 9 ++++-- Editor/UI/Localize/ILocalizedTexts.cs | 10 +++--- Editor/UI/Localize/Japanese.cs | 7 +++- 7 files changed, 69 insertions(+), 17 deletions(-) diff --git a/Editor/TransFront/Entry.cs b/Editor/TransFront/Entry.cs index a91c701..bb3bf7c 100644 --- a/Editor/TransFront/Entry.cs +++ b/Editor/TransFront/Entry.cs @@ -19,6 +19,7 @@ internal static ExportInformation PerformConversion( // ReSharper disable once InconsistentNaming bool runNDMF, bool bakeTexture, + bool applyRootScale, bool generateIntermediateArtifact ) { @@ -31,10 +32,11 @@ bool generateIntermediateArtifact runVRCSDKPipeline, runNDMF, bakeTexture, + applyRootScale, rootAlloc ); Profiler.EndSample(); - + Debug.Log("Exporting model as glTF"); var serialized = SerializationService.ExportToAssetFolder( new SerializationConfiguration( @@ -45,16 +47,16 @@ bool generateIntermediateArtifact rootAlloc ) ); - + Debug.Log("done"); // we can remove target because it is cloned in either way. Object.DestroyImmediate(result.Processed, false); Profiler.EndSample(); return serialized; } - + private const string DestinationFolder = "ZZZ_TemporalAsset"; - + private static string InitializeTemporalAssetDataDirectory(string secondaryDirectoryName) { #region sanity check @@ -92,4 +94,4 @@ private static string InitializeTemporalAssetDataDirectory(string secondaryDirec } } } -} \ No newline at end of file +} diff --git a/Editor/Transform/AvatarTransformService.cs b/Editor/Transform/AvatarTransformService.cs index 8ddfb6d..29316d6 100644 --- a/Editor/Transform/AvatarTransformService.cs +++ b/Editor/Transform/AvatarTransformService.cs @@ -25,6 +25,7 @@ internal static Result PerformConversionPure( // ReSharper disable once InconsistentNaming bool runNDMF, bool bakeTexture, + bool applyRootScale, ResourceAllocator alloc ) { @@ -34,7 +35,7 @@ ResourceAllocator alloc var intermediateMarker = IntermediateClonedHierarchyMarker.Construct(target, unmodifiableRoot); - var c = InPlaceConvert(target, bakeTexture, alloc); + var c = InPlaceConvert(target, bakeTexture, applyRootScale, alloc); Object.DestroyImmediate(intermediateMarker); @@ -71,7 +72,7 @@ GameObject PerformEnvironmentDependantShallowCopy(IPlatformExpander handler, Gam } private static MultipleUnorderedDictionary - InPlaceConvert(GameObject target, bool bakeTexture, ResourceAllocator alloc) + InPlaceConvert(GameObject target, bool bakeTexture, bool applyRootScale, ResourceAllocator alloc) { var rig = FindRigSetting(target); if (rig == null) @@ -82,6 +83,17 @@ private static MultipleUnorderedDictionary Debug.Log("Automated NoIK processor"); ModifyArmature(target, rig); + + if (applyRootScale) + { + Debug.Log("ApplyRootScale: invoked"); + ApplyRootScaleToArmatureRoot(target.transform, rig.GetBoneTransform(HumanBodyBones.Hips).parent); + } + else + { + Debug.Log("ApplyRootScale: skipped"); + } + Debug.Log("maybe bake texture"); if (bakeTexture) { @@ -100,6 +112,22 @@ private static MultipleUnorderedDictionary private static Animator? FindRigSetting(GameObject root) => root.TryGetComponent(out var a) ? a : null; + /// + /// multiply armature scale by root scale, then reset root scale to the identity scale. + /// + /// + /// + private static void ApplyRootScaleToArmatureRoot(UnityEngine.Transform root, UnityEngine.Transform armatureRoot) + { + var armatureScale = armatureRoot.transform.localScale; + var rootScale = root.transform.localScale; + armatureScale.x *= rootScale.x; + armatureScale.y *= rootScale.y; + armatureScale.z *= rootScale.z; + + root.transform.localScale = Vector3.one; + } + /// /// See also: Wiki /// diff --git a/Editor/UI/Component/Body.cs b/Editor/UI/Component/Body.cs index 2290009..077fe80 100644 --- a/Editor/UI/Component/Body.cs +++ b/Editor/UI/Component/Body.cs @@ -77,6 +77,7 @@ private static void RenderTo(VisualElement rootVisualElement, ILocalizedTexts la doRunVRCSDK3APreprocessors.value, doNDMFManualBake.value, experimentalSettingsFoldout.BakeShadersConfigurationIntoTextures.value, + experimentalSettingsFoldout.ApplyRootScale.value, experimentalSettingsFoldout.GenerateIntermediateArtifact.value ); destination.value = result.SerializedObject; diff --git a/Editor/UI/Component/ExperimentalSettingsFoldout.cs b/Editor/UI/Component/ExperimentalSettingsFoldout.cs index 7b54dec..4c24023 100644 --- a/Editor/UI/Component/ExperimentalSettingsFoldout.cs +++ b/Editor/UI/Component/ExperimentalSettingsFoldout.cs @@ -10,6 +10,8 @@ internal sealed class ExperimentalSettingsFoldout: Foldout internal readonly Toggle GenerateIntermediateArtifact; + internal readonly Toggle ApplyRootScale; + internal ExperimentalSettingsFoldout(ILocalizedTexts lang) { this.value = false; @@ -17,7 +19,7 @@ internal ExperimentalSettingsFoldout(ILocalizedTexts lang) this.Add( new HelpBox(lang.ExperimentalSettingsAreNeverSupported(), HelpBoxMessageType.Warning) ); - + BakeShadersConfigurationIntoTextures = new Toggle(lang.ExperimentalSetting_BakeLilToonLabel()) { tooltip = lang.ExperimentalSetting_BakeLilToonTooltip() @@ -28,9 +30,16 @@ internal ExperimentalSettingsFoldout(ILocalizedTexts lang) { tooltip = lang.ExperimentalSetting_GenerateIntermediateArtifactTooltip() }; - + this.Add(GenerateIntermediateArtifact); + + ApplyRootScale = new Toggle(lang.ExperimentalSetting_ApplyRootScale()) + { + tooltip = lang.ExperimentalSetting_ApplyRootScaleTip() + }; + + this.Add(ApplyRootScale); } } -} \ No newline at end of file +} diff --git a/Editor/UI/Localize/English.cs b/Editor/UI/Localize/English.cs index c4dc2c5..5cce401 100644 --- a/Editor/UI/Localize/English.cs +++ b/Editor/UI/Localize/English.cs @@ -36,7 +36,7 @@ public string ConflictingVersionOfUniGLTFIsInstalled() => public string InvokeVRCSDKPreprocessorLabel() => "Invoke VRChat SDK Preprocessor"; public string InvokeVRCSDKPreprocessorTooltip() => "Do you want NDMF or VRCFury to run?"; - + public string NDMFManualBakeLabel() => "NDMF Manual Bake"; public string NDMFManualBakeTooltip() => "Do you want NDMF to run?"; @@ -54,5 +54,10 @@ public string ExperimentalSetting_BakeLilToonTooltip() => public string ExperimentalSetting_GenerateIntermediateArtifactTooltip() => "Do you want to intermediate artifacts to debug?\nIt will be persisted under the same directory."; + + public string ExperimentalSetting_ApplyRootScale() => "Apply root scale to Armature"; + + public string ExperimentalSetting_ApplyRootScaleTip() => + "Do you want to multiply Armature scale by root scale?"; } -} \ No newline at end of file +} diff --git a/Editor/UI/Localize/ILocalizedTexts.cs b/Editor/UI/Localize/ILocalizedTexts.cs index 1597f4c..bd9142a 100644 --- a/Editor/UI/Localize/ILocalizedTexts.cs +++ b/Editor/UI/Localize/ILocalizedTexts.cs @@ -9,14 +9,14 @@ internal interface ILocalizedTexts string Root(); string RootTooltip(); string ExportSetting(); - + string ModelContainsVertexColor(); string Start(); string UniGLTFIsNotInstalled(); string OpenInstallationPageForUniGLTF(); string InstallUniGLTFAutomatically(); string ConflictingVersionOfUniGLTFIsInstalled(); - + string OpenInFileSystemLabel(); string ProcessedAvatarLabel(); string ProcessedAvatarTooltip(); @@ -24,12 +24,14 @@ internal interface ILocalizedTexts string InvokeVRCSDKPreprocessorTooltip(); string NDMFManualBakeLabel(); string NDMFManualBakeTooltip(); - + string ExperimentalSettingRootLabel(); string ExperimentalSettingsAreNeverSupported(); string ExperimentalSetting_BakeLilToonLabel(); string ExperimentalSetting_BakeLilToonTooltip(); string ExperimentalSetting_GenerateIntermediateArtifactLabel(); string ExperimentalSetting_GenerateIntermediateArtifactTooltip(); + string ExperimentalSetting_ApplyRootScale(); + string ExperimentalSetting_ApplyRootScaleTip(); } -} \ No newline at end of file +} diff --git a/Editor/UI/Localize/Japanese.cs b/Editor/UI/Localize/Japanese.cs index a8ce296..fffd654 100644 --- a/Editor/UI/Localize/Japanese.cs +++ b/Editor/UI/Localize/Japanese.cs @@ -50,5 +50,10 @@ public string ExperimentalSetting_BakeLilToonTooltip() => public string ExperimentalSetting_GenerateIntermediateArtifactTooltip() => "チェックを入れると、デバッグのために中間アーティファクトを生成します。中間アーティファクトはglTFと同じディレクトリに生成されます。"; + + public string ExperimentalSetting_ApplyRootScale() => "ルートのスケールをアーマチュアに適用する"; + + public string ExperimentalSetting_ApplyRootScaleTip() => + "チェックを入れると、ルートに設定されているスケールをアーマチュアのスケールに乗算し、ルートのスケールを(1, 1, 1)にします。"; } -} \ No newline at end of file +} From db725596e81fd5d45c35262e4c30bacb6ba2ef67 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sun, 17 Nov 2024 10:36:28 +0900 Subject: [PATCH 6/6] fix: assign copied Vector3 --- Editor/Transform/AvatarTransformService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Editor/Transform/AvatarTransformService.cs b/Editor/Transform/AvatarTransformService.cs index 29316d6..1b68ceb 100644 --- a/Editor/Transform/AvatarTransformService.cs +++ b/Editor/Transform/AvatarTransformService.cs @@ -124,6 +124,8 @@ private static void ApplyRootScaleToArmatureRoot(UnityEngine.Transform root, Uni armatureScale.x *= rootScale.x; armatureScale.y *= rootScale.y; armatureScale.z *= rootScale.z; + // コピーなので再代入が必要 + armatureRoot.transform.localScale = armatureScale; root.transform.localScale = Vector3.one; }