mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-24 23:18:04 -05:00
prefix
This commit is contained in:
parent
448cefded0
commit
7c3a0c48cc
|
|
@ -4,7 +4,7 @@ using UnityEngine;
|
|||
|
||||
namespace UniVRM10.VRM10Viewer
|
||||
{
|
||||
public class AIUEO : MonoBehaviour
|
||||
public class VRM10AIUEO : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public VRM10Controller Controller;
|
||||
|
|
@ -8,7 +8,7 @@ namespace UniVRM10.VRM10Viewer
|
|||
/// VRMBlendShapeProxy によるランダムに瞬きするサンプル。
|
||||
/// VRMBlendShapeProxy のある GameObject にアタッチする。
|
||||
/// </summary>
|
||||
public class Blinker : MonoBehaviour
|
||||
public class VRM10Blinker : MonoBehaviour
|
||||
{
|
||||
VRM10Controller m_controller;
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace UniVRM10.VRM10Viewer
|
||||
{
|
||||
public static class FileDialogForWindows
|
||||
public static class VRM10FileDialogForWindows
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN
|
||||
#region GetOpenFileName
|
||||
142
Assets/VRM10/Samples/VRM10Viewer/VRM10RokuroCamera.cs
Normal file
142
Assets/VRM10/Samples/VRM10Viewer/VRM10RokuroCamera.cs
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VRM.VRM10RokuroCamera
|
||||
{
|
||||
public class VRM10RokuroCamera : 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/VRM10/Samples/VRM10Viewer/VRM10RokuroCamera.cs.meta
Normal file
13
Assets/VRM10/Samples/VRM10Viewer/VRM10RokuroCamera.cs.meta
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f685b02cd48b2924c84125227ed153c9
|
||||
timeCreated: 1523878901
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -5,7 +5,7 @@ using UnityEngine;
|
|||
|
||||
namespace UniVRM10.VRM10Viewer
|
||||
{
|
||||
public class TargetMover : MonoBehaviour
|
||||
public class VRM10TargetMover : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
float m_radius = 5.0f;
|
||||
|
|
@ -4161,8 +4161,8 @@ GameObject:
|
|||
- component: {fileID: 1629460661}
|
||||
- component: {fileID: 1629460659}
|
||||
- component: {fileID: 1629460658}
|
||||
- component: {fileID: 1629460657}
|
||||
- component: {fileID: 1629460660}
|
||||
- component: {fileID: 1629460657}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
|
|
@ -4179,7 +4179,7 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 1629460656}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 77cf12e6f4085e246b0582a18a957bc1, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: f685b02cd48b2924c84125227ed153c9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
RotateSpeed: 0.7
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using UnityEngine.UI;
|
|||
|
||||
namespace UniVRM10.VRM10Viewer
|
||||
{
|
||||
public class ViewerUI : MonoBehaviour
|
||||
public class VRM10ViewerUI : MonoBehaviour
|
||||
{
|
||||
#region UI
|
||||
[SerializeField]
|
||||
|
|
@ -172,13 +172,13 @@ namespace UniVRM10.VRM10Viewer
|
|||
|
||||
m_src = GameObject.FindObjectOfType<HumanPoseTransfer>();
|
||||
|
||||
m_target = GameObject.FindObjectOfType<TargetMover>().gameObject;
|
||||
m_target = GameObject.FindObjectOfType<VRM10TargetMover>().gameObject;
|
||||
}
|
||||
|
||||
HumanPoseTransfer m_loaded;
|
||||
VRM10Controller m_controller;
|
||||
|
||||
AIUEO m_lipSync;
|
||||
VRM10AIUEO m_lipSync;
|
||||
bool m_enableLipSyncValue;
|
||||
bool EnableLipSyncValue
|
||||
{
|
||||
|
|
@ -193,7 +193,7 @@ namespace UniVRM10.VRM10Viewer
|
|||
}
|
||||
}
|
||||
|
||||
Blinker m_blink;
|
||||
VRM10Blinker m_blink;
|
||||
bool m_enableBlinkValue;
|
||||
bool EnableBlinkValue
|
||||
{
|
||||
|
|
@ -276,7 +276,7 @@ namespace UniVRM10.VRM10Viewer
|
|||
void OnOpenClicked()
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN
|
||||
var path = FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "bvh", "gltf", "zip");
|
||||
var path = VRM10FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "bvh", "gltf", "zip");
|
||||
#elif UNITY_EDITOR
|
||||
var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm");
|
||||
#else
|
||||
|
|
@ -404,8 +404,8 @@ namespace UniVRM10.VRM10Viewer
|
|||
m_loaded.Source = m_src;
|
||||
m_loaded.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer;
|
||||
|
||||
m_lipSync = go.AddComponent<AIUEO>();
|
||||
m_blink = go.AddComponent<Blinker>();
|
||||
m_lipSync = go.AddComponent<VRM10AIUEO>();
|
||||
m_blink = go.AddComponent<VRM10Blinker>();
|
||||
|
||||
m_controller.LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.CalcYawPitchToGaze;
|
||||
m_controller.Gaze = m_target.transform;
|
||||
Loading…
Reference in New Issue
Block a user