Skip to content

Commit

Permalink
Merge branch 'master' into pre-0.1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
KisaragiEffective committed Nov 20, 2024
2 parents 2cf9376 + e206bc8 commit 391be5e
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 29 deletions.
18 changes: 12 additions & 6 deletions Editor/Bootstrap/Logic/PackageManagerProxy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
Expand All @@ -18,12 +19,12 @@ 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";

private static HttpClient _httpClient;
private static HttpClient? _httpClient;
// ReSharper disable once InconsistentNaming
public static void InstallUniGLTF()
{
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -97,7 +103,7 @@ public static void InstallUniGLTF()

private static async Task<string> DownloadUnmanagedArchive()
{
var r = await _httpClient.GetAsync(UnmanagedArchiveInstallSource);
var r = await _httpClient!.GetAsync(UnmanagedArchiveInstallSource);
var content = r.Content;

var temp = Path.GetTempFileName();
Expand Down
12 changes: 7 additions & 5 deletions Editor/TransFront/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal static ExportInformation PerformConversion(
// ReSharper disable once InconsistentNaming
bool runNDMF,
bool bakeTexture,
bool applyRootScale,
bool generateIntermediateArtifact
)
{
Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -92,4 +94,4 @@ private static string InitializeTemporalAssetDataDirectory(string secondaryDirec
}
}
}
}
}
34 changes: 32 additions & 2 deletions Editor/Transform/AvatarTransformService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal static Result PerformConversionPure(
// ReSharper disable once InconsistentNaming
bool runNDMF,
bool bakeTexture,
bool applyRootScale,
ResourceAllocator alloc
)
{
Expand All @@ -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);

Expand Down Expand Up @@ -71,7 +72,7 @@ GameObject PerformEnvironmentDependantShallowCopy(IPlatformExpander handler, Gam
}

private static MultipleUnorderedDictionary<LoweredRenderMode, Material>
InPlaceConvert(GameObject target, bool bakeTexture, ResourceAllocator alloc)
InPlaceConvert(GameObject target, bool bakeTexture, bool applyRootScale, ResourceAllocator alloc)
{
var rig = FindRigSetting(target);
if (rig == null)
Expand All @@ -82,6 +83,17 @@ private static MultipleUnorderedDictionary<LoweredRenderMode, Material>

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)
{
Expand All @@ -100,6 +112,24 @@ private static MultipleUnorderedDictionary<LoweredRenderMode, Material>
private static Animator? FindRigSetting(GameObject root) =>
root.TryGetComponent<Animator>(out var a) ? a : null;

/// <summary>
/// multiply armature scale by root scale, then reset root scale to the identity scale.
/// </summary>
/// <param name="root"></param>
/// <param name="armatureRoot"></param>
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;
// コピーなので再代入が必要
armatureRoot.transform.localScale = armatureScale;

root.transform.localScale = Vector3.one;
}

/// <summary>
/// See also: <a href="https://wiki.resonite.com/Humanoid_Rig_Requirements_for_IK">Wiki</a>
/// </summary>
Expand Down
8 changes: 5 additions & 3 deletions Editor/Transform/Environment/LilToon/LilToonHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions Editor/UI/Component/Body.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions Editor/UI/Component/ExperimentalSettingsFoldout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ internal sealed class ExperimentalSettingsFoldout: Foldout

internal readonly Toggle GenerateIntermediateArtifact;

internal readonly Toggle ApplyRootScale;

internal ExperimentalSettingsFoldout(ILocalizedTexts lang)
{
this.value = false;
this.text = lang.ExperimentalSettingRootLabel();
this.Add(
new HelpBox(lang.ExperimentalSettingsAreNeverSupported(), HelpBoxMessageType.Warning)
);

BakeShadersConfigurationIntoTextures = new Toggle(lang.ExperimentalSetting_BakeLilToonLabel())
{
tooltip = lang.ExperimentalSetting_BakeLilToonTooltip()
Expand All @@ -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);
}

}
}
}
2 changes: 1 addition & 1 deletion Editor/UI/Component/UniGltfInstallPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions Editor/UI/Localize/English.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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?";
Expand All @@ -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?";
}
}
}
10 changes: 6 additions & 4 deletions Editor/UI/Localize/ILocalizedTexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ 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();
string InvokeVRCSDKPreprocessorLabel();
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();
}
}
}
7 changes: 6 additions & 1 deletion Editor/UI/Localize/Japanese.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ public string ExperimentalSetting_BakeLilToonTooltip() =>

public string ExperimentalSetting_GenerateIntermediateArtifactTooltip() =>
"チェックを入れると、デバッグのために中間アーティファクトを生成します。中間アーティファクトはglTFと同じディレクトリに生成されます。";

public string ExperimentalSetting_ApplyRootScale() => "ルートのスケールをアーマチュアに適用する";

public string ExperimentalSetting_ApplyRootScaleTip() =>
"チェックを入れると、ルートに設定されているスケールをアーマチュアのスケールに乗算し、ルートのスケールを(1, 1, 1)にします。";
}
}
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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>`][NOIK]
Expand All @@ -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:
Expand Down

0 comments on commit 391be5e

Please sign in to comment.