Move sample to UniVRMTest project

* https://github.com/dwango/UniVRMTest
This commit is contained in:
G21 2018-04-19 14:18:54 +09:00
parent ccd47b9d6f
commit 1f8a5d7fa5
23 changed files with 0 additions and 4907 deletions

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 3399903915becdb45b0a9d5ee452b827
folderAsset: yes
timeCreated: 1522734239
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: f8b8df97087120f489aaf03f9c7a0034
folderAsset: yes
timeCreated: 1524039219
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 53251aee795b92f41973601467818413
timeCreated: 1524039282
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 1a9160f0fe3ace243ae0a22921c3b133
timeCreated: 1524039283
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: d97e18dfaff15ed45908b0fca0f661ee
folderAsset: yes
timeCreated: 1524032882
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,22 +0,0 @@
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace VRM
{
public class CanvasManager : MonoBehaviour
{
[SerializeField]
public Button LoadVRMButton;
[SerializeField]
public Button LoadBVHButton;
private void Reset()
{
LoadVRMButton = GameObject.FindObjectsOfType<Button>().FirstOrDefault(x => x.name == "LoadVRM");
LoadBVHButton = GameObject.FindObjectsOfType<Button>().FirstOrDefault(x => x.name == "LoadBVH");
}
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 1ae08a6ba07c0864c9132bc8a004030d
timeCreated: 1520834280
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,74 +0,0 @@
#if UNITY_STANDALONE_WIN
using System;
using System.Runtime.InteropServices;
namespace VRM
{
public static class FileDialogForWindows
{
#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);
}
static string Filter(params string[] filters)
{
return string.Join("\0", filters) + "\0";
}
public static string FileDialog(string title, string extension)
{
OpenFileName ofn = new OpenFileName();
ofn.structSize = Marshal.SizeOf(ofn);
ofn.filter = Filter("All Files", "*.*", extension, "*" + extension);
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;
//FileDialogResult("file:///" + ofn.file);
} // later, possibly in some other method:
return ofn.file;
}
#endregion
#endif
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 649d78dc96acf5b4f83d54cd1859e940
timeCreated: 1524038001
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,150 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace VRM
{
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;
[SerializeField]
Camera m_camera;
private void Reset()
{
m_camera = GetComponent<Camera>();
}
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;
}
}
}
}

View File

@ -1,13 +0,0 @@
fileFormatVersion: 2
guid: 77cf12e6f4085e246b0582a18a957bc1
timeCreated: 1523878901
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,40 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace VRM
{
public class TargetMover : MonoBehaviour
{
[SerializeField]
float m_radius = 5.0f;
[SerializeField]
float m_angluarVelocity = 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_angluarVelocity * 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;
}
}
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: c04054aea7a18b642b0a4905e808604e
timeCreated: 1524045545
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,217 +0,0 @@
#pragma warning disable 0414
using System;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine;
namespace VRM
{
public class VRMRuntimeLoader : MonoBehaviour
{
[SerializeField]
bool m_loadAsync;
[SerializeField, Header("GUI")]
CanvasManager m_canvas;
[SerializeField]
LookTarget m_faceCamera;
[SerializeField, Header("loader")]
UniHumanoid.HumanPoseTransfer m_source;
[SerializeField]
UniHumanoid.HumanPoseTransfer m_target;
[SerializeField, Header("runtime")]
VRMFirstPerson m_firstPerson;
VRMBlendShapeProxy m_blendShape;
void SetupTarget()
{
if (m_target != null)
{
m_target.Source = m_source;
m_target.SourceType = UniHumanoid.HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
m_blendShape = m_target.GetComponent<VRMBlendShapeProxy>();
m_firstPerson = m_target.GetComponent<VRMFirstPerson>();
var animator = m_target.GetComponent<Animator>();
if (animator != null)
{
m_firstPerson.Setup();
if (m_faceCamera != null)
{
m_faceCamera.Target = animator.GetBoneTransform(HumanBodyBones.Head);
}
}
}
}
private void Awake()
{
SetupTarget();
}
private void Start()
{
if (m_canvas == null)
{
Debug.LogWarning("no canvas");
return;
}
m_canvas.LoadVRMButton.onClick.AddListener(LoadVRMClicked);
m_canvas.LoadBVHButton.onClick.AddListener(LoadBVHClicked);
}
void LoadVRMClicked()
{
#if UNITY_STANDALONE_WIN
var path = FileDialogForWindows.FileDialog("open VRM", ".vrm");
#else
var path = Application.dataPath + "/default.vrm";
#endif
if (string.IsNullOrEmpty(path))
{
return;
}
var bytes = File.ReadAllBytes(path);
// なんらかの方法でByte列を得た
var context = new VRMImporterContext(path);
// GLB形式でJSONを取得しParseします
context.ParseVrm(bytes);
// metaを取得(todo: thumbnailテクスチャのロード)
var meta = context.ReadMeta();
Debug.LogFormat("meta: title:{0}", meta.Title);
// ParseしたJSONをシーンオブジェクトに変換していく
if (m_loadAsync)
{
LoadAsync(context);
}
else
{
VRMImporter.LoadFromBytes(context);
OnLoaded(context.Root);
}
}
/// <summary>
/// メタが不要な場合のローダー
/// </summary>
void LoadVRMClicked_without_meta()
{
#if UNITY_STANDALONE_WIN
var path = FileDialogForWindows.FileDialog("open VRM", ".vrm");
#else
var path = Application.dataPath + "/default.vrm";
#endif
if (string.IsNullOrEmpty(path))
{
return;
}
#if true
var bytes = File.ReadAllBytes(path);
// なんらかの方法でByte列を得た
if (m_loadAsync)
{
// ローカルファイルシステムからロードします
VRMImporter.LoadVrmAsync(bytes, OnLoaded);
}
else
{
var root=VRMImporter.LoadFromBytes(bytes);
OnLoaded(root);
}
#else
// ParseしたJSONをシーンオブジェクトに変換していく
if (m_loadAsync)
{
// ローカルファイルシステムからロードします
VRMImporter.LoadVrmAsync(path, OnLoaded);
}
else
{
var root=VRMImporter.LoadFromPath(path);
OnLoaded(root);
}
#endif
}
void LoadAsync(VRMImporterContext context)
{
#if true
var now = Time.time;
VRMImporter.LoadVrmAsync(context, go=> {
var delta = Time.time - now;
Debug.LogFormat("LoadVrmAsync {0:0.0} seconds", delta);
OnLoaded(go);
});
#else
// ローカルファイルシステムからロードします
VRMImporter.LoadVrmAsync(path, OnLoaded);
#endif
}
void LoadBVHClicked()
{
#if UNITY_STANDALONE_WIN
var path = FileDialogForWindows.FileDialog("open BVH", ".bvh");
if (!string.IsNullOrEmpty(path))
{
LoadBvh(path);
}
#else
LoadBvh(Application.dataPath + "/default.bvh");
#endif
}
void OnLoaded(GameObject root)
{
root.transform.SetParent(transform, false);
// add motion
var humanPoseTransfer = root.AddComponent<UniHumanoid.HumanPoseTransfer>();
if (m_target != null)
{
GameObject.Destroy(m_target.gameObject);
}
m_target = humanPoseTransfer;
SetupTarget();
}
void LoadBvh(string path)
{
Debug.LogFormat("ImportBvh: {0}", path);
var context = new UniHumanoid.ImporterContext
{
Path = path
};
UniHumanoid.BvhImporter.Import(context);
if (m_source != null)
{
GameObject.Destroy(m_source.gameObject);
}
m_source = context.Root.GetComponent<UniHumanoid.HumanPoseTransfer>();
SetupTarget();
}
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 03b059a6d90275246ba8622ac40a63dc
timeCreated: 1517899576
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,135 +0,0 @@
using System.Linq;
using UniHumanoid;
using UnityEngine;
using UnityEngine.UI;
namespace VRM
{
public class ViewerUI : MonoBehaviour
{
#region UI
[SerializeField]
Text m_version;
[SerializeField]
Button m_open;
[SerializeField]
Toggle m_enableLipSync;
[SerializeField]
Toggle m_enableAutoBlink;
#endregion
[SerializeField]
HumanPoseTransfer m_src;
[SerializeField]
GameObject m_target;
private void Reset()
{
var buttons = GameObject.FindObjectsOfType<Button>();
m_open = buttons.First(x => x.name == "Open");
var toggles = GameObject.FindObjectsOfType<Toggle>();
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;
}
GameObject m_loaded;
AIUEO m_lipSync;
bool m_enableLipSyncValue;
bool EnableLipSyncValue
{
set
{
if (m_enableLipSyncValue == value) return;
m_enableLipSyncValue = value;
if (m_lipSync != null)
{
m_lipSync.enabled = m_enableLipSyncValue;
}
}
}
Blinker m_blink;
bool m_enableBlinkValue;
bool EnableBlinkValue
{
set
{
if (m_blink == value) return;
m_enableBlinkValue = value;
if (m_blink != null)
{
m_blink.enabled = m_enableBlinkValue;
}
}
}
private void Start()
{
m_version.text = string.Format("VRMViewer {0}.{1}",
VRMVersion.MAJOR, VRMVersion.MINOR);
m_open.onClick.AddListener(OnOpenClicked);
}
private void Update()
{
EnableLipSyncValue = m_enableLipSync.isOn;
EnableBlinkValue = m_enableAutoBlink.isOn;
}
void OnOpenClicked()
{
var path = FileDialogForWindows.FileDialog("open vrm", "vrm");
if (string.IsNullOrEmpty(path))
{
return;
}
Debug.LogFormat("{0}", path);
var go = VRMImporter.LoadFromPath(path);
if (go == null)
{
return;
}
SetModel(go);
}
void SetModel(GameObject go)
{
// cleanup
if (m_loaded != null)
{
GameObject.Destroy(m_loaded);
}
m_loaded = go;
var dst = go.AddComponent<HumanPoseTransfer>();
dst.Source = m_src;
dst.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
m_lipSync = go.AddComponent<AIUEO>();
m_blink = go.AddComponent<Blinker>();
var lookAt = go.GetComponent<VRMLookAtHead>();
lookAt.Target = m_target.transform;
lookAt.UpdateType = UpdateType.LateUpdate; // after HumanPoseTransfer's setPose
}
}
}

View File

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 8ff4c2e543f3a9143a42e9d01e7d9bc4
timeCreated: 1524037800
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: cb6ff948a1027244a86abf24f3445a87
timeCreated: 1520832729
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 5d0b0ec0bd1cdee4fbd25b64a6d059df
timeCreated: 1524033960
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant: