From 1ce8faa10313ee9b33564b22a1cd7f5a4f00843c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 7 Mar 2025 20:23:43 +0900 Subject: [PATCH] ArgumentChecker.cs --- .../VRM10Viewer/UI/ArgumentChecker.cs | 62 +++++ .../VRM10Viewer/UI/ArgumentChecker.cs.meta | 11 + .../VRM10Viewer/UI/MainView.uxml | 12 + .../VRM10Viewer/UI/VRM10MainView.cs | 218 +++++++++++++++++- .../VRM10Viewer/UI/VRM10ViewerUI.cs | 57 ----- .../VRM10Viewer/VRM10Viewer.unity | 22 ++ 6 files changed, 322 insertions(+), 60 deletions(-) create mode 100644 Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs create mode 100644 Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs.meta diff --git a/Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs b/Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs new file mode 100644 index 000000000..7d533e5ab --- /dev/null +++ b/Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs @@ -0,0 +1,62 @@ +using System.IO; +using System.Linq; +using UnityEngine; + + +namespace UniVRM10.VRM10Viewer +{ + static class ArgumentChecker + { + static string[] Supported = { + ".gltf", + ".glb", + ".vrm", + ".zip", + }; + + static string UnityHubPath => System.Environment.GetEnvironmentVariable("ProgramFiles") + "\\Unity\\Hub"; + + public static bool IsLoadable(string path) + { + if (!File.Exists(path)) + { + // not exists + return false; + } + + if (Application.isEditor) + { + // skip editor argument + // {UnityHub_Resources}\PackageManager\ProjectTemplates\com.unity.template.3d-5.0.4.tgz + if (path.StartsWith(UnityHubPath)) + { + return false; + } + } + + var ext = Path.GetExtension(path).ToLower(); + if (!Supported.Contains(ext)) + { + // unknown extension + return false; + } + + return true; + } + + public static bool TryGetFirstLoadable(out string cmd) + { + foreach (var arg in System.Environment.GetCommandLineArgs()) + { + if (ArgumentChecker.IsLoadable(arg)) + { + cmd = arg; + return true; + } + } + + cmd = default; + return false; + } + } +} \ No newline at end of file diff --git a/Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs.meta b/Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs.meta new file mode 100644 index 000000000..dd05c1821 --- /dev/null +++ b/Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 052e1c03459c30244b72f1e02ddbf420 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/VRM10Viewer/UI/MainView.uxml b/Assets/VRM10_Samples/VRM10Viewer/UI/MainView.uxml index dbc9babe5..bd879d600 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/UI/MainView.uxml +++ b/Assets/VRM10_Samples/VRM10Viewer/UI/MainView.uxml @@ -2,6 +2,18 @@ + + + + + + + + + + + + diff --git a/Assets/VRM10_Samples/VRM10Viewer/UI/VRM10MainView.cs b/Assets/VRM10_Samples/VRM10Viewer/UI/VRM10MainView.cs index 25a884a35..cd421a73c 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/UI/VRM10MainView.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/UI/VRM10MainView.cs @@ -1,12 +1,17 @@ -using System.Collections; -using System.Collections.Generic; +using UniGLTF; +using UniGLTF.SpringBoneJobs.Blittables; using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.UIElements; namespace UniVRM10.VRM10Viewer { public class VRM10MainView : MonoBehaviour { + [SerializeField] + TextAsset m_motion; + [Header("Material")] [SerializeField] Material m_pbrOpaqueMaterial = default; @@ -18,18 +23,225 @@ namespace UniVRM10.VRM10Viewer Material m_mtoonMaterialAlphaBlend = default; VRM10ViewerController m_controller; - + Toggle m_useAsync; + Toggle m_useSpringboneSingleton; + Toggle m_useCustomPbrMaterial; + Toggle m_useCustomMToonMaterial; + Toggle m_useTPose; + Slider m_springboneExternalX; + Slider m_springboneExternalY; + Slider m_springboneExternalZ; + Toggle m_useSpringbonePause; + Toggle m_useSpringboneScaling; void OnEnable() { m_controller = new VRM10ViewerController( (m_mtoonMaterialOpaque != null && m_mtoonMaterialAlphaBlend != null) ? new TinyMToonrMaterialImporter(m_mtoonMaterialOpaque, m_mtoonMaterialAlphaBlend) : null, (m_pbrOpaqueMaterial != null && m_pbrAlphaBlendMaterial != null) ? new TinyPbrMaterialImporter(m_pbrOpaqueMaterial, m_pbrAlphaBlendMaterial) : null ); + // m_controller.OnUpdateMeta += UpdateMeta; + m_controller.OnLoaded += OnLoaded; + + // The UXML is already instantiated by the UIDocument component + var uiDocument = GetComponent(); + var root = uiDocument.rootVisualElement; + + var openModelButton = root.Q