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: