Skip to content

Commit

Permalink
0.08 Oculus Touch テスト版
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-akira committed Aug 18, 2018
1 parent 15891fb commit 6450c30
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
29 changes: 24 additions & 5 deletions Assets/Scripts/ControlWPFWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class ControlWPFWindow : MonoBehaviour

private Animator animator = null;

private bool IsOculus { get { return SteamVR.instance.hmd_TrackingSystemName.ToLower().Contains("oculus"); } }

private enum MouseButtons
{
Left = 0,
Expand Down Expand Up @@ -160,7 +162,7 @@ await mainThreadInvoker.InvokeAsync(async () =>

else if (e.CommandType == typeof(PipeCommands.Calibrate))
{
Calibrate();
StartCoroutine(Calibrate());
}
else if (e.CommandType == typeof(PipeCommands.EndCalibrate))
{
Expand Down Expand Up @@ -456,7 +458,7 @@ private async void ImportVRM(string path, bool ImportForCalibration)
CurrentModel = await VRMImporter.LoadVrmAsync(context);

//モデルのSkinnedMeshRendererがカリングされないように、すべてのオプション変更
foreach(var renderer in CurrentModel.GetComponentsInChildren<SkinnedMeshRenderer>(true))
foreach (var renderer in CurrentModel.GetComponentsInChildren<SkinnedMeshRenderer>(true))
{
renderer.updateWhenOffscreen = true;
}
Expand Down Expand Up @@ -542,7 +544,7 @@ private void SetVRIK(GameObject model)
Transform leftHandTracker = null;
Transform rightHandTracker = null;

private void Calibrate()
private IEnumerator Calibrate()
{
Transform headTracker = handler.HMDObject.transform;// AddCalibrateTransform(handler.HMDObject.transform, TrackerNums.Zero);
var controllerTransforms = (new Transform[] { handler.LeftControllerObject.transform, handler.RightControllerObject.transform }).Select((d, i) => new { index = i, pos = headTracker.InverseTransformDirection(d.transform.position - headTracker.position), transform = d.transform }).OrderBy(d => d.pos.x).Select(d => d.transform);
Expand Down Expand Up @@ -570,8 +572,22 @@ private void Calibrate()
//DoCalibrate(vrik, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
//DoCalibrate2(vrik, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
vrik.solver.IKPositionWeight = 1.0f;
var settings = new RootMotion.FinalIK.VRIKCalibrator.Settings() { headOffset = new Vector3(0f, -0.15f, -0.15f), handOffset = new Vector3(0f, -0.03f, -0.07f) };
var settings = new RootMotion.FinalIK.VRIKCalibrator.Settings() { headOffset = new Vector3(0f, -0.15f, -0.15f), handOffset = new Vector3(0f, 0f, 0f) };
////モデルのスケールを両手に合わせて拡大
//if (animator != null)
//{
// var leftHand = animator.GetBoneTransform(HumanBodyBones.LeftHand); //手首のポジション
// var rightHand = animator.GetBoneTransform(HumanBodyBones.RightHand);
// var realLeftHand = leftHandTracker; //コントローラーの先端(メニューボタンの上あたり)のポジション
// var realRightHand = rightHandTracker;
// var handDistance = Vector3.Distance(leftHand.position, rightHand.position);
// var realHandDistance = Vector3.Distance(realLeftHand.position, realRightHand.position) - 0.1f; //片手15cm(コントローラー分)引く
// var scale = handDistance / realHandDistance;
// CurrentModel.transform.localScale = new Vector3(scale, scale, scale);
// yield return new WaitForEndOfFrame();
//}
Calibrator.Calibrate(vrik, settings, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
yield return new WaitForEndOfFrame();
Calibrator.Calibrate(vrik, settings, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
Calibrator.Calibrate(vrik, settings, headTracker, bodyTracker, leftHandTracker, rightHandTracker, leftFootTracker, rightFootTracker);
if (handler.Trackers.Count == 1)
Expand Down Expand Up @@ -965,6 +981,7 @@ private async void ControllerAction_KeyDown(object sender, OVRKeyEventArgs e)
config.keyIndex = e.IsAxis == false ? -1 : e.ButtonId == Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad ? NearestPointIndex(e.IsLeft, e.Axis.x, e.Axis.y) : 0;
if (e.IsAxis)
{
if (config.keyIndex < 0) return;
if (e.IsLeft) lastLeftAxisPoint = config.keyIndex;
else lastRightAxisPoint = config.keyIndex;
}
Expand All @@ -989,6 +1006,7 @@ private async void ControllerAction_KeyUp(object sender, OVRKeyEventArgs e)
if (doKeyConfig) await server.SendCommandAsync(new PipeCommands.KeyUp { Config = config });
else CheckKey(config, false);
config.keyIndex = newindex;
if (config.keyIndex < 0) return;
//新しいキーを押す
if (doKeyConfig) await server.SendCommandAsync(new PipeCommands.KeyDown { Config = config });
else CheckKey(config, true);
Expand Down Expand Up @@ -1054,13 +1072,14 @@ private int NearestPointIndex(bool isLeft, float x, float y)
var points = isLeft ? CurrentSettings.LeftTouchPadPoints : CurrentSettings.RightTouchPadPoints;
if (points == null) return 0; //未設定時は一つ
var centerEnable = isLeft ? CurrentSettings.LeftCenterEnable : CurrentSettings.RightCenterEnable;
if (centerEnable) //センターキー有効時
if (centerEnable || IsOculus) //センターキー有効時(Oculusの場合はスティックなので、センター無効にする)
{
var point_distance = x * x + y * y;
var r = 2.0f / 5.0f; //半径
var r2 = r * r;
if (point_distance < r2) //円内
{
if (IsOculus) return -1;
index = points.Count + 1;
return index;
}
Expand Down
23 changes: 21 additions & 2 deletions Assets/Scripts/OVRControllerAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,35 @@ private void Instance_OnOVREvent(object sender, OVREventArgs e)
}
}

EVRButtonId[] buttonIds = new EVRButtonId[] {
EVRButtonId[] buttonIds_vive = new EVRButtonId[] {
EVRButtonId.k_EButton_ApplicationMenu,
EVRButtonId.k_EButton_Grip,
EVRButtonId.k_EButton_SteamVR_Touchpad,
//EVRButtonId.k_EButton_SteamVR_Trigger
};

EVRButtonId[] axisIds = new EVRButtonId[] {
EVRButtonId[] axisIds_vive = new EVRButtonId[] {
EVRButtonId.k_EButton_SteamVR_Touchpad,
//EVRButtonId.k_EButton_SteamVR_Trigger
};

EVRButtonId[] buttonIds_oculus = new EVRButtonId[] {
EVRButtonId.k_EButton_SteamVR_Trigger, //人差し指トリガー
EVRButtonId.k_EButton_SteamVR_Touchpad, //スティック
EVRButtonId.k_EButton_Grip, //中指トリガー
EVRButtonId.k_EButton_A, //A/Xボタン (ちゃんと認識される?)
EVRButtonId.k_EButton_ApplicationMenu, //B/Yボタン
};

EVRButtonId[] axisIds_oculus = new EVRButtonId[] {
EVRButtonId.k_EButton_SteamVR_Trigger, //人差し指トリガー
EVRButtonId.k_EButton_SteamVR_Touchpad, //スティック
EVRButtonId.k_EButton_A, //A/Xボタン (ちゃんと認識される?)
EVRButtonId.k_EButton_ApplicationMenu, //B/Yボタン
};

private bool IsOculus { get { return SteamVR.instance.hmd_TrackingSystemName.ToLower().Contains("oculus"); } }

void Update()
{
var leftid = OpenVRWrapper.Instance.openVR.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
Expand All @@ -196,6 +213,8 @@ void Update()
private void CheckControllerStatus(int index, bool isLeft)
{
var name = isLeft ? " Left:" : "Right:";
var buttonIds = IsOculus ? buttonIds_oculus : buttonIds_vive;
var axisIds = IsOculus ? axisIds_oculus : axisIds_vive;
foreach (var buttonId in buttonIds)
{
if (SteamVR_Controller.Input(index).GetPressDown(buttonId))
Expand Down
4 changes: 2 additions & 2 deletions ControlWindowWPF/ControlWindowWPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.5")]
[assembly: AssemblyFileVersion("0.0.0.5")]
[assembly: AssemblyVersion("0.0.0.8")]
[assembly: AssemblyFileVersion("0.0.0.8")]
Binary file not shown.

0 comments on commit 6450c30

Please sign in to comment.