Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vrm10][Importer引数] ScriptedImpoter からの Import で SpringBone の初期化を回避する #2473

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace UniGLTF
/// </summary>
public class ImporterContext : IResponsibilityForDestroyObjects
{
public readonly bool IsAssetImport;
private readonly ImporterContextSettings _settings;

public ITextureDescriptorGenerator TextureDescriptorGenerator { get; protected set; }
Expand All @@ -37,8 +38,10 @@ public ImporterContext(
IReadOnlyDictionary<SubAssetKey, UnityEngine.Object> externalObjectMap = null,
ITextureDeserializer textureDeserializer = null,
IMaterialDescriptorGenerator materialGenerator = null,
ImporterContextSettings settings = null)
ImporterContextSettings settings = null,
bool isAssetImport = false)
{
IsAssetImport = isAssetImport;
_settings = settings ?? new ImporterContextSettings();
Data = data;
TextureDescriptorGenerator = new GltfTextureDescriptorGenerator(Data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ static void Process(Vrm10Data result, ScriptedImporter scriptedImporter, AssetIm

var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline);

using (var loader = new Vrm10Importer(result, externalObjectMap: extractedObjects, materialGenerator: materialGenerator))
using (var loader = new Vrm10Importer(result,
externalObjectMap: extractedObjects,
materialGenerator: materialGenerator,
isAssetImport: true))
{
// settings TextureImporters
foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable())
Expand Down
1 change: 1 addition & 0 deletions Assets/VRM10/Editor/Vrm10ExportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ protected override void ExportPath(string path)
{
Debug.Log("vrm-1.0 FreezeMesh");
var copy = GameObject.Instantiate(root);
copy.GetComponent<Vrm10Instance>().UpdateType = Vrm10Instance.UpdateTypes.None;
disposer.Push(copy);
root = copy;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Threading.Tasks;
using UniGLTF;
using UniGLTF.SpringBoneJobs.Blittables;
using UnityEngine;

namespace UniVRM10
{
/// <summary>
/// SpcriptedImporter 経由の import 向け。
/// NativeArray の確保や DontDestroyOnLoad を回避。
/// </summary>
public class Vrm10NopSpringboneRuntime : IVrm10SpringBoneRuntime
{
public void Dispose()
{
}

public Task InitializeAsync(Vrm10Instance instance, IAwaitCaller awaitCaller)
{
return Task.CompletedTask;
}

public void Process()
{
}

public bool ReconstructSpringBone()
{
return false;
}

public void RestoreInitialTransform()
{
}

public void SetJointLevel(Transform joint, BlittableJointMutable jointSettings)
{
}

public void SetModelLevel(Transform modelRoot, BlittableModelLevel modelSettings)
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 29 additions & 5 deletions Assets/VRM10/Runtime/IO/Vrm10Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public Vrm10Importer(
IMaterialDescriptorGenerator materialGenerator = null,
bool useControlRig = false,
ImporterContextSettings settings = null,
IVrm10SpringBoneRuntime springboneRuntime = null
IVrm10SpringBoneRuntime springboneRuntime = null,
bool isAssetImport = false
)
: base(vrm.Data, externalObjectMap, textureDeserializer, settings: settings)
: base(vrm.Data, externalObjectMap, textureDeserializer, settings: settings, isAssetImport: isAssetImport)
{
if (vrm == null)
{
Expand All @@ -53,7 +54,24 @@ public Vrm10Importer(
m_externalMap = new Dictionary<SubAssetKey, UnityEngine.Object>();
}

m_springboneRuntime = springboneRuntime ?? new Vrm10FastSpringboneRuntime();
m_springboneRuntime = MakeDefaultRuntime(springboneRuntime, isAssetImport);
}

static IVrm10SpringBoneRuntime MakeDefaultRuntime(IVrm10SpringBoneRuntime runtime, bool isAssetImport)
{
if (runtime != null)
{
return runtime;
}

if (isAssetImport)
{
// 何もしない dummy
return new Vrm10NopSpringboneRuntime();
}

// Vrm10Instance.MakeRuntime に移譲
return null;
}

static void AssignHumanoid(List<VrmLib.Node> nodes, UniGLTF.Extensions.VRMC_vrm.HumanBone humanBone, VrmLib.HumanoidBones key)
Expand Down Expand Up @@ -288,9 +306,15 @@ protected override async Task FinalizeAsync(IAwaitCaller awaitCaller)
await LoadSpringBoneAsync(awaitCaller, controller, springBone);
}

if (Application.isPlaying)
if (IsAssetImport)
{
// ScriptedImpoter から発動された。
// SpringBone のリソース確保を回避する。
// Application.isPlaying == true がありえる。
}
else
{
// EditorImport では呼ばない
// ScriptedImpoter 経由でない。
// Vrm10Runtime で初期化していたが、 async にするためこちらに移動 v0.127
// RuntimeGltfInstance にアクセスしたいのだが OnLoadHierarchy ではまだ attach されてなかった v0.128
// VRMC_springBone が無くても初期化する v0.127.2
Expand Down
1 change: 1 addition & 0 deletions ProjectSettings/QualitySettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ QualitySettings:
PSM: 5
PSP2: 2
Samsung TV: 2
Server: 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpringBoneとは関係なさそうな修正が入っている?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ。
まぁ、いいか 🙏

Standalone: 5
Switch: 5
Tizen: 2
Expand Down