From 10dafaab49fa7bb85e68ad628bbe2e25813f0ce6 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 24 Jan 2025 22:00:02 +0900 Subject: [PATCH 01/10] springboneRuntime --- Assets/VRM10/Runtime/IO/Vrm10.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Assets/VRM10/Runtime/IO/Vrm10.cs b/Assets/VRM10/Runtime/IO/Vrm10.cs index a797df092..1008602fa 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10.cs @@ -99,7 +99,8 @@ namespace UniVRM10 IMaterialDescriptorGenerator materialGenerator = null, VrmMetaInformationCallback vrmMetaInformationCallback = null, CancellationToken ct = default, - ImporterContextSettings importerContextSettings = null) + ImporterContextSettings importerContextSettings = null, + IVrm10SpringBoneRuntime springboneRuntime = null) { awaitCaller ??= Application.isPlaying ? new RuntimeOnlyAwaitCaller() @@ -116,7 +117,8 @@ namespace UniVRM10 materialGenerator, vrmMetaInformationCallback, ct, - importerContextSettings); + importerContextSettings, + springboneRuntime); } /// From 8108583f3ea7d414f95b5b30dd2c7a13e2b34894 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 24 Jan 2025 22:45:42 +0900 Subject: [PATCH 02/10] fix SimpleViewer WebGL build --- .../Runtime/Utils}/Plugins.meta | 0 .../Runtime/Utils}/Plugins/OpenFile.jslib | 8 +++++--- .../Runtime/Utils}/Plugins/OpenFile.jslib.meta | 0 .../Samples~/SimpleViewer/FileDialog/FileUtil.cs | 4 ++-- .../Samples~/SimpleViewer/FileDialog/WebGLUtil.cs | 2 +- Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs | 4 ++-- .../SimpleViewer/FileDialog/FileUtil.cs | 2 +- .../SimpleViewer/FileDialog/WebGLUtil.cs | 2 +- Assets/VRM_Samples/SimpleViewer/ViewerUI.cs | 14 +++++++++----- ProjectSettings/EditorBuildSettings.asset | 6 +++++- 10 files changed, 26 insertions(+), 16 deletions(-) rename Assets/{VRM_Samples/SimpleViewer => UniGLTF/Runtime/Utils}/Plugins.meta (100%) rename Assets/{VRM_Samples/SimpleViewer => UniGLTF/Runtime/Utils}/Plugins/OpenFile.jslib (68%) rename Assets/{VRM_Samples/SimpleViewer => UniGLTF/Runtime/Utils}/Plugins/OpenFile.jslib.meta (100%) diff --git a/Assets/VRM_Samples/SimpleViewer/Plugins.meta b/Assets/UniGLTF/Runtime/Utils/Plugins.meta similarity index 100% rename from Assets/VRM_Samples/SimpleViewer/Plugins.meta rename to Assets/UniGLTF/Runtime/Utils/Plugins.meta diff --git a/Assets/VRM_Samples/SimpleViewer/Plugins/OpenFile.jslib b/Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib similarity index 68% rename from Assets/VRM_Samples/SimpleViewer/Plugins/OpenFile.jslib rename to Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib index 48ba0ce57..691e2af72 100644 --- a/Assets/VRM_Samples/SimpleViewer/Plugins/OpenFile.jslib +++ b/Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib @@ -1,18 +1,20 @@ mergeInto(LibraryManager.library, { - WebGLFileDialog: function () { + WebGLFileDialog: function (_target, _message) { + const target = UTF8ToString(_target); + const message = UTF8ToString(_message); const file_input_id = "file-input"; var file_input = document.getElementById(file_input_id); if (!file_input) { file_input = document.createElement('input'); file_input.setAttribute('type', 'file'); file_input.setAttribute('id', file_input_id); - // file_input.setAttribute('accept', '.vrm') file_input.style.visibility = 'hidden'; file_input.onclick = function (event) { event.target.value = null; }; file_input.onchange = function (event) { - SendMessage('Canvas', 'FileSelected', URL.createObjectURL(event.target.files[0])); + console.log('SendMessage', target, message); + SendMessage(target, message, URL.createObjectURL(event.target.files[0])); } document.body.appendChild(file_input); } diff --git a/Assets/VRM_Samples/SimpleViewer/Plugins/OpenFile.jslib.meta b/Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib.meta similarity index 100% rename from Assets/VRM_Samples/SimpleViewer/Plugins/OpenFile.jslib.meta rename to Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib.meta diff --git a/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs index b7c73f2c8..1aa1bda9d 100644 --- a/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs +++ b/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs @@ -8,8 +8,8 @@ namespace VRM.SimpleViewer return FileDialogForWindows.FileDialog(title, extensions); #elif UNITY_WEBGL // Open WebGLFileDialog - // see: Assets\VRM_Samples\SimpleViewer\Plugins\OpenFile.jslib - WebGLUtil.WebGLFileDialog(); + // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib + WebGLUtil.WebGLFileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return ""; #elif UNITY_EDITOR diff --git a/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs b/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs index 1d94e2de8..eaf48866d 100644 --- a/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs +++ b/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs @@ -6,7 +6,7 @@ namespace VRM.SimpleViewer public static class WebGLUtil { [DllImport("__Internal")] - public static extern void WebGLFileDialog(); + public static extern void WebGLFileDialog(string target, string message); } } #endif \ No newline at end of file diff --git a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs index 3a4988c90..36ca09951 100644 --- a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs @@ -359,9 +359,9 @@ namespace VRM.SimpleViewer IEnumerator LoadCoroutine(string url) { - var www = new UnityEngine.Networking.UnityWebRequest(url); + var www = new WWW(url); yield return www; - var task = LoadBytesAsync("WebGL.vrm", www.downloadHandler.data); + var task = LoadBytesAsync("WebGL.vrm", www.bytes); } /// diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs index b7c73f2c8..5a8abf371 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs @@ -9,7 +9,7 @@ namespace VRM.SimpleViewer #elif UNITY_WEBGL // Open WebGLFileDialog // see: Assets\VRM_Samples\SimpleViewer\Plugins\OpenFile.jslib - WebGLUtil.WebGLFileDialog(); + WebGLUtil.WebGLFileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return ""; #elif UNITY_EDITOR diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs index 1d94e2de8..eaf48866d 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs @@ -6,7 +6,7 @@ namespace VRM.SimpleViewer public static class WebGLUtil { [DllImport("__Internal")] - public static extern void WebGLFileDialog(); + public static extern void WebGLFileDialog(string target, string message); } } #endif \ No newline at end of file diff --git a/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs b/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs index 3a4988c90..4671e1135 100644 --- a/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using UniGLTF; -using UniGLTF.SpringBoneJobs; using UniHumanoid; using Unity.Collections; using UnityEngine; @@ -294,8 +293,7 @@ namespace VRM.SimpleViewer private void Start() { - m_version.text = string.Format("VRMViewer {0}.{1}", - PackageVersion.MAJOR, PackageVersion.MINOR); + m_version.text = string.Format("VRMViewer {0}", PackageVersion.VERSION); m_open.onClick.AddListener(OnOpenClicked); m_reset.onClick.AddListener(() => m_loaded?.ResetSpringbone()); @@ -313,6 +311,12 @@ namespace VRM.SimpleViewer } m_texts.Start(); + + if (Application.platform == RuntimePlatform.WebGLPlayer) + { + m_useAsync.isOn = false; + m_useAsync.interactable = false; + } } private void LoadMotion(string path, string source) @@ -359,9 +363,9 @@ namespace VRM.SimpleViewer IEnumerator LoadCoroutine(string url) { - var www = new UnityEngine.Networking.UnityWebRequest(url); + var www = new WWW(url); yield return www; - var task = LoadBytesAsync("WebGL.vrm", www.downloadHandler.data); + var task = LoadBytesAsync("WebGL.vrm", www.bytes); } /// diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 6dc24f7df..98205ba1b 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -4,4 +4,8 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 - m_Scenes: [] + m_Scenes: + - enabled: 1 + path: Assets/VRM_Samples/SimpleViewer/SimpleViewer.unity + guid: 5d0b0ec0bd1cdee4fbd25b64a6d059df + m_configObjects: {} From fe511a5211b5f142b721bb2b183b5d2d2056c9de Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 24 Jan 2025 23:38:37 +0900 Subject: [PATCH 03/10] BuildWebGLForCi --- Assets/VRM/Editor/BuildClass.cs | 23 ++++++++++++++++++++++- Assets/VRM/Editor/VrmTopMenu.cs | 5 ++++- ProjectSettings/ProjectSettings.asset | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Assets/VRM/Editor/BuildClass.cs b/Assets/VRM/Editor/BuildClass.cs index f1ed4a9c9..43f99e2f4 100644 --- a/Assets/VRM/Editor/BuildClass.cs +++ b/Assets/VRM/Editor/BuildClass.cs @@ -1,4 +1,5 @@ using UnityEditor; +using UnityEngine.Rendering; namespace VRM { @@ -15,7 +16,7 @@ namespace VRM var report = BuildPipeline.BuildPlayer( scenes, - "./Build/DummyBuild.exe", + "./Build/DummyBuild/DummyBuild.exe", BuildTarget.StandaloneWindows, BuildOptions.Development ); @@ -25,5 +26,25 @@ namespace VRM throw new System.Exception(report.summary.ToString()); } } + + public static void BuildWebGL_SimpleViewer() + { + var scenes = new string[]{ + "./Assets/VRM_Samples/SimpleViewer/SimpleViewer.unity", + }; + + var report = BuildPipeline.BuildPlayer(new BuildPlayerOptions + { + scenes = scenes, + locationPathName = "Build/SimpleViewer", + target = BuildTarget.WebGL, + } + ); + + if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded) + { + throw new System.Exception(report.summary.ToString()); + } + } } } diff --git a/Assets/VRM/Editor/VrmTopMenu.cs b/Assets/VRM/Editor/VrmTopMenu.cs index f1e910074..895cf1cdf 100644 --- a/Assets/VRM/Editor/VrmTopMenu.cs +++ b/Assets/VRM/Editor/VrmTopMenu.cs @@ -55,7 +55,10 @@ namespace VRM [MenuItem(DevelopmentMenuPrefix + "/Build dummy for CI", false, 93)] private static void BuildDummyForCi() => BuildClass.Build(); - [MenuItem(DevelopmentMenuPrefix + "/Create UnityPackage", false, 94)] + [MenuItem(DevelopmentMenuPrefix + "/Build WebGL for CI", false, 94)] + private static void BuildWebGLForCi() => BuildClass.BuildWebGL_SimpleViewer(); + + [MenuItem(DevelopmentMenuPrefix + "/Create UnityPackage", false, 95)] private static void CreateUnityPackage() => VRMExportUnityPackage.CreateUnityPackageWithoutBuild(); #endif } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index dca42bdd7..4574a21f1 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -602,7 +602,7 @@ PlayerSettings: webGLTemplate: APPLICATION:Default webGLAnalyzeBuildSize: 0 webGLUseEmbeddedResources: 0 - webGLCompressionFormat: 1 + webGLCompressionFormat: 2 webGLWasmArithmeticExceptions: 0 webGLLinkerTarget: 1 webGLThreadsSupport: 0 @@ -628,7 +628,7 @@ PlayerSettings: Stadia: UNITY_POST_PROCESSING_STACK_V2 Standalone: VRM_DEVELOP;UNITY_POST_PROCESSING_STACK_V2 VisionOS: UNITY_POST_PROCESSING_STACK_V2 - WebGL: UNITY_POST_PROCESSING_STACK_V2 + WebGL: UNITY_POST_PROCESSING_STACK_V2;VRM_DEVELOP Windows Store Apps: UNITY_POST_PROCESSING_STACK_V2 XboxOne: UNITY_POST_PROCESSING_STACK_V2 tvOS: UNITY_POST_PROCESSING_STACK_V2 From 1080729d0b1373fcdf87789f902f206e78db4ee4 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Sat, 25 Jan 2025 01:43:34 +0900 Subject: [PATCH 04/10] fix WebGL build VRM10Viewer --- .../VRM10Viewer/FaceCameraTarget.asset | 1 + .../VRM10Viewer/VRM10ViewerUI.cs | 78 ++++++++++++++++--- .../SimpleViewer/FileDialog/FileUtil.cs | 2 +- Assets/VRM_Samples/SimpleViewer/ViewerUI.cs | 8 +- ProjectSettings/EditorBuildSettings.asset | 5 +- 5 files changed, 73 insertions(+), 21 deletions(-) diff --git a/Assets/VRM10_Samples/VRM10Viewer/FaceCameraTarget.asset b/Assets/VRM10_Samples/VRM10Viewer/FaceCameraTarget.asset index c1311d8e0..dc5b55f8e 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/FaceCameraTarget.asset +++ b/Assets/VRM10_Samples/VRM10Viewer/FaceCameraTarget.asset @@ -26,6 +26,7 @@ CustomRenderTexture: m_UseDynamicScale: 0 m_BindMS: 0 m_EnableCompatibleFormat: 1 + m_EnableRandomWrite: 0 m_TextureSettings: serializedVersion: 2 m_FilterMode: 1 diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index 5dbc28055..cba67b0ab 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -1,8 +1,11 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading; +using System.Threading.Tasks; using UniGLTF; using UniGLTF.SpringBoneJobs.Blittables; using UnityEngine; @@ -474,8 +477,7 @@ namespace UniVRM10.VRM10Viewer m_autoBlink = gameObject.AddComponent(); m_autoLipsync = gameObject.AddComponent(); - m_version.text = string.Format("VRMViewer {0}.{1}", - VRM10SpecVersion.MAJOR, VRM10SpecVersion.MINOR); + m_version.text = string.Format("VRM10ViewerUI {0}", PackageVersion.VERSION); m_openModel.onClick.AddListener(OnOpenModelClicked); m_openMotion.onClick.AddListener(OnOpenMotionClicked); @@ -491,7 +493,7 @@ namespace UniVRM10.VRM10Viewer if (ArgumentChecker.TryGetFirstLoadable(out var cmd)) { - LoadModel(cmd); + var _ = LoadModel(cmd); } m_texts.Start(); @@ -502,7 +504,6 @@ namespace UniVRM10.VRM10Viewer _cancellationTokenSource?.Dispose(); } - private void Update() { if (Input.GetKeyDown(KeyCode.Tab)) @@ -639,15 +640,29 @@ namespace UniVRM10.VRM10Viewer } } - void OnOpenModelClicked() + [DllImport("__Internal")] + public static extern void WebGLFileDialog(string target, string message); + + string FileDialog() { #if UNITY_STANDALONE_WIN - var path = VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); + return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); +#elif UNITY_WEBGL + // Open WebGLFileDialog + // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib + WebGLFileDialog("Canvas", "FileSelected"); + // Control flow does not return here. return empty string with dummy + return null; #elif UNITY_EDITOR - var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); + return UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else - var path = Application.dataPath + "/default.vrm"; + return Application.dataPath + "/default.vrm"; #endif + } + + void OnOpenModelClicked() + { + var path = FileDialog(); if (string.IsNullOrEmpty(path)) { return; @@ -660,7 +675,24 @@ namespace UniVRM10.VRM10Viewer return; } - LoadModel(path); + _ = LoadModel(path); + } + + /// + /// for WebGL + /// call from OpenFile.jslib + /// + public void FileSelected(string url) + { + Debug.Log($"FileSelected: {url}"); + StartCoroutine(LoadCoroutine(url)); + } + + IEnumerator LoadCoroutine(string url) + { + var www = new WWW(url); + yield return www; + var _ = LoadModel("WebGL.vrm", www.bytes); } async void OnOpenMotionClicked() @@ -760,7 +792,29 @@ namespace UniVRM10.VRM10Viewer } } - async void LoadModel(string path) + IAwaitCaller GetIAwaitCaller() + { + if (m_useAsync) + { +#if UNITY_WEBGL + return new RuntimeOnlyNoThreadAwaitCaller(); +#else + return new RuntimeOnlyAwaitCaller(); +#endif + } + else + { + return new ImmediateCaller(); + } + } + + async Task LoadModel(string path) + { + var bytes = await File.ReadAllBytesAsync(path); + await LoadModel(path, bytes); + } + + async Task LoadModel(string path, byte[] bytes) { // cleanup m_loaded?.Dispose(); @@ -772,10 +826,10 @@ namespace UniVRM10.VRM10Viewer try { Debug.LogFormat("{0}", path); - var vrm10Instance = await Vrm10.LoadPathAsync(path, + var vrm10Instance = await Vrm10.LoadBytesAsync(bytes, canLoadVrm0X: true, showMeshes: false, - awaitCaller: m_useAsync.enabled ? new RuntimeOnlyAwaitCaller() : new ImmediateCaller(), + awaitCaller: GetIAwaitCaller(), vrmMetaInformationCallback: m_texts.UpdateMeta, ct: cancellationToken, springboneRuntime: m_useSpringboneSingelton.isOn ? new Vrm10FastSpringboneRuntime() : new Vrm10FastSpringboneRuntimeStandalone()); diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs index 5a8abf371..1aa1bda9d 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs @@ -8,7 +8,7 @@ namespace VRM.SimpleViewer return FileDialogForWindows.FileDialog(title, extensions); #elif UNITY_WEBGL // Open WebGLFileDialog - // see: Assets\VRM_Samples\SimpleViewer\Plugins\OpenFile.jslib + // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib WebGLUtil.WebGLFileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return ""; diff --git a/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs b/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs index 4671e1135..575f44556 100644 --- a/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM_Samples/SimpleViewer/ViewerUI.cs @@ -293,7 +293,7 @@ namespace VRM.SimpleViewer private void Start() { - m_version.text = string.Format("VRMViewer {0}", PackageVersion.VERSION); + m_version.text = string.Format("SimpleViewer {0}", PackageVersion.VERSION); m_open.onClick.AddListener(OnOpenClicked); m_reset.onClick.AddListener(() => m_loaded?.ResetSpringbone()); @@ -311,12 +311,6 @@ namespace VRM.SimpleViewer } m_texts.Start(); - - if (Application.platform == RuntimePlatform.WebGLPlayer) - { - m_useAsync.isOn = false; - m_useAsync.interactable = false; - } } private void LoadMotion(string path, string source) diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 98205ba1b..62587d23f 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -5,7 +5,10 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 m_Scenes: - - enabled: 1 + - enabled: 0 path: Assets/VRM_Samples/SimpleViewer/SimpleViewer.unity guid: 5d0b0ec0bd1cdee4fbd25b64a6d059df + - enabled: 1 + path: Assets/VRM10_Samples/VRM10Viewer/VRM10Viewer.unity + guid: c91fa5ff7b6696646a8b16d9bf88a5c2 m_configObjects: {} From e1db3122039ca3b794144bc13c563fa0dc81df72 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Sat, 25 Jan 2025 02:14:18 +0900 Subject: [PATCH 05/10] menu "Build 10 WebGL for CI". Update sample --- Assets/VRM/Editor/BuildClass.cs | 20 +++++ Assets/VRM/Editor/VrmTopMenu.cs | 9 ++- Assets/VRM/Samples~/SimpleViewer/Plugins.meta | 8 -- .../SimpleViewer/Plugins/OpenFile.jslib | 21 ----- .../SimpleViewer/Plugins/OpenFile.jslib.meta | 32 -------- Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs | 4 +- .../VRM10Viewer/FaceCameraTarget.asset | 1 + .../Samples~/VRM10Viewer/VRM10ViewerUI.cs | 78 ++++++++++++++++--- 8 files changed, 94 insertions(+), 79 deletions(-) delete mode 100644 Assets/VRM/Samples~/SimpleViewer/Plugins.meta delete mode 100644 Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib delete mode 100644 Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib.meta diff --git a/Assets/VRM/Editor/BuildClass.cs b/Assets/VRM/Editor/BuildClass.cs index 43f99e2f4..410de15a4 100644 --- a/Assets/VRM/Editor/BuildClass.cs +++ b/Assets/VRM/Editor/BuildClass.cs @@ -46,5 +46,25 @@ namespace VRM throw new System.Exception(report.summary.ToString()); } } + + public static void BuildWebGL_VRM10Viewer() + { + var scenes = new string[]{ + "./Assets/VRM10_Samples/VRM10Viewer/VRM10Viewer.unity", + }; + + var report = BuildPipeline.BuildPlayer(new BuildPlayerOptions + { + scenes = scenes, + locationPathName = "Build/VRM10Viewer", + target = BuildTarget.WebGL, + } + ); + + if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded) + { + throw new System.Exception(report.summary.ToString()); + } + } } } diff --git a/Assets/VRM/Editor/VrmTopMenu.cs b/Assets/VRM/Editor/VrmTopMenu.cs index 895cf1cdf..7c8caa901 100644 --- a/Assets/VRM/Editor/VrmTopMenu.cs +++ b/Assets/VRM/Editor/VrmTopMenu.cs @@ -55,10 +55,13 @@ namespace VRM [MenuItem(DevelopmentMenuPrefix + "/Build dummy for CI", false, 93)] private static void BuildDummyForCi() => BuildClass.Build(); - [MenuItem(DevelopmentMenuPrefix + "/Build WebGL for CI", false, 94)] - private static void BuildWebGLForCi() => BuildClass.BuildWebGL_SimpleViewer(); + [MenuItem(DevelopmentMenuPrefix + "/Build 0x WebGL for CI", false, 94)] + private static void BuildWebGLForCi0x() => BuildClass.BuildWebGL_SimpleViewer(); - [MenuItem(DevelopmentMenuPrefix + "/Create UnityPackage", false, 95)] + [MenuItem(DevelopmentMenuPrefix + "/Build 10 WebGL for CI", false, 95)] + private static void BuildWebGLForCi10() => BuildClass.BuildWebGL_VRM10Viewer(); + + [MenuItem(DevelopmentMenuPrefix + "/Create UnityPackage", false, 99)] private static void CreateUnityPackage() => VRMExportUnityPackage.CreateUnityPackageWithoutBuild(); #endif } diff --git a/Assets/VRM/Samples~/SimpleViewer/Plugins.meta b/Assets/VRM/Samples~/SimpleViewer/Plugins.meta deleted file mode 100644 index fdecce026..000000000 --- a/Assets/VRM/Samples~/SimpleViewer/Plugins.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ccb1849bc34bcd740ba2e17462125200 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib b/Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib deleted file mode 100644 index 48ba0ce57..000000000 --- a/Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib +++ /dev/null @@ -1,21 +0,0 @@ -mergeInto(LibraryManager.library, { - WebGLFileDialog: function () { - const file_input_id = "file-input"; - var file_input = document.getElementById(file_input_id); - if (!file_input) { - file_input = document.createElement('input'); - file_input.setAttribute('type', 'file'); - file_input.setAttribute('id', file_input_id); - // file_input.setAttribute('accept', '.vrm') - file_input.style.visibility = 'hidden'; - file_input.onclick = function (event) { - event.target.value = null; - }; - file_input.onchange = function (event) { - SendMessage('Canvas', 'FileSelected', URL.createObjectURL(event.target.files[0])); - } - document.body.appendChild(file_input); - } - file_input.click(); - }, -}); \ No newline at end of file diff --git a/Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib.meta b/Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib.meta deleted file mode 100644 index ee0cd7c4f..000000000 --- a/Assets/VRM/Samples~/SimpleViewer/Plugins/OpenFile.jslib.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: 2e8941ad33d65584f8ef2f8b829a05e7 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - - first: - WebGL: WebGL - second: - enabled: 1 - settings: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs index 36ca09951..575f44556 100644 --- a/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs +++ b/Assets/VRM/Samples~/SimpleViewer/ViewerUI.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using UniGLTF; -using UniGLTF.SpringBoneJobs; using UniHumanoid; using Unity.Collections; using UnityEngine; @@ -294,8 +293,7 @@ namespace VRM.SimpleViewer private void Start() { - m_version.text = string.Format("VRMViewer {0}.{1}", - PackageVersion.MAJOR, PackageVersion.MINOR); + m_version.text = string.Format("SimpleViewer {0}", PackageVersion.VERSION); m_open.onClick.AddListener(OnOpenClicked); m_reset.onClick.AddListener(() => m_loaded?.ResetSpringbone()); diff --git a/Assets/VRM10/Samples~/VRM10Viewer/FaceCameraTarget.asset b/Assets/VRM10/Samples~/VRM10Viewer/FaceCameraTarget.asset index c1311d8e0..dc5b55f8e 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/FaceCameraTarget.asset +++ b/Assets/VRM10/Samples~/VRM10Viewer/FaceCameraTarget.asset @@ -26,6 +26,7 @@ CustomRenderTexture: m_UseDynamicScale: 0 m_BindMS: 0 m_EnableCompatibleFormat: 1 + m_EnableRandomWrite: 0 m_TextureSettings: serializedVersion: 2 m_FilterMode: 1 diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs index 5dbc28055..cba67b0ab 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs @@ -1,8 +1,11 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading; +using System.Threading.Tasks; using UniGLTF; using UniGLTF.SpringBoneJobs.Blittables; using UnityEngine; @@ -474,8 +477,7 @@ namespace UniVRM10.VRM10Viewer m_autoBlink = gameObject.AddComponent(); m_autoLipsync = gameObject.AddComponent(); - m_version.text = string.Format("VRMViewer {0}.{1}", - VRM10SpecVersion.MAJOR, VRM10SpecVersion.MINOR); + m_version.text = string.Format("VRM10ViewerUI {0}", PackageVersion.VERSION); m_openModel.onClick.AddListener(OnOpenModelClicked); m_openMotion.onClick.AddListener(OnOpenMotionClicked); @@ -491,7 +493,7 @@ namespace UniVRM10.VRM10Viewer if (ArgumentChecker.TryGetFirstLoadable(out var cmd)) { - LoadModel(cmd); + var _ = LoadModel(cmd); } m_texts.Start(); @@ -502,7 +504,6 @@ namespace UniVRM10.VRM10Viewer _cancellationTokenSource?.Dispose(); } - private void Update() { if (Input.GetKeyDown(KeyCode.Tab)) @@ -639,15 +640,29 @@ namespace UniVRM10.VRM10Viewer } } - void OnOpenModelClicked() + [DllImport("__Internal")] + public static extern void WebGLFileDialog(string target, string message); + + string FileDialog() { #if UNITY_STANDALONE_WIN - var path = VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); + return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); +#elif UNITY_WEBGL + // Open WebGLFileDialog + // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib + WebGLFileDialog("Canvas", "FileSelected"); + // Control flow does not return here. return empty string with dummy + return null; #elif UNITY_EDITOR - var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); + return UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm"); #else - var path = Application.dataPath + "/default.vrm"; + return Application.dataPath + "/default.vrm"; #endif + } + + void OnOpenModelClicked() + { + var path = FileDialog(); if (string.IsNullOrEmpty(path)) { return; @@ -660,7 +675,24 @@ namespace UniVRM10.VRM10Viewer return; } - LoadModel(path); + _ = LoadModel(path); + } + + /// + /// for WebGL + /// call from OpenFile.jslib + /// + public void FileSelected(string url) + { + Debug.Log($"FileSelected: {url}"); + StartCoroutine(LoadCoroutine(url)); + } + + IEnumerator LoadCoroutine(string url) + { + var www = new WWW(url); + yield return www; + var _ = LoadModel("WebGL.vrm", www.bytes); } async void OnOpenMotionClicked() @@ -760,7 +792,29 @@ namespace UniVRM10.VRM10Viewer } } - async void LoadModel(string path) + IAwaitCaller GetIAwaitCaller() + { + if (m_useAsync) + { +#if UNITY_WEBGL + return new RuntimeOnlyNoThreadAwaitCaller(); +#else + return new RuntimeOnlyAwaitCaller(); +#endif + } + else + { + return new ImmediateCaller(); + } + } + + async Task LoadModel(string path) + { + var bytes = await File.ReadAllBytesAsync(path); + await LoadModel(path, bytes); + } + + async Task LoadModel(string path, byte[] bytes) { // cleanup m_loaded?.Dispose(); @@ -772,10 +826,10 @@ namespace UniVRM10.VRM10Viewer try { Debug.LogFormat("{0}", path); - var vrm10Instance = await Vrm10.LoadPathAsync(path, + var vrm10Instance = await Vrm10.LoadBytesAsync(bytes, canLoadVrm0X: true, showMeshes: false, - awaitCaller: m_useAsync.enabled ? new RuntimeOnlyAwaitCaller() : new ImmediateCaller(), + awaitCaller: GetIAwaitCaller(), vrmMetaInformationCallback: m_texts.UpdateMeta, ct: cancellationToken, springboneRuntime: m_useSpringboneSingelton.isOn ? new Vrm10FastSpringboneRuntime() : new Vrm10FastSpringboneRuntimeStandalone()); From 51797e08e2555cdc29b21593347f2b534ff16695 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Jan 2025 16:16:06 +0900 Subject: [PATCH 06/10] github action --- .github/workflows/build-webgl.yml | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/build-webgl.yml diff --git a/.github/workflows/build-webgl.yml b/.github/workflows/build-webgl.yml new file mode 100644 index 000000000..a526bb476 --- /dev/null +++ b/.github/workflows/build-webgl.yml @@ -0,0 +1,79 @@ +name: Create UnityPackage + +on: + workflow_dispatch: + +env: + UNITY_PROJECT_PATH: . + +defaults: + run: + shell: bash + +jobs: + create-unitypackage: + runs-on: [self-hosted, Windows, X64, Unity] + timeout-minutes: 60 + steps: + - id: checkout + uses: actions/checkout@v4 + with: + submodules: recursive + lfs: true + + - name: Detect Unity Version + id: detect-unity-version + run: | + PROJECT_VERSION_PATH="${{ env.UNITY_PROJECT_PATH }}/ProjectSettings/ProjectVersion.txt" + UNITY_HUB="C:\Program Files\Unity Hub\Unity Hub.exe" + + UNITY_VERSION=`cat ${PROJECT_VERSION_PATH} | sed -n -E "s/^m_EditorVersion:\s+//p" | head -n 1` + UNITY_CHANGESET=`cat ${PROJECT_VERSION_PATH} | sed -n -E "s/^m_EditorVersionWithRevision:\s+\S+\s+\((\S+)\)/\1/p" | head -n 1` + UNITY_EDITOR_EXECUTABLE=`"${UNITY_HUB}" -- --headless editors --installed | \ + sed -n -E "s/^${UNITY_VERSION} , installed at //p" | \ + head -n 1` + + if [ -z "${UNITY_EDITOR_EXECUTABLE}" ]; then + echo "Unity ${UNITY_VERSION} is not installed." + exit 1 + + # コマンドラインからのインストールは Unity 3.7.0 時点では UAC 必須で難しい + UNITY_INSTALL_COMMAND="\"${UNITY_HUB}\" -- --headless install \ + --version ${UNITY_VERSION} \ + --changeset ${UNITY_CHANGESET} \ + --module windows-il2cpp \ + --childModules" + fi + + echo "${UNITY_EDITOR_EXECUTABLE} is installed." + echo "unity-editor-executable=${UNITY_EDITOR_EXECUTABLE}" >> "${GITHUB_OUTPUT}" + + - name: Buidl WebGL + id: build-webgl + run: | + # build to Build/SimpleViewer + "${{ steps.detect-unity-version.outputs.unity-editor-executable }}" \ + -batchmode \ + -silent-crashes \ + -projectPath "${{ env.UNITY_PROJECT_PATH }}" \ + -executeMethod "VRM.BuildClass.BuildWebGL_SimpleViewer" \ + -logFile create-webgl.log + echo "Success to create BuildWebGL." + + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: Build + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: build + runs-on: ubuntu-latest + name: Deploy + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 From dc3d4067574e328249ca39d7c0af544d3d8533d6 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Jan 2025 16:21:59 +0900 Subject: [PATCH 07/10] permission --- .github/workflows/build-webgl.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-webgl.yml b/.github/workflows/build-webgl.yml index a526bb476..527d2377a 100644 --- a/.github/workflows/build-webgl.yml +++ b/.github/workflows/build-webgl.yml @@ -10,6 +10,11 @@ defaults: run: shell: bash +permissions: + contents: read + pages: write + id-token: write + jobs: create-unitypackage: runs-on: [self-hosted, Windows, X64, Unity] From e48867cfeac69d2cd9f9a5de90d64da8f0e31c33 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Jan 2025 17:05:53 +0900 Subject: [PATCH 08/10] WebGLFileDialog to UniVRM_Sample_WebGLFileDialog --- Assets/UniGLTF/Editor/Plugins.meta | 8 ++++++++ .../{Runtime/Utils => Editor}/Plugins/OpenFile.jslib | 4 ++-- .../{Runtime/Utils => Editor}/Plugins/OpenFile.jslib.meta | 0 Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs | 4 ++-- Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs | 4 ++-- Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs | 6 +++--- Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs | 6 +++--- Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs | 4 ++-- Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs | 4 ++-- 9 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 Assets/UniGLTF/Editor/Plugins.meta rename Assets/UniGLTF/{Runtime/Utils => Editor}/Plugins/OpenFile.jslib (92%) rename Assets/UniGLTF/{Runtime/Utils => Editor}/Plugins/OpenFile.jslib.meta (100%) diff --git a/Assets/UniGLTF/Editor/Plugins.meta b/Assets/UniGLTF/Editor/Plugins.meta new file mode 100644 index 000000000..7e020264f --- /dev/null +++ b/Assets/UniGLTF/Editor/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a75c9f76297d99041bdf9ca2458d12bb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib b/Assets/UniGLTF/Editor/Plugins/OpenFile.jslib similarity index 92% rename from Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib rename to Assets/UniGLTF/Editor/Plugins/OpenFile.jslib index 691e2af72..b754730c3 100644 --- a/Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib +++ b/Assets/UniGLTF/Editor/Plugins/OpenFile.jslib @@ -1,5 +1,5 @@ mergeInto(LibraryManager.library, { - WebGLFileDialog: function (_target, _message) { + UniVRM_Sample_WebGLFileDialog: function (_target, _message) { const target = UTF8ToString(_target); const message = UTF8ToString(_message); const file_input_id = "file-input"; @@ -20,4 +20,4 @@ mergeInto(LibraryManager.library, { } file_input.click(); }, -}); \ No newline at end of file +}); diff --git a/Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib.meta b/Assets/UniGLTF/Editor/Plugins/OpenFile.jslib.meta similarity index 100% rename from Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib.meta rename to Assets/UniGLTF/Editor/Plugins/OpenFile.jslib.meta diff --git a/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs index 1aa1bda9d..cff558d35 100644 --- a/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs +++ b/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs @@ -7,9 +7,9 @@ namespace VRM.SimpleViewer #if UNITY_STANDALONE_WIN return FileDialogForWindows.FileDialog(title, extensions); #elif UNITY_WEBGL - // Open WebGLFileDialog + // Open UniVRM_Sample_WebGLFileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - WebGLUtil.WebGLFileDialog("Canvas", "FileSelected"); + WebGLUtil.UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return ""; #elif UNITY_EDITOR diff --git a/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs b/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs index eaf48866d..26f751433 100644 --- a/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs +++ b/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs @@ -6,7 +6,7 @@ namespace VRM.SimpleViewer public static class WebGLUtil { [DllImport("__Internal")] - public static extern void WebGLFileDialog(string target, string message); + public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); } } -#endif \ No newline at end of file +#endif diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs index cba67b0ab..857fe6832 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs @@ -641,16 +641,16 @@ namespace UniVRM10.VRM10Viewer } [DllImport("__Internal")] - public static extern void WebGLFileDialog(string target, string message); + public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); string FileDialog() { #if UNITY_STANDALONE_WIN return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); #elif UNITY_WEBGL - // Open WebGLFileDialog + // Open UniVRM_Sample_WebGLFileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - WebGLFileDialog("Canvas", "FileSelected"); + UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return null; #elif UNITY_EDITOR diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index cba67b0ab..857fe6832 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -641,16 +641,16 @@ namespace UniVRM10.VRM10Viewer } [DllImport("__Internal")] - public static extern void WebGLFileDialog(string target, string message); + public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); string FileDialog() { #if UNITY_STANDALONE_WIN return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); #elif UNITY_WEBGL - // Open WebGLFileDialog + // Open UniVRM_Sample_WebGLFileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - WebGLFileDialog("Canvas", "FileSelected"); + UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return null; #elif UNITY_EDITOR diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs index 1aa1bda9d..cff558d35 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs @@ -7,9 +7,9 @@ namespace VRM.SimpleViewer #if UNITY_STANDALONE_WIN return FileDialogForWindows.FileDialog(title, extensions); #elif UNITY_WEBGL - // Open WebGLFileDialog + // Open UniVRM_Sample_WebGLFileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - WebGLUtil.WebGLFileDialog("Canvas", "FileSelected"); + WebGLUtil.UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return ""; #elif UNITY_EDITOR diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs index eaf48866d..26f751433 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs @@ -6,7 +6,7 @@ namespace VRM.SimpleViewer public static class WebGLUtil { [DllImport("__Internal")] - public static extern void WebGLFileDialog(string target, string message); + public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); } } -#endif \ No newline at end of file +#endif From 65362387220bee4bb2cc02b8cf6799f35d7dc90f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 27 Jan 2025 19:34:28 +0900 Subject: [PATCH 09/10] jslib --- .vscode/settings.json | 5 ++- .../SimpleViewer/FileDialog/FileUtil.cs | 4 +-- .../SimpleViewer/FileDialog/WebGLUtil.cs | 2 +- Assets/VRM/Samples~/SimpleViewer/Plugins.meta | 8 +++++ .../Plugins/WebGL_VRM0X_SimpleViewer.jslib | 23 +++++++++++++ .../WebGL_VRM0X_SimpleViewer.jslib.meta | 32 +++++++++++++++++++ .../Samples~/VRM10Viewer}/Plugins.meta | 0 .../Plugins/WebGL_VRM10_VRM10Viewer.jslib} | 2 +- .../WebGL_VRM10_VRM10Viewer.jslib.meta} | 0 .../Samples~/VRM10Viewer/VRM10ViewerUI.cs | 6 ++-- Assets/VRM10_Samples/VRM10Viewer/Plugins.meta | 8 +++++ .../Plugins/WebGL_VRM10_VRM10Viewer.jslib | 23 +++++++++++++ .../WebGL_VRM10_VRM10Viewer.jslib.meta | 32 +++++++++++++++++++ .../VRM10Viewer/VRM10ViewerUI.cs | 6 ++-- .../SimpleViewer/FileDialog/FileUtil.cs | 4 +-- .../SimpleViewer/FileDialog/WebGLUtil.cs | 2 +- Assets/VRM_Samples/SimpleViewer/Plugins.meta | 8 +++++ .../Plugins/WebGL_VRM0X_SimpleViewer.jslib | 23 +++++++++++++ .../WebGL_VRM0X_SimpleViewer.jslib.meta | 32 +++++++++++++++++++ 19 files changed, 206 insertions(+), 14 deletions(-) create mode 100644 Assets/VRM/Samples~/SimpleViewer/Plugins.meta create mode 100644 Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib create mode 100644 Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta rename Assets/{UniGLTF/Editor => VRM10/Samples~/VRM10Viewer}/Plugins.meta (100%) rename Assets/{UniGLTF/Editor/Plugins/OpenFile.jslib => VRM10/Samples~/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib} (92%) rename Assets/{UniGLTF/Editor/Plugins/OpenFile.jslib.meta => VRM10/Samples~/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib.meta} (100%) create mode 100644 Assets/VRM10_Samples/VRM10Viewer/Plugins.meta create mode 100644 Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib create mode 100644 Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib.meta create mode 100644 Assets/VRM_Samples/SimpleViewer/Plugins.meta create mode 100644 Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib create mode 100644 Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta diff --git a/.vscode/settings.json b/.vscode/settings.json index 622fb688b..2bd897499 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -56,5 +56,8 @@ "Scriptable", "UNIVRM" ], - "dotnet.defaultSolution": "UniVRM.sln" + "dotnet.defaultSolution": "UniVRM.sln", + "files.associations": { + "*.jslib": "javascript", + } } \ No newline at end of file diff --git a/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs index cff558d35..49455fc6c 100644 --- a/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs +++ b/Assets/VRM/Samples~/SimpleViewer/FileDialog/FileUtil.cs @@ -7,9 +7,9 @@ namespace VRM.SimpleViewer #if UNITY_STANDALONE_WIN return FileDialogForWindows.FileDialog(title, extensions); #elif UNITY_WEBGL - // Open UniVRM_Sample_WebGLFileDialog + // Open WebGL_VRM0X_SimpleViewer_FileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - WebGLUtil.UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); + WebGLUtil.WebGL_VRM0X_SimpleViewer_FileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return ""; #elif UNITY_EDITOR diff --git a/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs b/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs index 26f751433..06dea7b71 100644 --- a/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs +++ b/Assets/VRM/Samples~/SimpleViewer/FileDialog/WebGLUtil.cs @@ -6,7 +6,7 @@ namespace VRM.SimpleViewer public static class WebGLUtil { [DllImport("__Internal")] - public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); + public static extern void WebGL_VRM0X_SimpleViewer_FileDialog(string target, string message); } } #endif diff --git a/Assets/VRM/Samples~/SimpleViewer/Plugins.meta b/Assets/VRM/Samples~/SimpleViewer/Plugins.meta new file mode 100644 index 000000000..7c4d5035c --- /dev/null +++ b/Assets/VRM/Samples~/SimpleViewer/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 453de3a4f46d44d4087a1fca730e04d5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib b/Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib new file mode 100644 index 000000000..11c9321aa --- /dev/null +++ b/Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib @@ -0,0 +1,23 @@ +mergeInto(LibraryManager.library, { + WebGL_VRM0X_SimpleViewer_FileDialog: function (_target, _message) { + const target = UTF8ToString(_target); + const message = UTF8ToString(_message); + const file_input_id = "file-input"; + var file_input = document.getElementById(file_input_id); + if (!file_input) { + file_input = document.createElement('input'); + file_input.setAttribute('type', 'file'); + file_input.setAttribute('id', file_input_id); + file_input.style.visibility = 'hidden'; + file_input.onclick = function (event) { + event.target.value = null; + }; + file_input.onchange = function (event) { + console.log('SendMessage', target, message); + SendMessage(target, message, URL.createObjectURL(event.target.files[0])); + } + document.body.appendChild(file_input); + } + file_input.click(); + }, +}); diff --git a/Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta b/Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta new file mode 100644 index 000000000..d1ccd5cd3 --- /dev/null +++ b/Assets/VRM/Samples~/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: ef25d97dc58954a4ca17b4173225e58f +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + WebGL: WebGL + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/Plugins.meta b/Assets/VRM10/Samples~/VRM10Viewer/Plugins.meta similarity index 100% rename from Assets/UniGLTF/Editor/Plugins.meta rename to Assets/VRM10/Samples~/VRM10Viewer/Plugins.meta diff --git a/Assets/UniGLTF/Editor/Plugins/OpenFile.jslib b/Assets/VRM10/Samples~/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib similarity index 92% rename from Assets/UniGLTF/Editor/Plugins/OpenFile.jslib rename to Assets/VRM10/Samples~/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib index b754730c3..1a0cb627b 100644 --- a/Assets/UniGLTF/Editor/Plugins/OpenFile.jslib +++ b/Assets/VRM10/Samples~/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib @@ -1,5 +1,5 @@ mergeInto(LibraryManager.library, { - UniVRM_Sample_WebGLFileDialog: function (_target, _message) { + WebGL_VRM10_VRM10Viewer_FileDialog: function (_target, _message) { const target = UTF8ToString(_target); const message = UTF8ToString(_message); const file_input_id = "file-input"; diff --git a/Assets/UniGLTF/Editor/Plugins/OpenFile.jslib.meta b/Assets/VRM10/Samples~/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib.meta similarity index 100% rename from Assets/UniGLTF/Editor/Plugins/OpenFile.jslib.meta rename to Assets/VRM10/Samples~/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib.meta diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs index 857fe6832..cd788bb7a 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10/Samples~/VRM10Viewer/VRM10ViewerUI.cs @@ -641,16 +641,16 @@ namespace UniVRM10.VRM10Viewer } [DllImport("__Internal")] - public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); + public static extern void WebGL_VRM10_VRM10Viewer_FileDialog(string target, string message); string FileDialog() { #if UNITY_STANDALONE_WIN return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); #elif UNITY_WEBGL - // Open UniVRM_Sample_WebGLFileDialog + // Open WebGL_VRM10_VRM10Viewer_FileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); + WebGL_VRM10_VRM10Viewer_FileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return null; #elif UNITY_EDITOR diff --git a/Assets/VRM10_Samples/VRM10Viewer/Plugins.meta b/Assets/VRM10_Samples/VRM10Viewer/Plugins.meta new file mode 100644 index 000000000..7e020264f --- /dev/null +++ b/Assets/VRM10_Samples/VRM10Viewer/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a75c9f76297d99041bdf9ca2458d12bb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib b/Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib new file mode 100644 index 000000000..1a0cb627b --- /dev/null +++ b/Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib @@ -0,0 +1,23 @@ +mergeInto(LibraryManager.library, { + WebGL_VRM10_VRM10Viewer_FileDialog: function (_target, _message) { + const target = UTF8ToString(_target); + const message = UTF8ToString(_message); + const file_input_id = "file-input"; + var file_input = document.getElementById(file_input_id); + if (!file_input) { + file_input = document.createElement('input'); + file_input.setAttribute('type', 'file'); + file_input.setAttribute('id', file_input_id); + file_input.style.visibility = 'hidden'; + file_input.onclick = function (event) { + event.target.value = null; + }; + file_input.onchange = function (event) { + console.log('SendMessage', target, message); + SendMessage(target, message, URL.createObjectURL(event.target.files[0])); + } + document.body.appendChild(file_input); + } + file_input.click(); + }, +}); diff --git a/Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib.meta b/Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib.meta new file mode 100644 index 000000000..ee0cd7c4f --- /dev/null +++ b/Assets/VRM10_Samples/VRM10Viewer/Plugins/WebGL_VRM10_VRM10Viewer.jslib.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 2e8941ad33d65584f8ef2f8b829a05e7 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + WebGL: WebGL + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index 857fe6832..cd788bb7a 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -641,16 +641,16 @@ namespace UniVRM10.VRM10Viewer } [DllImport("__Internal")] - public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); + public static extern void WebGL_VRM10_VRM10Viewer_FileDialog(string target, string message); string FileDialog() { #if UNITY_STANDALONE_WIN return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm"); #elif UNITY_WEBGL - // Open UniVRM_Sample_WebGLFileDialog + // Open WebGL_VRM10_VRM10Viewer_FileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); + WebGL_VRM10_VRM10Viewer_FileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return null; #elif UNITY_EDITOR diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs index cff558d35..49455fc6c 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/FileUtil.cs @@ -7,9 +7,9 @@ namespace VRM.SimpleViewer #if UNITY_STANDALONE_WIN return FileDialogForWindows.FileDialog(title, extensions); #elif UNITY_WEBGL - // Open UniVRM_Sample_WebGLFileDialog + // Open WebGL_VRM0X_SimpleViewer_FileDialog // see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib - WebGLUtil.UniVRM_Sample_WebGLFileDialog("Canvas", "FileSelected"); + WebGLUtil.WebGL_VRM0X_SimpleViewer_FileDialog("Canvas", "FileSelected"); // Control flow does not return here. return empty string with dummy return ""; #elif UNITY_EDITOR diff --git a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs index 26f751433..06dea7b71 100644 --- a/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs +++ b/Assets/VRM_Samples/SimpleViewer/FileDialog/WebGLUtil.cs @@ -6,7 +6,7 @@ namespace VRM.SimpleViewer public static class WebGLUtil { [DllImport("__Internal")] - public static extern void UniVRM_Sample_WebGLFileDialog(string target, string message); + public static extern void WebGL_VRM0X_SimpleViewer_FileDialog(string target, string message); } } #endif diff --git a/Assets/VRM_Samples/SimpleViewer/Plugins.meta b/Assets/VRM_Samples/SimpleViewer/Plugins.meta new file mode 100644 index 000000000..7c4d5035c --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 453de3a4f46d44d4087a1fca730e04d5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib b/Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib new file mode 100644 index 000000000..11c9321aa --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib @@ -0,0 +1,23 @@ +mergeInto(LibraryManager.library, { + WebGL_VRM0X_SimpleViewer_FileDialog: function (_target, _message) { + const target = UTF8ToString(_target); + const message = UTF8ToString(_message); + const file_input_id = "file-input"; + var file_input = document.getElementById(file_input_id); + if (!file_input) { + file_input = document.createElement('input'); + file_input.setAttribute('type', 'file'); + file_input.setAttribute('id', file_input_id); + file_input.style.visibility = 'hidden'; + file_input.onclick = function (event) { + event.target.value = null; + }; + file_input.onchange = function (event) { + console.log('SendMessage', target, message); + SendMessage(target, message, URL.createObjectURL(event.target.files[0])); + } + document.body.appendChild(file_input); + } + file_input.click(); + }, +}); diff --git a/Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta b/Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta new file mode 100644 index 000000000..d1ccd5cd3 --- /dev/null +++ b/Assets/VRM_Samples/SimpleViewer/Plugins/WebGL_VRM0X_SimpleViewer.jslib.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: ef25d97dc58954a4ca17b4173225e58f +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + WebGL: WebGL + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: From b19222ba1ea60867184174760c78ed72a5afd484 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 28 Jan 2025 12:52:46 +0900 Subject: [PATCH 10/10] remove meta --- Assets/UniGLTF/Runtime/Utils/Plugins.meta | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Assets/UniGLTF/Runtime/Utils/Plugins.meta diff --git a/Assets/UniGLTF/Runtime/Utils/Plugins.meta b/Assets/UniGLTF/Runtime/Utils/Plugins.meta deleted file mode 100644 index fdecce026..000000000 --- a/Assets/UniGLTF/Runtime/Utils/Plugins.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ccb1849bc34bcd740ba2e17462125200 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: