mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 13:29:41 -05:00
copy Samples~ to under Assets
This commit is contained in:
74
Assets/VRM_Samples/SimpleViewer/AIUEO.cs
Normal file
74
Assets/VRM_Samples/SimpleViewer/AIUEO.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VRM.SimpleViewer
|
||||
{
|
||||
public class AIUEO : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public VRMBlendShapeProxy BlendShapes;
|
||||
private void Reset()
|
||||
{
|
||||
BlendShapes = GetComponent<VRMBlendShapeProxy>();
|
||||
}
|
||||
|
||||
Coroutine m_coroutine;
|
||||
|
||||
[SerializeField]
|
||||
float m_wait = 0.5f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (BlendShapes == null)
|
||||
{
|
||||
BlendShapes = GetComponent<VRM.VRMBlendShapeProxy>();
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator RoutineNest(BlendShapePreset preset, float velocity, float wait)
|
||||
{
|
||||
for (var value = 0.0f; value <= 1.0f; value += velocity)
|
||||
{
|
||||
BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), value);
|
||||
yield return null;
|
||||
}
|
||||
BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), 1.0f);
|
||||
yield return new WaitForSeconds(wait);
|
||||
for (var value = 1.0f; value >= 0; value -= velocity)
|
||||
{
|
||||
BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), value);
|
||||
yield return null;
|
||||
}
|
||||
BlendShapes.ImmediatelySetValue(BlendShapeKey.CreateFromPreset(preset), 0);
|
||||
yield return new WaitForSeconds(wait * 2);
|
||||
}
|
||||
|
||||
IEnumerator Routine()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
|
||||
var velocity = 0.1f;
|
||||
|
||||
yield return RoutineNest(BlendShapePreset.A, velocity, m_wait);
|
||||
yield return RoutineNest(BlendShapePreset.I, velocity, m_wait);
|
||||
yield return RoutineNest(BlendShapePreset.U, velocity, m_wait);
|
||||
yield return RoutineNest(BlendShapePreset.E, velocity, m_wait);
|
||||
yield return RoutineNest(BlendShapePreset.O, velocity, m_wait);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_coroutine = StartCoroutine(Routine());
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Debug.Log("StopCoroutine");
|
||||
StopCoroutine(m_coroutine);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM_Samples/SimpleViewer/AIUEO.cs.meta
Normal file
11
Assets/VRM_Samples/SimpleViewer/AIUEO.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7d971d3cc4439c4ba3f3ae4072cf82d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
118
Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs
Normal file
118
Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
#if UNITY_STANDALONE_WIN
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
|
||||
|
||||
namespace VRM.SimpleViewer
|
||||
{
|
||||
public static class FileDialogForWindows
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN
|
||||
#region GetOpenFileName
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public class OpenFileName
|
||||
{
|
||||
public int structSize = 0;
|
||||
public IntPtr dlgOwner = IntPtr.Zero;
|
||||
public IntPtr instance = IntPtr.Zero;
|
||||
public String filter = null;
|
||||
public String customFilter = null;
|
||||
public int maxCustFilter = 0;
|
||||
public int filterIndex = 0;
|
||||
public String file = null;
|
||||
public int maxFile = 0;
|
||||
public String fileTitle = null;
|
||||
public int maxFileTitle = 0;
|
||||
public String initialDir = null;
|
||||
public String title = null;
|
||||
public int flags = 0;
|
||||
public short fileOffset = 0;
|
||||
public short fileExtension = 0;
|
||||
public String defExt = null;
|
||||
public IntPtr custData = IntPtr.Zero;
|
||||
public IntPtr hook = IntPtr.Zero;
|
||||
public String templateName = null;
|
||||
public IntPtr reservedPtr = IntPtr.Zero;
|
||||
public int reservedInt = 0;
|
||||
public int flagsEx = 0;
|
||||
}
|
||||
|
||||
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
|
||||
/*
|
||||
public static bool GetOpenFileName1([In, Out] OpenFileName ofn)
|
||||
{
|
||||
return GetOpenFileName(ofn);
|
||||
}
|
||||
*/
|
||||
|
||||
[DllImport("Comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
private static extern bool GetSaveFileName([In, Out] OpenFileName ofn);
|
||||
|
||||
static string Filter(params string[] filters)
|
||||
{
|
||||
return string.Join("\0", filters) + "\0";
|
||||
}
|
||||
public static string FileDialog(string title, params string[] extensions)
|
||||
{
|
||||
OpenFileName ofn = new OpenFileName();
|
||||
ofn.structSize = Marshal.SizeOf(ofn);
|
||||
|
||||
var filters = new List<string>();
|
||||
filters.Add("All Files"); filters.Add("*.*");
|
||||
foreach(var ext in extensions)
|
||||
{
|
||||
filters.Add(ext); filters.Add("*" + ext);
|
||||
}
|
||||
ofn.filter = Filter(filters.ToArray());
|
||||
ofn.filterIndex = 2;
|
||||
ofn.file = new string(new char[256]);
|
||||
ofn.maxFile = ofn.file.Length;
|
||||
ofn.fileTitle = new string(new char[64]);
|
||||
ofn.maxFileTitle = ofn.fileTitle.Length;
|
||||
ofn.initialDir = UnityEngine.Application.dataPath;
|
||||
ofn.title = title;
|
||||
//ofn.defExt = "PNG";
|
||||
ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
|
||||
if (!GetOpenFileName(ofn))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ofn.file;
|
||||
}
|
||||
public static string SaveDialog(string title, string path)
|
||||
{
|
||||
var extension = Path.GetExtension(path);
|
||||
OpenFileName ofn = new OpenFileName();
|
||||
ofn.structSize = Marshal.SizeOf(ofn);
|
||||
ofn.filter = Filter("All Files", "*.*", extension, "*" + extension);
|
||||
ofn.filterIndex = 2;
|
||||
var chars = new char[256];
|
||||
var it = Path.GetFileName(path).GetEnumerator();
|
||||
for (int i = 0; i < chars.Length && it.MoveNext(); ++i)
|
||||
{
|
||||
chars[i] = it.Current;
|
||||
}
|
||||
ofn.file = new string(chars);
|
||||
ofn.maxFile = ofn.file.Length;
|
||||
ofn.fileTitle = new string(new char[64]);
|
||||
ofn.maxFileTitle = ofn.fileTitle.Length;
|
||||
ofn.initialDir = Path.GetDirectoryName(path);
|
||||
ofn.title = title;
|
||||
//ofn.defExt = "PNG";
|
||||
ofn.flags = 0x00000002 | 0x00000004; // OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
|
||||
if (!GetSaveFileName(ofn))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ofn.file;
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
}
|
||||
12
Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs.meta
Normal file
12
Assets/VRM_Samples/SimpleViewer/FileDialogForWindows.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 649d78dc96acf5b4f83d54cd1859e940
|
||||
timeCreated: 1524038001
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
142
Assets/VRM_Samples/SimpleViewer/RokuroCamera.cs
Normal file
142
Assets/VRM_Samples/SimpleViewer/RokuroCamera.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VRM.SimpleViewer
|
||||
{
|
||||
public class RokuroCamera : MonoBehaviour
|
||||
{
|
||||
[Range(0.1f, 5.0f)]
|
||||
public float RotateSpeed = 0.7f;
|
||||
|
||||
[Range(0.1f, 5.0f)]
|
||||
public float GrabSpeed = 0.7f;
|
||||
|
||||
[Range(0.1f, 5.0f)]
|
||||
public float DollySpeed = 1.0f;
|
||||
|
||||
struct PosRot
|
||||
{
|
||||
public Vector3 Position;
|
||||
public Quaternion Rotation;
|
||||
}
|
||||
|
||||
class _Rokuro
|
||||
{
|
||||
public float Yaw;
|
||||
public float Pitch;
|
||||
public float ShiftX;
|
||||
public float ShiftY;
|
||||
public float Distance = 2.0f;
|
||||
|
||||
public void Rotate(float x, float y)
|
||||
{
|
||||
Yaw += x;
|
||||
Pitch -= y;
|
||||
Pitch = Mathf.Clamp(Pitch, -90, 90);
|
||||
}
|
||||
|
||||
public void Grab(float x, float y)
|
||||
{
|
||||
ShiftX += x * Distance;
|
||||
ShiftY += y * Distance;
|
||||
}
|
||||
|
||||
public void Dolly(float delta)
|
||||
{
|
||||
if (delta > 0)
|
||||
{
|
||||
Distance *= 0.9f;
|
||||
}
|
||||
else if (delta < 0)
|
||||
{
|
||||
Distance *= 1.1f;
|
||||
}
|
||||
}
|
||||
|
||||
public PosRot Calc()
|
||||
{
|
||||
var r = Quaternion.Euler(Pitch, Yaw, 0);
|
||||
return new PosRot
|
||||
{
|
||||
Position = r * new Vector3(-ShiftX, -ShiftY, -Distance),
|
||||
Rotation = r,
|
||||
};
|
||||
}
|
||||
}
|
||||
private _Rokuro _currentCamera = new _Rokuro();
|
||||
|
||||
private List<Coroutine> _activeCoroutines = new List<Coroutine>();
|
||||
private void OnEnable()
|
||||
{
|
||||
// left mouse drag
|
||||
_activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(0, diff =>
|
||||
{
|
||||
_currentCamera.Rotate(diff.x * RotateSpeed, diff.y * RotateSpeed);
|
||||
})));
|
||||
// right mouse drag
|
||||
_activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(1, diff =>
|
||||
{
|
||||
_currentCamera.Rotate(diff.x * RotateSpeed, diff.y * RotateSpeed);
|
||||
})));
|
||||
// middle mouse drag
|
||||
_activeCoroutines.Add(StartCoroutine(MouseDragOperationCoroutine(2, diff =>
|
||||
{
|
||||
_currentCamera.Grab(
|
||||
diff.x * GrabSpeed / Screen.height,
|
||||
diff.y * GrabSpeed / Screen.height
|
||||
);
|
||||
})));
|
||||
// mouse wheel
|
||||
_activeCoroutines.Add(StartCoroutine(MouseScrollOperationCoroutine(diff =>
|
||||
{
|
||||
_currentCamera.Dolly(diff.y * DollySpeed);
|
||||
})));
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
foreach (var coroutine in _activeCoroutines)
|
||||
{
|
||||
StopCoroutine(coroutine);
|
||||
}
|
||||
_activeCoroutines.Clear();
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
var posRot = _currentCamera.Calc();
|
||||
|
||||
transform.localRotation = posRot.Rotation;
|
||||
transform.localPosition = posRot.Position;
|
||||
}
|
||||
private IEnumerator MouseDragOperationCoroutine(int buttonIndex, Action<Vector2> dragOperation)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
while (!Input.GetMouseButtonDown(buttonIndex))
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
var prevPos = Input.mousePosition;
|
||||
while (Input.GetMouseButton(buttonIndex))
|
||||
{
|
||||
var currPos = Input.mousePosition;
|
||||
var diff = currPos - prevPos;
|
||||
dragOperation(diff);
|
||||
|
||||
prevPos = currPos;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
private IEnumerator MouseScrollOperationCoroutine(Action<Vector2> scrollOperation)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
scrollOperation(Input.mouseScrollDelta);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/VRM_Samples/SimpleViewer/RokuroCamera.cs.meta
Normal file
13
Assets/VRM_Samples/SimpleViewer/RokuroCamera.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77cf12e6f4085e246b0582a18a957bc1
|
||||
timeCreated: 1523878901
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6356
Assets/VRM_Samples/SimpleViewer/SimpleViewer.unity
Normal file
6356
Assets/VRM_Samples/SimpleViewer/SimpleViewer.unity
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/VRM_Samples/SimpleViewer/SimpleViewer.unity.meta
Normal file
8
Assets/VRM_Samples/SimpleViewer/SimpleViewer.unity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d0b0ec0bd1cdee4fbd25b64a6d059df
|
||||
timeCreated: 1524033960
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/VRM_Samples/SimpleViewer/TargetMover.cs
Normal file
40
Assets/VRM_Samples/SimpleViewer/TargetMover.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VRM.SimpleViewer
|
||||
{
|
||||
public class TargetMover : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
float m_radius = 5.0f;
|
||||
|
||||
[SerializeField]
|
||||
float m_angularVelocity = 40.0f;
|
||||
|
||||
[SerializeField]
|
||||
float m_y = 1.5f;
|
||||
|
||||
[SerializeField]
|
||||
float m_height = 3.0f;
|
||||
|
||||
public IEnumerator Start()
|
||||
{
|
||||
var angle = 0.0f;
|
||||
|
||||
while (true)
|
||||
{
|
||||
angle += m_angularVelocity * Time.deltaTime * Mathf.Deg2Rad;
|
||||
|
||||
var x = Mathf.Cos(angle) * m_radius;
|
||||
var z = Mathf.Sin(angle) * m_radius;
|
||||
var y = m_y + m_height * Mathf.Cos(angle / 3);
|
||||
|
||||
transform.localPosition = new Vector3(x, y, z);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM_Samples/SimpleViewer/TargetMover.cs.meta
Normal file
11
Assets/VRM_Samples/SimpleViewer/TargetMover.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93a55f745733f794b963f9eb00d0c0af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "VRM.Samples.SimpleViewer",
|
||||
"references": [
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:b7aa47b240b57de44a4b2021c143c9bf",
|
||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:05dd262a0c0a2f841b8252c8c3815582"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42e9a7b6394cf484fb209ac80e611df2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
502
Assets/VRM_Samples/SimpleViewer/ViewerUI.cs
Normal file
502
Assets/VRM_Samples/SimpleViewer/ViewerUI.cs
Normal file
@@ -0,0 +1,502 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UniGLTF;
|
||||
using UniHumanoid;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using VRMShaders;
|
||||
|
||||
|
||||
namespace VRM.SimpleViewer
|
||||
{
|
||||
|
||||
|
||||
public class ViewerUI : MonoBehaviour
|
||||
{
|
||||
#region UI
|
||||
[SerializeField]
|
||||
Text m_version = default;
|
||||
|
||||
[SerializeField]
|
||||
Button m_open = default;
|
||||
|
||||
[SerializeField]
|
||||
Toggle m_enableLipSync = default;
|
||||
|
||||
[SerializeField]
|
||||
Toggle m_enableAutoBlink = default;
|
||||
|
||||
[SerializeField]
|
||||
Toggle m_useUrpMaterial = default;
|
||||
|
||||
[SerializeField]
|
||||
Toggle m_useFastSpringBone = default;
|
||||
#endregion
|
||||
|
||||
[SerializeField]
|
||||
HumanPoseTransfer m_src = default;
|
||||
|
||||
[SerializeField]
|
||||
GameObject m_target = default;
|
||||
|
||||
[SerializeField]
|
||||
GameObject Root = default;
|
||||
|
||||
[SerializeField]
|
||||
Button m_reset = default;
|
||||
|
||||
[SerializeField]
|
||||
TextAsset m_motion;
|
||||
|
||||
[Serializable]
|
||||
class TextFields
|
||||
{
|
||||
[SerializeField, Header("Info")]
|
||||
Text m_textModelTitle = default;
|
||||
[SerializeField]
|
||||
Text m_textModelVersion = default;
|
||||
[SerializeField]
|
||||
Text m_textModelAuthor = default;
|
||||
[SerializeField]
|
||||
Text m_textModelContact = default;
|
||||
[SerializeField]
|
||||
Text m_textModelReference = default;
|
||||
[SerializeField]
|
||||
RawImage m_thumbnail = default;
|
||||
|
||||
[SerializeField, Header("CharacterPermission")]
|
||||
Text m_textPermissionAllowed = default;
|
||||
[SerializeField]
|
||||
Text m_textPermissionViolent = default;
|
||||
[SerializeField]
|
||||
Text m_textPermissionSexual = default;
|
||||
[SerializeField]
|
||||
Text m_textPermissionCommercial = default;
|
||||
[SerializeField]
|
||||
Text m_textPermissionOther = default;
|
||||
|
||||
[SerializeField, Header("DistributionLicense")]
|
||||
Text m_textDistributionLicense = default;
|
||||
[SerializeField]
|
||||
Text m_textDistributionOther = default;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
m_textModelTitle.text = "";
|
||||
m_textModelVersion.text = "";
|
||||
m_textModelAuthor.text = "";
|
||||
m_textModelContact.text = "";
|
||||
m_textModelReference.text = "";
|
||||
|
||||
m_textPermissionAllowed.text = "";
|
||||
m_textPermissionViolent.text = "";
|
||||
m_textPermissionSexual.text = "";
|
||||
m_textPermissionCommercial.text = "";
|
||||
m_textPermissionOther.text = "";
|
||||
|
||||
m_textDistributionLicense.text = "";
|
||||
m_textDistributionOther.text = "";
|
||||
}
|
||||
|
||||
public async Task UpdateMetaAsync(VRMImporterContext context)
|
||||
{
|
||||
var meta = await context.ReadMetaAsync(new ImmediateCaller(), true);
|
||||
|
||||
m_textModelTitle.text = meta.Title;
|
||||
m_textModelVersion.text = meta.Version;
|
||||
m_textModelAuthor.text = meta.Author;
|
||||
m_textModelContact.text = meta.ContactInformation;
|
||||
m_textModelReference.text = meta.Reference;
|
||||
|
||||
m_textPermissionAllowed.text = meta.AllowedUser.ToString();
|
||||
m_textPermissionViolent.text = meta.ViolentUssage.ToString();
|
||||
m_textPermissionSexual.text = meta.SexualUssage.ToString();
|
||||
m_textPermissionCommercial.text = meta.CommercialUssage.ToString();
|
||||
m_textPermissionOther.text = meta.OtherPermissionUrl;
|
||||
|
||||
m_textDistributionLicense.text = meta.LicenseType.ToString();
|
||||
m_textDistributionOther.text = meta.OtherLicenseUrl;
|
||||
|
||||
m_thumbnail.texture = meta.Thumbnail;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
TextFields m_texts = default;
|
||||
|
||||
[Serializable]
|
||||
class UIFields
|
||||
{
|
||||
[SerializeField]
|
||||
Toggle ToggleMotionTPose = default;
|
||||
|
||||
[SerializeField]
|
||||
Toggle ToggleMotionBVH = default;
|
||||
|
||||
[SerializeField]
|
||||
ToggleGroup ToggleMotion = default;
|
||||
|
||||
Toggle m_activeToggleMotion = default;
|
||||
|
||||
public void UpdateToggle(Action onBvh, Action onTPose)
|
||||
{
|
||||
var value = ToggleMotion.ActiveToggles().FirstOrDefault();
|
||||
if (value == m_activeToggleMotion)
|
||||
return;
|
||||
|
||||
m_activeToggleMotion = value;
|
||||
if (value == ToggleMotionTPose)
|
||||
{
|
||||
onTPose();
|
||||
}
|
||||
else if (value == ToggleMotionBVH)
|
||||
{
|
||||
onBvh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("motion: no toggle");
|
||||
}
|
||||
}
|
||||
}
|
||||
[SerializeField]
|
||||
UIFields m_ui = default;
|
||||
|
||||
[SerializeField]
|
||||
HumanPoseClip m_pose = default;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
var buttons = GameObject.FindObjectsOfType<Button>();
|
||||
m_open = buttons.First(x => x.name == "Open");
|
||||
|
||||
m_reset = buttons.First(x => x.name == "ResetSpringBone");
|
||||
|
||||
var toggles = GameObject.FindObjectsOfType<Toggle>();
|
||||
m_useFastSpringBone = toggles.First(x => x.name == "UseFastSpringBone");
|
||||
m_enableLipSync = toggles.First(x => x.name == "EnableLipSync");
|
||||
m_enableAutoBlink = toggles.First(x => x.name == "EnableAutoBlink");
|
||||
|
||||
var texts = GameObject.FindObjectsOfType<Text>();
|
||||
m_version = texts.First(x => x.name == "Version");
|
||||
|
||||
m_src = GameObject.FindObjectOfType<HumanPoseTransfer>();
|
||||
|
||||
m_target = GameObject.FindObjectOfType<TargetMover>().gameObject;
|
||||
}
|
||||
|
||||
class Loaded : IDisposable
|
||||
{
|
||||
RuntimeGltfInstance _instance;
|
||||
HumanPoseTransfer _pose;
|
||||
VRMBlendShapeProxy m_proxy;
|
||||
|
||||
Blinker m_blink;
|
||||
bool m_enableBlinkValue;
|
||||
public bool EnableBlinkValue
|
||||
{
|
||||
set
|
||||
{
|
||||
if (m_blink == value) return;
|
||||
m_enableBlinkValue = value;
|
||||
if (m_blink != null)
|
||||
{
|
||||
m_blink.enabled = m_enableBlinkValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AIUEO m_lipSync;
|
||||
bool m_enableLipSyncValue;
|
||||
public bool EnableLipSyncValue
|
||||
{
|
||||
set
|
||||
{
|
||||
if (m_enableLipSyncValue == value) return;
|
||||
m_enableLipSyncValue = value;
|
||||
if (m_lipSync != null)
|
||||
{
|
||||
m_lipSync.enabled = m_enableLipSyncValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Loaded(RuntimeGltfInstance instance, HumanPoseTransfer src, Transform lookAtTarget)
|
||||
{
|
||||
_instance = instance;
|
||||
|
||||
var lookAt = instance.GetComponent<VRMLookAtHead>();
|
||||
if (lookAt != null)
|
||||
{
|
||||
// vrm
|
||||
_pose = _instance.gameObject.AddComponent<HumanPoseTransfer>();
|
||||
_pose.Source = src;
|
||||
_pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
|
||||
|
||||
m_lipSync = instance.gameObject.AddComponent<AIUEO>();
|
||||
m_blink = instance.gameObject.AddComponent<Blinker>();
|
||||
|
||||
lookAt.Target = lookAtTarget;
|
||||
lookAt.UpdateType = UpdateType.LateUpdate; // after HumanPoseTransfer's setPose
|
||||
|
||||
m_proxy = instance.GetComponent<VRMBlendShapeProxy>();
|
||||
}
|
||||
|
||||
// not vrm
|
||||
var animation = instance.GetComponent<Animation>();
|
||||
if (animation && animation.clip != null)
|
||||
{
|
||||
animation.Play(animation.clip.name);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Destroy game object. not RuntimeGltfInstance
|
||||
GameObject.Destroy(_instance.gameObject);
|
||||
}
|
||||
|
||||
public void EnableBvh(HumanPoseTransfer src)
|
||||
{
|
||||
if (_pose != null)
|
||||
{
|
||||
_pose.Source = src;
|
||||
_pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableTPose(HumanPoseClip pose)
|
||||
{
|
||||
if (_pose != null)
|
||||
{
|
||||
_pose.PoseClip = pose;
|
||||
_pose.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseClip;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnResetClicked()
|
||||
{
|
||||
if (_pose != null)
|
||||
{
|
||||
foreach (var spring in _pose.GetComponentsInChildren<VRMSpringBone>())
|
||||
{
|
||||
spring.Setup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (m_proxy != null)
|
||||
{
|
||||
m_proxy.Apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded m_loaded;
|
||||
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_version.text = string.Format("VRMViewer {0}.{1}",
|
||||
VRMVersion.MAJOR, VRMVersion.MINOR);
|
||||
m_open.onClick.AddListener(OnOpenClicked);
|
||||
m_useFastSpringBone.onValueChanged.AddListener(OnUseFastSpringBoneValueChanged);
|
||||
OnUseFastSpringBoneValueChanged(m_useFastSpringBone.isOn);
|
||||
|
||||
m_reset.onClick.AddListener(() => m_loaded.OnResetClicked());
|
||||
|
||||
// load initial bvh
|
||||
if (m_motion != null)
|
||||
{
|
||||
LoadMotion("tmp.bvh", m_motion.text);
|
||||
}
|
||||
|
||||
string[] cmds = System.Environment.GetCommandLineArgs();
|
||||
if (cmds.Length > 1)
|
||||
{
|
||||
LoadModel(cmds[1]);
|
||||
}
|
||||
|
||||
m_texts.Start();
|
||||
}
|
||||
|
||||
private void LoadMotion(string path, string source)
|
||||
{
|
||||
var context = new UniHumanoid.BvhImporterContext();
|
||||
context.Parse(path, source);
|
||||
context.Load();
|
||||
SetMotion(context.Root.GetComponent<HumanPoseTransfer>());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab))
|
||||
{
|
||||
if (Root != null) Root.SetActive(!Root.activeSelf);
|
||||
}
|
||||
|
||||
m_ui.UpdateToggle(() => m_loaded?.EnableBvh(m_src), () => m_loaded?.EnableTPose(m_pose));
|
||||
|
||||
if (m_loaded != null)
|
||||
{
|
||||
m_loaded.EnableLipSyncValue = m_enableLipSync.isOn;
|
||||
m_loaded.EnableBlinkValue = m_enableAutoBlink.isOn;
|
||||
m_loaded.Update();
|
||||
}
|
||||
}
|
||||
|
||||
void OnOpenClicked()
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN
|
||||
var path = FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "bvh", "gltf", "zip");
|
||||
#elif UNITY_EDITOR
|
||||
var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm");
|
||||
#else
|
||||
var path = Application.dataPath + "/default.vrm";
|
||||
#endif
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LoadModel(path);
|
||||
}
|
||||
|
||||
void LoadModel(string path)
|
||||
{
|
||||
var ext = Path.GetExtension(path).ToLower();
|
||||
switch (ext)
|
||||
{
|
||||
case ".gltf":
|
||||
case ".glb":
|
||||
case ".zip":
|
||||
LoadModelAsync(path, false);
|
||||
break;
|
||||
|
||||
case ".vrm":
|
||||
LoadModelAsync(path, true);
|
||||
break;
|
||||
|
||||
case ".bvh":
|
||||
LoadMotion(path, File.ReadAllText(path));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnUseFastSpringBoneValueChanged(bool flag)
|
||||
{
|
||||
m_reset.gameObject.SetActive(!flag);
|
||||
}
|
||||
|
||||
static IMaterialDescriptorGenerator GetGltfMaterialGenerator(bool useUrp)
|
||||
{
|
||||
if (useUrp)
|
||||
{
|
||||
return new GltfUrpMaterialDescriptorGenerator();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GltfMaterialDescriptorGenerator();
|
||||
}
|
||||
}
|
||||
|
||||
static IMaterialDescriptorGenerator GetVrmMaterialGenerator(bool useUrp, VRM.glTF_VRM_extensions vrm)
|
||||
{
|
||||
if (useUrp)
|
||||
{
|
||||
return new VRM.VRMUrpMaterialDescriptorGenerator(vrm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new VRM.VRMMaterialDescriptorGenerator(vrm);
|
||||
}
|
||||
}
|
||||
|
||||
async void LoadModelAsync(string path, bool isVrm)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.LogFormat("{0}", path);
|
||||
|
||||
GltfData data;
|
||||
try
|
||||
{
|
||||
data = new AutoGltfFileParser(path).Parse();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarningFormat("parse error: {0}", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isVrm)
|
||||
{
|
||||
try
|
||||
{
|
||||
var vrm = new VRMData(data);
|
||||
using (var loader = new VRMImporterContext(vrm, materialGenerator: GetVrmMaterialGenerator(m_useUrpMaterial.isOn, vrm.VrmExtension)))
|
||||
{
|
||||
await m_texts.UpdateMetaAsync(loader);
|
||||
var instance = await loader.LoadAsync();
|
||||
SetModel(instance);
|
||||
}
|
||||
}
|
||||
catch (NotVrm0Exception)
|
||||
{
|
||||
// retry
|
||||
Debug.LogWarning("file extension is vrm. but not vrm ?");
|
||||
using (var loader = new UniGLTF.ImporterContext(data, materialGenerator: GetGltfMaterialGenerator(m_useUrpMaterial.isOn)))
|
||||
{
|
||||
var instance = await loader.LoadAsync();
|
||||
SetModel(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var loader = new UniGLTF.ImporterContext(data, materialGenerator: GetGltfMaterialGenerator(m_useUrpMaterial.isOn)))
|
||||
{
|
||||
var instance = await loader.LoadAsync();
|
||||
SetModel(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetModel(RuntimeGltfInstance instance)
|
||||
{
|
||||
// cleanup
|
||||
if (m_loaded != null)
|
||||
{
|
||||
m_loaded.Dispose();
|
||||
m_loaded = null;
|
||||
}
|
||||
|
||||
if (m_useFastSpringBone.isOn)
|
||||
{
|
||||
FastSpringBoneReplacer.ReplaceAsync(instance.Root);
|
||||
}
|
||||
|
||||
instance.EnableUpdateWhenOffscreen();
|
||||
instance.ShowMeshes();
|
||||
|
||||
m_loaded = new Loaded(instance, m_src, m_target.transform);
|
||||
}
|
||||
|
||||
void SetMotion(HumanPoseTransfer src)
|
||||
{
|
||||
m_src = src;
|
||||
src.GetComponent<Renderer>().enabled = false;
|
||||
if (m_loaded != null)
|
||||
{
|
||||
m_loaded.EnableBvh(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/VRM_Samples/SimpleViewer/ViewerUI.cs.meta
Normal file
12
Assets/VRM_Samples/SimpleViewer/ViewerUI.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ff4c2e543f3a9143a42e9d01e7d9bc4
|
||||
timeCreated: 1524037800
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user