diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index 3631a4df5..e12073de2 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -61,28 +61,47 @@ namespace UniVRM10 } } + void OnData() + { + if (m_result == null) + { + // error + return; + } + m_model = ModelReader.Read(m_result.Data); + + var tmp = m_importer.GetExternalObjectMap(); + + var generator = new Vrm10MaterialDescriptorGenerator(); + var materialKeys = m_result.Data.GLTF.materials.Select((x, i) => generator.Get(m_result.Data, i).SubAssetKey); + var textureKeys = new Vrm10TextureDescriptorGenerator(m_result.Data).Get().GetEnumerable().Select(x => x.SubAssetKey); + m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys), GetEditorMap, SetEditorMap); + m_vrmEditor = new RemapEditorVrm(new[] { VRM10Object.SubAssetKey }.Concat(EnumerateExpressinKeys(m_result.VrmExtension.Expressions)), GetEditorMap, SetEditorMap); + } + public override void OnEnable() { base.OnEnable(); var importer = target as VrmScriptedImporter; m_importer = importer; - using (Vrm10Data.ParseOrMigrate(m_importer.assetPath, importer.MigrateToVrm1, out m_result, out m_migration)) + using (var data = new GlbFileParser(m_importer.assetPath).Parse()) { - if (m_result == null) + m_result = Vrm10Data.Parse(data); + if (m_result != null) { - // error - return; + OnData(); + } + else + { + using (var migrated = Vrm10Data.Migrate(data, out m_result, out m_migration)) + { + if (m_result != null) + { + OnData(); + } + } } - m_model = ModelReader.Read(m_result.Data); - - var tmp = m_importer.GetExternalObjectMap(); - - var generator = new Vrm10MaterialDescriptorGenerator(); - var materialKeys = m_result.Data.GLTF.materials.Select((x, i) => generator.Get(m_result.Data, i).SubAssetKey); - var textureKeys = new Vrm10TextureDescriptorGenerator(m_result.Data).Get().GetEnumerable().Select(x => x.SubAssetKey); - m_materialEditor = new RemapEditorMaterial(materialKeys.Concat(textureKeys), GetEditorMap, SetEditorMap); - m_vrmEditor = new RemapEditorVrm(new[] { VRM10Object.SubAssetKey }.Concat(EnumerateExpressinKeys(m_result.VrmExtension.Expressions)), GetEditorMap, SetEditorMap); } } diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs index b3900eb74..979ea011e 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs @@ -29,60 +29,87 @@ namespace UniVRM10 } } + static void Process(Vrm10Data result, ScriptedImporter scriptedImporter, AssetImportContext context, RenderPipelineTypes renderPipeline, bool doNormalize) + { + // + // Import(create unity objects) + // + var extractedObjects = scriptedImporter.GetExternalObjectMap() + .Where(kv => kv.Value != null) + .ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value); + + var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline); + + using (var loader = new Vrm10Importer(result, extractedObjects, + materialGenerator: materialGenerator, + doNormalize: doNormalize)) + { + // settings TextureImporters + foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable()) + { + VRMShaders.TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalTextures); + } + + var loaded = loader.Load(); + loaded.ShowMeshes(); + + loaded.TransferOwnership((key, o) => + { + context.AddObjectToAsset(key.Name, o); + }); + var root = loaded.Root; + GameObject.DestroyImmediate(loaded); + + context.AddObjectToAsset(root.name, root); + context.SetMainObject(root); + } + } + /// /// /// /// /// - /// vrm0 だった場合に vrm1 化する + /// vrm0 だった場合に vrm1 化する /// /// normalize する - public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1, RenderPipelineTypes renderPipeline, bool doNormalize) + public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool doMigrate, RenderPipelineTypes renderPipeline, bool doNormalize) { #if VRM_DEVELOP Debug.Log("OnImportAsset to " + scriptedImporter.assetPath); #endif - using (var data = Vrm10Data.ParseOrMigrate(scriptedImporter.assetPath, migrateToVrm1, out Vrm10Data result, out MigrationData migration)) + // 1st parse as vrm1 + using (var data = new GlbFileParser(scriptedImporter.assetPath).Parse()) { - if (result == null) + var vrm1Data = Vrm10Data.Parse(data); + if (vrm1Data != null) + { + // successfully parsed vrm-1.0 + Process(vrm1Data, scriptedImporter, context, renderPipeline, doNormalize); + } + + if (!doMigrate) { - // fail to parse vrm1 return; } - // - // Import(create unity objects) - // - var extractedObjects = scriptedImporter.GetExternalObjectMap() - .Where(kv => kv.Value != null) - .ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value); - - var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline); - - using (var loader = new Vrm10Importer(result, extractedObjects, - materialGenerator: materialGenerator, - doNormalize: doNormalize)) + // try migration... + MigrationData migration; + using (var migrated = Vrm10Data.Migrate(data, out vrm1Data, out migration)) { - // settings TextureImporters - foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable()) + if (vrm1Data != null) { - VRMShaders.TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalTextures); + Process(vrm1Data, scriptedImporter, context, renderPipeline, doNormalize); } - - var loaded = loader.Load(); - loaded.ShowMeshes(); - - loaded.TransferOwnership((key, o) => - { - context.AddObjectToAsset(key.Name, o); - }); - var root = loaded.Root; - GameObject.DestroyImmediate(loaded); - - context.AddObjectToAsset(root.name, root); - context.SetMainObject(root); } + + // fail to migrate... + if (migration != null) + { + Debug.LogWarning(migration.Message); + } + return; } } } diff --git a/Assets/VRM10/Runtime/IO/MigrationData.cs b/Assets/VRM10/Runtime/IO/MigrationData.cs new file mode 100644 index 000000000..2dc4fb48e --- /dev/null +++ b/Assets/VRM10/Runtime/IO/MigrationData.cs @@ -0,0 +1,27 @@ +namespace UniVRM10 +{ + public class MigrationData + { + /// + /// マイグレーション失敗など + /// + public readonly string Message; + + /// + /// vrm0 からマイグレーションした場合に、vrm0 版の meta 情報 + /// + public readonly Migration.Vrm0Meta OriginalMetaBeforeMigration; + + /// + /// Migration した結果のバイト列(デバッグ用) + /// + public readonly byte[] MigratedBytes; + + public MigrationData(string msg, Migration.Vrm0Meta meta = default, byte[] bytes = default) + { + Message = msg; + OriginalMetaBeforeMigration = meta; + MigratedBytes = bytes; + } + } +} diff --git a/Assets/VRM10/Runtime/IO/MigrationData.cs.meta b/Assets/VRM10/Runtime/IO/MigrationData.cs.meta new file mode 100644 index 000000000..e00997231 --- /dev/null +++ b/Assets/VRM10/Runtime/IO/MigrationData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86d0f8ee9681a2e43b959952e51810cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/IO/Vrm10Data.cs b/Assets/VRM10/Runtime/IO/Vrm10Data.cs index fe122898d..cf4c9069e 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Data.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Data.cs @@ -4,34 +4,10 @@ using System.Linq; using UniGLTF; using UniGLTF.Extensions.VRMC_vrm; using UniJSON; +using UnityEngine; namespace UniVRM10 { - public class MigrationData - { - /// - /// マイグレーション失敗など - /// - public readonly String Message; - - /// - /// vrm0 からマイグレーションした場合に、vrm0 版の meta 情報 - /// - public readonly Migration.Vrm0Meta OriginalMetaBeforeMigration; - - /// - /// Migration した結果のバイト列(デバッグ用) - /// - public readonly byte[] MigratedBytes; - - public MigrationData(string msg, Migration.Vrm0Meta meta = default, byte[] bytes = default) - { - Message = msg; - OriginalMetaBeforeMigration = meta; - MigratedBytes = bytes; - } - } - public class Vrm10Data { public GltfData Data { get; } @@ -43,92 +19,67 @@ namespace UniVRM10 VrmExtension = vrm; } - public static GltfData ParseOrMigrate(string path, bool doMigrate, out Vrm10Data vrm1Data, out MigrationData migration) + /// + /// VRM-1.0 拡張を取得する。 + /// + /// + /// 失敗したら null が返る + public static Vrm10Data Parse(GltfData data) { - return ParseOrMigrate(path, File.ReadAllBytes(path), doMigrate, out vrm1Data, out migration); + if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(data.GLTF.extensions, out var vrm)) + { + return null; + } + return new Vrm10Data(data, vrm); } /// - /// vrm1 をパースする。vrm0 からのマイグレートもできる。 + /// /// - /// - /// - /// - /// 成功した場合非 null - /// doMigrate==true の場合、関連情報が入る - /// GltfDataを作成できたときは Return するのでDisposeすること - public static GltfData ParseOrMigrate(string path, byte[] bytes, bool doMigrate, out Vrm10Data vrm1Data, out MigrationData migration) + /// + /// + /// + /// Migrated GltfData if succeeded. Must Dispose + public static GltfData Migrate(GltfData data, out Vrm10Data vrm1Data, out MigrationData migration) { - var data = new GlbLowLevelParser(path, bytes).Parse(); - byte[] migrated = default; - byte[] migratedBytes = null; - Migration.Vrm0Meta oldMeta = default; - try + var json = data.Json.ParseAsJson(); + if (!json.TryGet("extensions", out JsonNode extensions)) { - if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(data.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm)) - { - // success - vrm1Data = new Vrm10Data(data, vrm); - migration = default; - return data; - } - - if (!doMigrate) - { - vrm1Data = default; - migration = new MigrationData("Not vrm1 and no migration"); - return data; - } - - // try migrateion - // Migration.Vrm0Meta oldMeta = default; - JsonNode json = data.Json.ParseAsJson(); - if (!json.TryGet("extensions", out JsonNode extensions)) - { - vrm1Data = default; - migration = new MigrationData("gltf: no extensions"); - return data; - } - - if (!extensions.TryGet("VRM", out JsonNode vrm0)) - { - vrm1Data = default; - migration = new MigrationData("gltf: no vrm0"); - return data; - } - - // found vrm0 - oldMeta = Migration.Vrm0Meta.FromJsonBytes(json); - if (oldMeta == null) - { - throw new NullReferenceException("oldMeta"); - } - - // try migrate... - migrated = MigrationVrm.Migrate(data); - if (migrated == null) - { - vrm1Data = default; - migration = new MigrationData("Found vrm0. But fail to migrate", oldMeta); - return data; - } - - if (VRMShaders.Symbols.VRM_DEVELOP) - { - // load 時の右手左手座標変換でバッファが破壊的変更されるので、コピーを作っている - migratedBytes = migrated.Select(x => x).ToArray(); - } - } - catch (Exception ex) - { - // 何か起きた。Dispose は頼む vrm1Data = default; - migration = new MigrationData(ex.Message); - return data; + migration = new MigrationData("gltf: no extensions"); + return null; + } + + if (!extensions.TryGet("VRM", out JsonNode vrm0)) + { + vrm1Data = default; + migration = new MigrationData("gltf: no vrm0"); + return null; + } + + // found vrm0 + var oldMeta = Migration.Vrm0Meta.FromJsonBytes(json); + if (oldMeta == null) + { + throw new NullReferenceException("oldMeta"); + } + + // try migrate... + var migrated = MigrationVrm.Migrate(data); + if (migrated == null) + { + vrm1Data = default; + migration = new MigrationData("Found vrm0. But fail to migrate", oldMeta); + return null; + } + + byte[] debugCopy = null; + if (VRMShaders.Symbols.VRM_DEVELOP) + { + // load 時の右手左手座標変換でバッファが破壊的変更されるので、コピーを作っている + debugCopy = migrated.Select(x => x).ToArray(); } - // マイグレーション前を破棄 - data.Dispose(); // マイグレーション結果をパースする var migratedData = new GlbLowLevelParser(data.TargetPath, migrated).Parse(); try @@ -138,22 +89,26 @@ namespace UniVRM10 // migration した結果のパースに失敗した ! vrm1Data = default; migration = new MigrationData("vrm0: migrate but error ?", oldMeta, migrated); - return migratedData; + // 破棄 + migratedData.Dispose(); + return null; } { - // success + // success. 非null値が返るのはここだけ。 vrm1Data = new Vrm10Data(migratedData, vrm); - migration = new MigrationData("vrm0: migrated", oldMeta, migratedBytes); + migration = new MigrationData("vrm0: migrated", oldMeta, debugCopy); return migratedData; } } catch (Exception ex) { - // 何か起きた。Dispose は頼む + Debug.LogWarning(ex); vrm1Data = default; migration = new MigrationData(ex.Message); - return migratedData; + // 破棄 + migratedData.Dispose(); + return null; } } } diff --git a/Assets/VRM10/Runtime/IO/Vrm10Utility.cs b/Assets/VRM10/Runtime/IO/Vrm10Utility.cs index a1c7405b2..9f86ab2d3 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Utility.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Utility.cs @@ -7,9 +7,8 @@ namespace UniVRM10 { public static class Vrm10Utility { - // public delegate IMaterialDescriptorGenerator MaterialGeneratorCallback(VRM.glTF_VRM_extensions vrm); public delegate void MetaCallback(Texture2D thumbnail, UniGLTF.Extensions.VRMC_vrm.Meta meta1, Migration.Vrm0Meta meta0); - public static async Task LoadAsync(string path, + public static async Task LoadPathAsync(string path, bool doMigrate, bool doNormalize, IAwaitCaller awaitCaller = null, @@ -17,24 +16,67 @@ namespace UniVRM10 MetaCallback metaCallback = null ) { - using (var data = Vrm10Data.ParseOrMigrate(path, doMigrate, out Vrm10Data vrm1Data, out MigrationData migration)) + return await LoadBytesAsync(path, System.IO.File.ReadAllBytes(path), doMigrate, doNormalize, awaitCaller, materialGenerator, metaCallback); + } + + public static async Task LoadBytesAsync(string path, byte[] bytes, + bool doMigrate, + bool doNormalize, + IAwaitCaller awaitCaller = null, + IMaterialDescriptorGenerator materialGenerator = null, + MetaCallback metaCallback = null + ) + { + // 1st parse as vrm1 + using (var data = new GlbLowLevelParser(path, bytes).Parse()) { - if (vrm1Data == null) + var vrm1Data = Vrm10Data.Parse(data); + if (vrm1Data != null) + { + // successfully parsed vrm-1.0 + using (var loader = new Vrm10Importer(vrm1Data, materialGenerator: materialGenerator, doNormalize: doNormalize)) + { + if (metaCallback != null) + { + var thumbnail = await loader.LoadVrmThumbnailAsync(); + metaCallback(thumbnail, vrm1Data.VrmExtension.Meta, null); + } + var instance = await loader.LoadAsync(awaitCaller); + return instance; + } + } + + if (!doMigrate) { return default; } - using (var loader = new Vrm10Importer(vrm1Data, materialGenerator: materialGenerator, doNormalize: doNormalize)) - { - // migrate しても thumbnail は同じ - if (metaCallback != null) - { - var thumbnail = await loader.LoadVrmThumbnailAsync(); - metaCallback(thumbnail, vrm1Data.VrmExtension.Meta, migration.OriginalMetaBeforeMigration); - } - var instance = await loader.LoadAsync(awaitCaller); - return instance; + // try migration... + MigrationData migration; + using (var migrated = Vrm10Data.Migrate(data, out vrm1Data, out migration)) + { + if (vrm1Data != null) + { + // successfully migrated from vrm-0.x + using (var loader = new Vrm10Importer(vrm1Data, materialGenerator: materialGenerator, doNormalize: doNormalize)) + { + if (metaCallback != null) + { + var thumbnail = await loader.LoadVrmThumbnailAsync(); + metaCallback(thumbnail, vrm1Data.VrmExtension.Meta, null); + } + var instance = await loader.LoadAsync(awaitCaller); + return instance; + } + } } + + // fail to migrate... + if (migration != null) + { + Debug.LogWarning(migration.Message); + } + return default; } } } diff --git a/Assets/VRM10/Runtime/Scenes/Sample.cs b/Assets/VRM10/Runtime/Scenes/Sample.cs index e3678e898..c5c35bbab 100644 --- a/Assets/VRM10/Runtime/Scenes/Sample.cs +++ b/Assets/VRM10/Runtime/Scenes/Sample.cs @@ -13,27 +13,21 @@ namespace UniVRM10.Sample [SerializeField] string m_vrmPath = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm"; - static GameObject Import(byte[] bytes, FileInfo path) - { - using (var data = Vrm10Data.ParseOrMigrate(path.FullName, bytes, doMigrate: true, out Vrm10Data result, out MigrationData migration)) - using (var loader = new Vrm10Importer(result)) - { - var loaded = loader.Load(); - loaded.ShowMeshes(); - return loaded.gameObject; - } - } - // Start is called before the first frame update void OnEnable() { - var src = new FileInfo(m_vrmPath); - var go = Import(File.ReadAllBytes(m_vrmPath), src); + Run(); + } - var exportedBytes = Vrm10Exporter.Export(go); + async void Run() + { + var src = new FileInfo(m_vrmPath); + var instance = await Vrm10Utility.LoadPathAsync(m_vrmPath, true, true); + + var exportedBytes = Vrm10Exporter.Export(instance.gameObject); // Import 1.0 - var vrm10 = Import(exportedBytes, src); + var vrm10 = await Vrm10Utility.LoadBytesAsync("tmp.vrm", exportedBytes, false, true); var pos = vrm10.transform.position; pos.x += 1.5f; vrm10.transform.position = pos; diff --git a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs index 2715018dc..9b817596c 100644 --- a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs +++ b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs @@ -31,7 +31,8 @@ namespace UniVRM10.Test private (GameObject, IReadOnlyList) ToUnity(byte[] bytes) { // Vrm => Model - using (var data = Vrm10Data.ParseOrMigrate("tpm.vrm", bytes, true, out Vrm10Data result, out MigrationData migration)) + using(var data = new GlbBinaryParser(bytes, "tmp.vrm").Parse()) + using (var migrated = Vrm10Data.Migrate(data, out Vrm10Data result, out MigrationData migration)) { if (result == null) { diff --git a/Assets/VRM10/Tests/ApiSampleTests.cs b/Assets/VRM10/Tests/ApiSampleTests.cs index 2c40df71b..f306c7990 100644 --- a/Assets/VRM10/Tests/ApiSampleTests.cs +++ b/Assets/VRM10/Tests/ApiSampleTests.cs @@ -39,7 +39,8 @@ namespace UniVRM10.Test var path = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm"; Debug.Log($"load: {path}"); - using (var data = Vrm10Data.ParseOrMigrate(path, true, out Vrm10Data result, out MigrationData migration)) + using (var data = new GlbFileParser(path).Parse()) + using (var migrated = Vrm10Data.Migrate(data, out Vrm10Data result, out MigrationData migration)) { Assert.NotNull(result); diff --git a/Assets/VRM10/Tests/LoadTests.cs b/Assets/VRM10/Tests/LoadTests.cs index 9d10f27be..652e5a146 100644 --- a/Assets/VRM10/Tests/LoadTests.cs +++ b/Assets/VRM10/Tests/LoadTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using UniGLTF; namespace UniVRM10.Test { @@ -7,16 +8,18 @@ namespace UniVRM10.Test [Test] public void EmptyThumbnailName() { - using (var data = Vrm10Data.ParseOrMigrate(TestAsset.AliciaPath, true, out Vrm10Data vrm, out MigrationData migration)) + using (var data = new GlbFileParser(TestAsset.AliciaPath).Parse()) + using (var migrated = Vrm10Data.Migrate(data, out var vrm1Data, out var migration)) { - Assert.NotNull(vrm); + // Vrm10Data.ParseOrMigrate(TestAsset.AliciaPath, true, out Vrm10Data vrm, out MigrationData migration)) + Assert.NotNull(vrm1Data); - var index = vrm.VrmExtension.Meta.ThumbnailImage.Value; + var index = vrm1Data.VrmExtension.Meta.ThumbnailImage.Value; // empty thumbnail name - vrm.Data.GLTF.images[index].name = null; + vrm1Data.Data.GLTF.images[index].name = null; - using (var loader = new Vrm10Importer(vrm)) + using (var loader = new Vrm10Importer(vrm1Data)) { loader.LoadAsync(new VRMShaders.ImmediateCaller()).Wait(); } diff --git a/Assets/VRM10/Tests/MigrationTests.cs b/Assets/VRM10/Tests/MigrationTests.cs index d6ade99be..62044094e 100644 --- a/Assets/VRM10/Tests/MigrationTests.cs +++ b/Assets/VRM10/Tests/MigrationTests.cs @@ -198,11 +198,7 @@ namespace UniVRM10 { try { - using (var data = Vrm10Data.ParseOrMigrate(gltf.FullName, true, out Vrm10Data vrm, out MigrationData migration)) - using (var loader = new Vrm10Importer(vrm)) - { - loader.LoadAsync().Wait(); - } + Vrm10Utility.LoadPathAsync(gltf.FullName, true, false).Wait(); } catch (UnNormalizedException) { @@ -261,7 +257,8 @@ namespace UniVRM10 [Test] public void MigrateMeta() { - using (var data = Vrm10Data.ParseOrMigrate(AliciaPath, true, out Vrm10Data vrm, out MigrationData migration)) + using (var data = new GlbFileParser(AliciaPath).Parse()) + using (var migrated = Vrm10Data.Migrate(data, out Vrm10Data vrm, out MigrationData migration)) { Assert.NotNull(vrm); Assert.NotNull(migration); diff --git a/Assets/VRM10/Tests/TestAsset.cs b/Assets/VRM10/Tests/TestAsset.cs index aaaaae76f..9b536d66e 100644 --- a/Assets/VRM10/Tests/TestAsset.cs +++ b/Assets/VRM10/Tests/TestAsset.cs @@ -16,16 +16,11 @@ namespace UniVRM10 public static Vrm10Instance LoadAlicia() { - using (var data = Vrm10Data.ParseOrMigrate(AliciaPath, true, out Vrm10Data vrm, out MigrationData migration)) - using (var loader = new Vrm10Importer(vrm)) - { - var task = loader.LoadAsync(new VRMShaders.ImmediateCaller()); - task.Wait(); + var task = Vrm10Utility.LoadPathAsync(AliciaPath, true, true); + task.Wait(); + var instance = task.Result; - var instance = task.Result; - - return instance.GetComponent(); - } + return instance.GetComponent(); } } } diff --git a/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs b/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs index 44f40f790..f10c429ae 100644 --- a/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs +++ b/Assets/VRM10_Samples/VRM10FirstPersonSample/VRM10RuntimeLoader.cs @@ -88,7 +88,7 @@ namespace UniVRM10.FirstPersonSample async Task LoadAsync(string path) { - var instance = await Vrm10Utility.LoadAsync(path, true, true); + var instance = await Vrm10Utility.LoadPathAsync(path, true, true); // VR用 FirstPerson 設定 var controller = instance.GetComponent(); diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index ccfc5dc0b..89f606eb3 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -415,7 +415,7 @@ namespace UniVRM10.VRM10Viewer } Debug.LogFormat("{0}", path); - var instance = await Vrm10Utility.LoadAsync(path, true, m_useNormalization.isOn, + var instance = await Vrm10Utility.LoadPathAsync(path, true, m_useNormalization.isOn, awaitCaller: new RuntimeOnlyAwaitCaller(), materialGenerator: GetVrmMaterialDescriptorGenerator(m_useUrpMaterial.isOn), metaCallback: m_texts.UpdateMeta);