mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-10 21:09:08 -05:00
ArgumentChecker.cs
This commit is contained in:
62
Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs
Normal file
62
Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs.meta
Normal file
11
Assets/VRM10_Samples/VRM10Viewer/UI/ArgumentChecker.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 052e1c03459c30244b72f1e02ddbf420
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -2,6 +2,18 @@
|
||||
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
|
||||
<ui:VisualElement name="left" style="flex-grow: 0; min-width: 200px; background-color: rgba(255, 255, 255, 0.35);">
|
||||
<ui:Button text="Open Model" parse-escape-sequences="true" display-tooltip-when-elided="true" name="OpenModel" />
|
||||
<ui:Toggle label="Use Async" name="UseAsync" style="flex-direction: row-reverse;" />
|
||||
<ui:Label tabindex="-1" text="SpringBone" parse-escape-sequences="true" display-tooltip-when-elided="true" style="-unity-font-style: bold;" />
|
||||
<ui:Toggle label="Singelton" name="UseSpringboneSingleton" style="flex-direction: row-reverse;" />
|
||||
<ui:Toggle label="Use CustomMToonMaterial" name="UseCustomMToonMaterial" style="flex-direction: row-reverse;" />
|
||||
<ui:Toggle label="Use CustomPbrMaterial" name="UseCustomPbrMaterial" value="true" style="flex-direction: row-reverse;" />
|
||||
<ui:Label tabindex="-1" text="Motion" parse-escape-sequences="true" display-tooltip-when-elided="true" style="-unity-font-style: bold;" />
|
||||
<ui:Toggle label="T-Pose" name="UseTPose" style="flex-direction: row-reverse;" />
|
||||
<ui:Slider label="ExternalX" high-value="10" name="SpringboneExternalX" />
|
||||
<ui:Slider label="ExternalY" high-value="10" name="SpringboneExternalY" />
|
||||
<ui:Slider label="ExternalZ" high-value="10" name="SpringboneExternalZ" />
|
||||
<ui:Toggle label="Pause" name="UeSpringbonePause" />
|
||||
<ui:Toggle label="Support Scaling" name="UseSpringboneScaling" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="right" style="flex-grow: 1;" />
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -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<UIDocument>();
|
||||
var root = uiDocument.rootVisualElement;
|
||||
|
||||
var openModelButton = root.Q<Button>("OpenModel");
|
||||
openModelButton.clicked += () =>
|
||||
{
|
||||
m_controller.OnOpenModelClicked(MakeLoadOptions());
|
||||
};
|
||||
m_useAsync = root.Q<Toggle>("UseAsync");
|
||||
m_useSpringboneSingleton = root.Q<Toggle>("UseSpringboneSingleton");
|
||||
m_useCustomPbrMaterial = root.Q<Toggle>("UseCustomPbrMaterial");
|
||||
m_useCustomMToonMaterial = root.Q<Toggle>("UseCustomMToonMaterial");
|
||||
// URP かつ WebGL で有効にする
|
||||
m_useCustomMToonMaterial.value = Application.platform == RuntimePlatform.WebGLPlayer && GraphicsSettings.renderPipelineAsset != null;
|
||||
m_useTPose = root.Q<Toggle>("UseTPose");
|
||||
m_springboneExternalX = root.Q<Slider>("SpringboneExternalX");
|
||||
m_springboneExternalY = root.Q<Slider>("SpringboneExternalY");
|
||||
m_springboneExternalZ = root.Q<Slider>("SpringboneExternalZ");
|
||||
m_useSpringbonePause = root.Q<Toggle>("UeSpringbonePause");
|
||||
m_useSpringboneScaling = root.Q<Toggle>("UseSpringboneScaling");
|
||||
|
||||
// m_autoEmotion = gameObject.AddComponent<VRM10AutoExpression>();
|
||||
// m_autoBlink = gameObject.AddComponent<VRM10Blinker>();
|
||||
// m_autoLipsync = gameObject.AddComponent<VRM10AIUEO>();
|
||||
|
||||
// m_version.text = string.Format("VRM10ViewerUI {0}", PackageVersion.VERSION);
|
||||
|
||||
// m_openModel.onClick.AddListener(() => m_controller.OnOpenModelClicked(MakeLoadOptions()));
|
||||
// m_openMotion.onClick.AddListener(m_controller.OnOpenMotionClicked);
|
||||
// m_pastePose.onClick.AddListener(m_controller.OnPastePoseClicked);
|
||||
// m_resetSpringBone.onClick.AddListener(m_controller.OnResetSpringBoneClicked);
|
||||
// m_reconstructSpringBone.onClick.AddListener(m_controller.OnReconstructSpringBoneClicked);
|
||||
|
||||
// load initial bvh
|
||||
if (m_motion != null)
|
||||
{
|
||||
m_controller.Motion = BvhMotion.LoadBvhFromText(m_motion.text);
|
||||
if (GraphicsSettings.renderPipelineAsset != null
|
||||
&& m_pbrAlphaBlendMaterial != null)
|
||||
{
|
||||
m_controller.Motion.SetBoxManMaterial(Instantiate(m_pbrOpaqueMaterial));
|
||||
}
|
||||
}
|
||||
|
||||
if (ArgumentChecker.TryGetFirstLoadable(out var cmd))
|
||||
{
|
||||
var _ = m_controller.LoadModelPath(cmd, MakeLoadOptions());
|
||||
}
|
||||
|
||||
// m_texts.Start();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
m_controller.Dispose();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab))
|
||||
{
|
||||
// if (Root != null) Root.SetActive(!Root.activeSelf);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
m_controller.Cancel();
|
||||
}
|
||||
|
||||
// m_controller.ShowBoxMan(m_showBoxMan.isOn);
|
||||
if (m_controller.TryUpdate(
|
||||
m_useTPose.value,
|
||||
new BlittableModelLevel
|
||||
{
|
||||
ExternalForce = new Vector3(m_springboneExternalX.value, m_springboneExternalY.value, m_springboneExternalZ.value),
|
||||
StopSpringBoneWriteback = m_useSpringbonePause.value,
|
||||
SupportsScalingAtRuntime = m_useSpringboneScaling.value,
|
||||
},
|
||||
out var loaded
|
||||
))
|
||||
{
|
||||
// m_happy.ApplyRuntime(loaded.Instance.Vrm.Expression.Happy);
|
||||
// m_angry.ApplyRuntime(loaded.Instance.Vrm.Expression.Angry);
|
||||
// m_sad.ApplyRuntime(loaded.Instance.Vrm.Expression.Sad);
|
||||
// m_relaxed.ApplyRuntime(loaded.Instance.Vrm.Expression.Relaxed);
|
||||
// m_surprised.ApplyRuntime(loaded.Instance.Vrm.Expression.Surprised);
|
||||
// m_lipAa.ApplyRuntime(loaded.Instance.Vrm.Expression.Aa);
|
||||
// m_lipIh.ApplyRuntime(loaded.Instance.Vrm.Expression.Ih);
|
||||
// m_lipOu.ApplyRuntime(loaded.Instance.Vrm.Expression.Ou);
|
||||
// m_lipEe.ApplyRuntime(loaded.Instance.Vrm.Expression.Ee);
|
||||
// m_lipOh.ApplyRuntime(loaded.Instance.Vrm.Expression.Oh);
|
||||
// m_blink.ApplyRuntime(loaded.Instance.Vrm.Expression.Blink);
|
||||
|
||||
// var vrm = loaded.Instance;
|
||||
// if (m_enableAutoExpression.isOn)
|
||||
// {
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Happy, m_autoEmotion.Happy);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Angry, m_autoEmotion.Angry);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Sad, m_autoEmotion.Sad);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Relaxed, m_autoEmotion.Relaxed);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Surprised, m_autoEmotion.Surprised);
|
||||
// m_happy.m_expression.SetValueWithoutNotify(m_autoEmotion.Happy);
|
||||
// m_angry.m_expression.SetValueWithoutNotify(m_autoEmotion.Angry);
|
||||
// m_sad.m_expression.SetValueWithoutNotify(m_autoEmotion.Sad);
|
||||
// m_relaxed.m_expression.SetValueWithoutNotify(m_autoEmotion.Relaxed);
|
||||
// m_surprised.m_expression.SetValueWithoutNotify(m_autoEmotion.Surprised);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Happy, m_happy.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Angry, m_angry.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Sad, m_sad.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Relaxed, m_relaxed.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Surprised, m_surprised.m_expression.value);
|
||||
// }
|
||||
|
||||
// if (m_enableLipSync.isOn)
|
||||
// {
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Aa, m_autoLipsync.Aa);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Ih, m_autoLipsync.Ih);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Ou, m_autoLipsync.Ou);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Ee, m_autoLipsync.Ee);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Oh, m_autoLipsync.Oh);
|
||||
// m_lipAa.m_expression.SetValueWithoutNotify(m_autoLipsync.Aa);
|
||||
// m_lipIh.m_expression.SetValueWithoutNotify(m_autoLipsync.Ih);
|
||||
// m_lipOu.m_expression.SetValueWithoutNotify(m_autoLipsync.Ou);
|
||||
// m_lipEe.m_expression.SetValueWithoutNotify(m_autoLipsync.Ee);
|
||||
// m_lipOh.m_expression.SetValueWithoutNotify(m_autoLipsync.Oh);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Aa, m_lipAa.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Ih, m_lipIh.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Ou, m_lipOu.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Ee, m_lipEe.m_expression.value);
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Oh, m_lipOh.m_expression.value);
|
||||
// }
|
||||
|
||||
// if (m_enableAutoBlink.isOn)
|
||||
// {
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Blink, m_autoBlink.BlinkValue);
|
||||
// m_blink.m_expression.SetValueWithoutNotify(m_autoBlink.BlinkValue);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// vrm.Runtime.Expression.SetWeight(ExpressionKey.Blink, m_blink.m_expression.value);
|
||||
// }
|
||||
|
||||
// if (m_useLookAtTarget.isOn)
|
||||
// {
|
||||
// var (yaw, pitch) = vrm.Runtime.LookAt.CalculateYawPitchFromLookAtPosition(m_lookAtTarget.transform.position);
|
||||
// vrm.Runtime.LookAt.SetYawPitchManually(yaw, pitch);
|
||||
// m_yaw.value = yaw;
|
||||
// m_pitch.value = pitch;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// vrm.Runtime.LookAt.SetYawPitchManually(m_yaw.value, m_pitch.value);
|
||||
// }
|
||||
|
||||
// if (vrm.TryGetBoneTransform(HumanBodyBones.Head, out var head))
|
||||
// {
|
||||
// var initLocarlRotation = vrm.DefaultTransformStates[head].LocalRotation;
|
||||
// var r = head.rotation * Quaternion.Inverse(initLocarlRotation);
|
||||
// var pos = head.position
|
||||
// + (r * Vector3.forward * 0.7f)
|
||||
// + (r * Vector3.up * 0.07f)
|
||||
// ;
|
||||
// m_faceCamera.position = pos;
|
||||
// m_faceCamera.rotation = r;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
LoadOptions MakeLoadOptions()
|
||||
{
|
||||
return new LoadOptions()
|
||||
{
|
||||
UseAsync = m_useAsync.value,
|
||||
UseSpringboneSingelton = m_useSpringboneSingleton.value,
|
||||
UseCustomPbrMaterial = m_useCustomPbrMaterial.value,
|
||||
UseCustomMToonMaterial = m_useCustomMToonMaterial.value,
|
||||
};
|
||||
}
|
||||
|
||||
void OnLoaded(Loaded loaded)
|
||||
{
|
||||
// m_showBoxMan.isOn = false;
|
||||
// m_happy.OnLoad(loaded.Instance.Vrm.Expression.Happy);
|
||||
// m_angry.OnLoad(loaded.Instance.Vrm.Expression.Angry);
|
||||
// m_sad.OnLoad(loaded.Instance.Vrm.Expression.Sad);
|
||||
// m_relaxed.OnLoad(loaded.Instance.Vrm.Expression.Relaxed);
|
||||
// m_surprised.OnLoad(loaded.Instance.Vrm.Expression.Surprised);
|
||||
// m_lipAa.OnLoad(loaded.Instance.Vrm.Expression.Aa);
|
||||
// m_lipIh.OnLoad(loaded.Instance.Vrm.Expression.Ih);
|
||||
// m_lipOu.OnLoad(loaded.Instance.Vrm.Expression.Ou);
|
||||
// m_lipEe.OnLoad(loaded.Instance.Vrm.Expression.Ee);
|
||||
// m_lipOh.OnLoad(loaded.Instance.Vrm.Expression.Oh);
|
||||
// m_blink.OnLoad(loaded.Instance.Vrm.Expression.Blink);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UniGLTF.SpringBoneJobs.Blittables;
|
||||
@@ -406,61 +404,6 @@ namespace UniVRM10.VRM10Viewer
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
VRM10ViewerController m_controller;
|
||||
VRM10AutoExpression m_autoEmotion;
|
||||
VRM10Blinker m_autoBlink;
|
||||
|
||||
@@ -4000,6 +4000,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 268016455}
|
||||
- component: {fileID: 268016454}
|
||||
- component: {fileID: 268016456}
|
||||
m_Layer: 0
|
||||
m_Name: MainView
|
||||
m_TagString: Untagged
|
||||
@@ -4039,6 +4040,27 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &268016456
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 268016453}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: ce3555915b1cabf43a72ad94373270e2, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_motion: {fileID: 4900000, guid: 08df5151e71aed748b13547492fb8b9a, type: 3}
|
||||
m_pbrOpaqueMaterial: {fileID: -876546973899608171, guid: ac58f8c11a130e04ba883a82ae4b78e4,
|
||||
type: 3}
|
||||
m_pbrAlphaBlendMaterial: {fileID: -876546973899608171, guid: 868190a58757d6242bb3ca456402f82f,
|
||||
type: 3}
|
||||
m_mtoonMaterialOpaque: {fileID: -876546973899608171, guid: fd08e80eb7e04e849b8a6d534e48efea,
|
||||
type: 3}
|
||||
m_mtoonMaterialAlphaBlend: {fileID: -876546973899608171, guid: 6b60fe85d745eda4281e3278fcb0657c,
|
||||
type: 3}
|
||||
--- !u!1 &279721863
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Reference in New Issue
Block a user