From e22189c7bb0ee236f640380cb35614b5ec00e3df Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 4 Feb 2022 19:51:26 +0900 Subject: [PATCH] UniVRM-0.95.0 --- .../UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs | 4 +- Assets/UniGLTF/package.json | 4 +- Assets/VRM/Runtime/Format/VRMVersion.cs | 4 +- .../FirstPersonSample/VRMRuntimeLoader.cs | 23 +-- .../VRMRuntimeExporter.cs | 22 +-- Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs | 82 +++-------- Assets/VRM/package.json | 6 +- .../VRM10RuntimeLoader.cs | 21 +-- .../Samples~/VRM10Viewer/VRM10ViewerUI.cs | 136 ++++++------------ Assets/VRM10/package.json | 6 +- Assets/VRMShaders/package.json | 2 +- 11 files changed, 85 insertions(+), 225 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs b/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs index 2ce72dbaa..4f1ae5db8 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs @@ -4,8 +4,8 @@ namespace UniGLTF public static partial class UniGLTFVersion { public const int MAJOR = 2; - public const int MINOR = 30; + public const int MINOR = 31; public const int PATCH = 0; - public const string VERSION = "2.30.0"; + public const string VERSION = "2.31.0"; } } diff --git a/Assets/UniGLTF/package.json b/Assets/UniGLTF/package.json index 7ab68dfd2..bb8ecf14b 100644 --- a/Assets/UniGLTF/package.json +++ b/Assets/UniGLTF/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.gltf", - "version": "0.94.0", + "version": "0.95.0", "displayName": "UniGLTF", "description": "GLTF importer and exporter", "unity": "2019.4", @@ -11,6 +11,6 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.vrmshaders": "0.94.0" + "com.vrmc.vrmshaders": "0.95.0" } } \ No newline at end of file diff --git a/Assets/VRM/Runtime/Format/VRMVersion.cs b/Assets/VRM/Runtime/Format/VRMVersion.cs index 40c44e2c5..c931a9fcb 100644 --- a/Assets/VRM/Runtime/Format/VRMVersion.cs +++ b/Assets/VRM/Runtime/Format/VRMVersion.cs @@ -4,8 +4,8 @@ namespace VRM public static partial class VRMVersion { public const int MAJOR = 0; - public const int MINOR = 94; + public const int MINOR = 95; public const int PATCH = 0; - public const string VERSION = "0.94.0"; + public const string VERSION = "0.95.0"; } } diff --git a/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs b/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs index 57dcb479e..ed4c36a07 100644 --- a/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs +++ b/Assets/VRM/Samples~/FirstPersonSample/VRMRuntimeLoader.cs @@ -85,27 +85,8 @@ namespace VRM.FirstPersonSample // GLB形式でJSONを取得しParseします // VRM extension を parse します - var data = new GlbFileParser(path).Parse(); - var vrm = new VRMData(data); - using (var context = new VRMImporterContext(vrm)) - { - // metaを取得(todo: thumbnailテクスチャのロード) - var meta = await context.ReadMetaAsync(); - Debug.LogFormat("meta: title:{0}", meta.Title); - - // ParseしたJSONをシーンオブジェクトに変換していく - var loaded = default(RuntimeGltfInstance); - if (m_loadAsync) - { - loaded = await context.LoadAsync(); - } - else - { - loaded = context.Load(); - } - - OnLoaded(loaded); - } + var loaded = await VrmUtility.LoadAsync(path); + OnLoaded(loaded); } /// diff --git a/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs b/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs index 50c6fce21..0c39e342c 100644 --- a/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs +++ b/Assets/VRM/Samples~/RuntimeExporterSample/VRMRuntimeExporter.cs @@ -49,25 +49,11 @@ namespace VRM.RuntimeExporterSample return; } - // GLB形式でJSONを取得しParseします - var data = new GlbFileParser(path).Parse(); - // VRM extension を parse します - var vrm = new VRMData(data); - using (var context = new VRMImporterContext(vrm)) - { + var loaded = await VrmUtility.LoadAsync(path); - // metaを取得(todo: thumbnailテクスチャのロード) - var meta = await context.ReadMetaAsync(); - Debug.LogFormat("meta: title:{0}", meta.Title); - - // ParseしたJSONをシーンオブジェクトに変換していく - var loaded = await context.LoadAsync(); - - loaded.ShowMeshes(); - loaded.EnableUpdateWhenOffscreen(); - - OnLoaded(loaded.gameObject); - } + loaded.ShowMeshes(); + loaded.EnableUpdateWhenOffscreen(); + OnLoaded(loaded.gameObject); } void OnLoaded(GameObject go) diff --git a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs index d60fa64a6..fb924cd22 100644 --- a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs @@ -103,10 +103,8 @@ namespace VRM.SimpleViewer m_textDistributionOther.text = ""; } - public async Task UpdateMetaAsync(VRMImporterContext context) + public void UpdateMeta(VRMMetaObject meta) { - var meta = await context.ReadMetaAsync(new ImmediateCaller(), true); - m_textModelTitle.text = meta.Title; m_textModelVersion.text = meta.Version; m_textModelAuthor.text = meta.Author; @@ -321,7 +319,7 @@ namespace VRM.SimpleViewer string[] cmds = System.Environment.GetCommandLineArgs(); if (cmds.Length > 1) { - LoadModel(cmds[1]); + LoadModelAsync(cmds[1]); } m_texts.Start(); @@ -366,10 +364,10 @@ namespace VRM.SimpleViewer return; } - LoadModel(path); + LoadModelAsync(path); } - void LoadModel(string path) + async void LoadModelAsync(string path) { var ext = Path.GetExtension(path).ToLower(); switch (ext) @@ -377,12 +375,21 @@ namespace VRM.SimpleViewer case ".gltf": case ".glb": case ".zip": - LoadModelAsync(path, false); - break; + { + var instance = await GltfUtility.LoadAsync(path, + GetIAwaitCaller(m_useAsync.isOn), + GetGltfMaterialGenerator(m_useUrpMaterial.isOn)); + break; + } case ".vrm": - LoadModelAsync(path, true); - break; + { + VrmUtility.MaterialGeneratorCallback materialCallback = (VRM.glTF_VRM_extensions vrm) => GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm); + VrmUtility.MetaCallback metaCallback = m_texts.UpdateMeta; + var instance = await VrmUtility.LoadAsync(path, GetIAwaitCaller(m_useAsync.isOn), materialCallback, metaCallback); + SetModel(instance); + break; + } case ".bvh": LoadMotion(path, File.ReadAllText(path)); @@ -431,59 +438,6 @@ namespace VRM.SimpleViewer } } - async void LoadModelAsync(string path, bool isVrm) - { - if (!File.Exists(path)) - { - return; - } - - Debug.LogFormat("{0}", path); - - GltfData data; - try - { - data = new AutoGltfFileParser(path).Parse(); - } - catch (Exception ex) - { - Debug.LogWarningFormat("parse error: {0}", ex); - return; - } - - if (isVrm) - { - try - { - var vrm = new VRMData(data); - using (var loader = new VRMImporterContext(vrm, materialGenerator: GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm.VrmExtension))) - { - await m_texts.UpdateMetaAsync(loader); - var instance = await loader.LoadAsync(GetIAwaitCaller(m_useAsync.isOn)); - SetModel(instance); - } - } - catch (NotVrm0Exception) - { - // retry - Debug.LogWarning("file extension is vrm. but not vrm ?"); - using (var loader = new UniGLTF.ImporterContext(data, materialGenerator: GetGltfMaterialGenerator(m_useUrpMaterial.isOn))) - { - var instance = await loader.LoadAsync(GetIAwaitCaller(m_useAsync.isOn)); - SetModel(instance); - } - } - } - else - { - using (var loader = new UniGLTF.ImporterContext(data, materialGenerator: GetGltfMaterialGenerator(m_useUrpMaterial.isOn))) - { - var instance = await loader.LoadAsync(GetIAwaitCaller(m_useAsync.isOn)); - SetModel(instance); - } - } - } - void SetModel(RuntimeGltfInstance instance) { // cleanup @@ -495,7 +449,7 @@ namespace VRM.SimpleViewer if (m_useFastSpringBone.isOn) { - FastSpringBoneReplacer.ReplaceAsync(instance.Root); + var _ = FastSpringBoneReplacer.ReplaceAsync(instance.Root); } instance.EnableUpdateWhenOffscreen(); diff --git a/Assets/VRM/package.json b/Assets/VRM/package.json index a6ec86422..f7b30634d 100644 --- a/Assets/VRM/package.json +++ b/Assets/VRM/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.univrm", - "version": "0.94.0", + "version": "0.95.0", "displayName": "VRM", "description": "VRM importer", "unity": "2019.4", @@ -14,8 +14,8 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.vrmshaders": "0.94.0", - "com.vrmc.gltf": "0.94.0" + "com.vrmc.vrmshaders": "0.95.0", + "com.vrmc.gltf": "0.95.0" }, "samples": [ { diff --git a/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs b/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs index 9ea0ea4de..b2c30e826 100644 --- a/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs +++ b/Assets/VRM10/Samples~/VRM10FirstPersonSample/VRM10RuntimeLoader.cs @@ -82,27 +82,16 @@ namespace UniVRM10.FirstPersonSample } m_target = humanPoseTransfer; SetupTarget(m_target); - - instance.ShowMeshes(); } - async Task LoadAsync(string path) + async Task LoadAsync(string path) { - var data = new GlbFileParser(path).Parse(); - if (!Vrm10Data.TryParseOrMigrate(data, true, out Vrm10Data vrm)) - { - throw new System.Exception("vrm parse error !"); - } - using (var loader = new Vrm10Importer(vrm)) - { - var instance = await loader.LoadAsync(); + var instance = await Vrm10.LoadPathAsync(path); - // VR用 FirstPerson 設定 - var controller = instance.GetComponent(); - await controller.Vrm.FirstPerson.SetupAsync(controller.gameObject); + // VR用 FirstPerson 設定 + await instance.Vrm.FirstPerson.SetupAsync(instance.gameObject); - return instance; - } + return instance; } void LoadBVHClicked() diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs index 9d0e0f5fe..77f191a0a 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs @@ -96,55 +96,45 @@ namespace UniVRM10.VRM10Viewer m_textDistributionOther.text = ""; } - public void UpdateMeta(Migration.Vrm0Meta meta, Texture2D thumbnail) + public void UpdateMeta(Texture2D thumbnail, UniGLTF.Extensions.VRMC_vrm.Meta meta, Migration.Vrm0Meta meta0) { - if (meta == null) - { - return; - } - - m_textModelTitle.text = meta.title; - m_textModelVersion.text = meta.version; - m_textModelAuthor.text = meta.author; - m_textModelContact.text = meta.contactInformation; - m_textModelReference.text = meta.reference; - m_textPermissionAllowed.text = meta.allowedUser.ToString(); - m_textPermissionViolent.text = meta.violentUsage.ToString(); - m_textPermissionSexual.text = meta.sexualUsage.ToString(); - m_textPermissionCommercial.text = meta.commercialUsage.ToString(); - m_textPermissionOther.text = meta.otherPermissionUrl; - - // m_textDistributionLicense.text = meta.ModificationLicense.ToString(); - m_textDistributionOther.text = meta.otherLicenseUrl; - m_thumbnail.texture = thumbnail; - } - public void UpdateMeta(UniGLTF.Extensions.VRMC_vrm.Meta meta, Texture2D thumbnail) - { - if (meta == null) + if (meta != null) { - return; + m_textModelTitle.text = meta.Name; + m_textModelVersion.text = meta.Version; + m_textModelAuthor.text = meta.Authors[0]; + m_textModelContact.text = meta.ContactInformation; + if (meta.References != null && meta.References.Count > 0) + { + m_textModelReference.text = meta.References[0]; + } + // m_textPermissionAllowed.text = meta.AllowedUser.ToString(); + m_textPermissionViolent.text = meta.AllowExcessivelyViolentUsage.ToString(); + m_textPermissionSexual.text = meta.AllowExcessivelySexualUsage.ToString(); + m_textPermissionCommercial.text = meta.CommercialUsage.ToString(); + // m_textPermissionOther.text = meta.OtherPermissionUrl; + + // m_textDistributionLicense.text = meta.ModificationLicense.ToString(); + m_textDistributionOther.text = meta.OtherLicenseUrl; } - m_textModelTitle.text = meta.Name; - m_textModelVersion.text = meta.Version; - m_textModelAuthor.text = meta.Authors[0]; - m_textModelContact.text = meta.ContactInformation; - if (meta.References != null && meta.References.Count > 0) + if (meta0 != null) { - m_textModelReference.text = meta.References[0]; + m_textModelTitle.text = meta0.title; + m_textModelVersion.text = meta0.version; + m_textModelAuthor.text = meta0.author; + m_textModelContact.text = meta0.contactInformation; + m_textModelReference.text = meta0.reference; + m_textPermissionAllowed.text = meta0.allowedUser.ToString(); + m_textPermissionViolent.text = meta0.violentUsage.ToString(); + m_textPermissionSexual.text = meta0.sexualUsage.ToString(); + m_textPermissionCommercial.text = meta0.commercialUsage.ToString(); + m_textPermissionOther.text = meta0.otherPermissionUrl; + // m_textDistributionLicense.text = meta0.ModificationLicense.ToString(); + m_textDistributionOther.text = meta0.otherLicenseUrl; } - // m_textPermissionAllowed.text = meta.AllowedUser.ToString(); - m_textPermissionViolent.text = meta.AllowExcessivelyViolentUsage.ToString(); - m_textPermissionSexual.text = meta.AllowExcessivelySexualUsage.ToString(); - m_textPermissionCommercial.text = meta.CommercialUsage.ToString(); - // m_textPermissionOther.text = meta.OtherPermissionUrl; - - // m_textDistributionLicense.text = meta.ModificationLicense.ToString(); - m_textDistributionOther.text = meta.OtherLicenseUrl; - - m_thumbnail.texture = thumbnail; } } [SerializeField] @@ -425,62 +415,22 @@ namespace UniVRM10.VRM10Viewer } Debug.LogFormat("{0}", path); - GltfData data; - try + var vrm10Instance = await Vrm10.LoadPathAsync(path, + canLoadVrm0X: true, + normalizeTransform: m_useNormalization.isOn, + showMeshes: false, + awaitCaller: new RuntimeOnlyAwaitCaller(), + materialGenerator: GetVrmMaterialDescriptorGenerator(m_useUrpMaterial.isOn), + vrmMetaInformationCallback: m_texts.UpdateMeta); + if (vrm10Instance != null) { - data = new AutoGltfFileParser(path).Parse(); - } - catch (Exception ex) - { - Debug.LogWarning(ex); - return; - } - - var vrm = await System.Threading.Tasks.Task.Run(() => - { - if (Vrm10Data.TryParseOrMigrate(data, doMigrate: true, out Vrm10Data _vrm)) - { - return _vrm; - } - else - { - return null; - } - }); - - if (vrm != null) - { - // vrm - using (var loader = new Vrm10Importer(vrm, - materialGenerator: GetVrmMaterialDescriptorGenerator(m_useUrpMaterial.isOn), - doNormalize: m_useNormalization.isOn)) - { - // migrate しても thumbnail は同じ - var thumbnail = await loader.LoadVrmThumbnailAsync(); - - if (vrm.OriginalMetaBeforeMigration != null) - { - // migrated from vrm-0.x. use OldMeta - m_texts.UpdateMeta(vrm.OriginalMetaBeforeMigration, thumbnail); - } - else - { - // load vrm-1.0. use newMeta - m_texts.UpdateMeta(vrm.VrmExtension.Meta, thumbnail); - } - - var instance = await loader.LoadAsync(new RuntimeOnlyAwaitCaller()); - SetModel(instance); - } + SetModel(vrm10Instance.GetComponent()); } else { - // gltf - using (var loader = new UniGLTF.ImporterContext(data, materialGenerator: GetMaterialDescriptorGenerator(m_useUrpMaterial.isOn))) - { - var instance = await loader.LoadAsync(new RuntimeOnlyAwaitCaller()); - SetModel(instance); - } + // fallback to gltf + var instance = await GltfUtility.LoadAsync(path, awaitCaller: new RuntimeOnlyAwaitCaller()); + SetModel(instance); } } diff --git a/Assets/VRM10/package.json b/Assets/VRM10/package.json index cd05b28cf..b2143c9b1 100644 --- a/Assets/VRM10/package.json +++ b/Assets/VRM10/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.vrm", - "version": "0.94.0", + "version": "0.95.0", "displayName": "VRM-1.0β", "description": "VRM-1.0β importer", "unity": "2019.4", @@ -14,8 +14,8 @@ "name": "VRM Consortium" }, "dependencies": { - "com.vrmc.vrmshaders": "0.94.0", - "com.vrmc.gltf": "0.94.0" + "com.vrmc.vrmshaders": "0.95.0", + "com.vrmc.gltf": "0.95.0" }, "samples": [ { diff --git a/Assets/VRMShaders/package.json b/Assets/VRMShaders/package.json index 6e1466c66..ae0f7fb91 100644 --- a/Assets/VRMShaders/package.json +++ b/Assets/VRMShaders/package.json @@ -1,6 +1,6 @@ { "name": "com.vrmc.vrmshaders", - "version": "0.94.0", + "version": "0.95.0", "displayName": "VRM Shaders", "description": "VRM Shaders", "unity": "2019.4",