add package files
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
|
||||
{
|
||||
public class ActionAssetEnabler : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
InputActionAsset m_ActionAsset;
|
||||
public InputActionAsset actionAsset
|
||||
{
|
||||
get => m_ActionAsset;
|
||||
set => m_ActionAsset = value;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if(m_ActionAsset != null)
|
||||
{
|
||||
m_ActionAsset.Enable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e6db3fe75b0e5d48ba6decfa5d009fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
|
||||
public class Controller : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private InputActionReference m_ActionReferenceTrigger;
|
||||
public InputActionReference actionReferenceTrigger { get => m_ActionReferenceTrigger ; set => m_ActionReferenceTrigger=value; }
|
||||
|
||||
public TextMesh pinchValue;
|
||||
//[SerializeField]
|
||||
//private InputActionReference m_ActionReferenceGrip;
|
||||
//public InputActionReference actionReferenceGrip { get => m_ActionReferenceGrip ; set => m_ActionReferenceGrip=value; }
|
||||
|
||||
Type lastActiveType_Trigger = null;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
pinchValue.text = "0";
|
||||
if ( actionReferenceTrigger != null && actionReferenceTrigger.action != null
|
||||
&& actionReferenceTrigger.action.enabled && actionReferenceTrigger.action.controls.Count > 0
|
||||
/*&& actionReferenceGrip != null && actionReferenceGrip.action != null
|
||||
&& actionReferenceGrip.action.enabled && actionReferenceGrip.action.controls.Count > 0*/)
|
||||
{
|
||||
// Grip
|
||||
//Type typeToUse_Grip = null;
|
||||
//if(actionReferenceGrip.action.activeControl != null)
|
||||
//{
|
||||
// typeToUse_Grip = actionReferenceGrip.action.activeControl.valueType;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// typeToUse_Grip = lastActiveType_Grip;
|
||||
//}
|
||||
|
||||
//if(typeToUse_Grip == typeof(float))
|
||||
//{
|
||||
// lastActiveType_Grip = typeof(float);
|
||||
// float value = actionReferenceGrip.action.ReadValue<float>();
|
||||
// if(value > 0.5)
|
||||
// {
|
||||
// if(!isSwitchedMeshPrefab)
|
||||
// {
|
||||
// isSwitchedMeshPrefab = true;
|
||||
// Debug.Log("Press Button B.");
|
||||
// //if(MeshSubSystem != null)
|
||||
// //{
|
||||
// // MeshSubSystem.GetComponent<UnityEngine.XR.OpenXR.Samples.MeshingFeature.MeshingBehaviour>().SwitchMeshPrefab();
|
||||
// //}
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// isSwitchedMeshPrefab = false;
|
||||
// }
|
||||
//}
|
||||
|
||||
// Trigger
|
||||
Type typeToUse_Trigger = null;
|
||||
if(actionReferenceTrigger.action.activeControl != null)
|
||||
{
|
||||
typeToUse_Trigger = actionReferenceTrigger.action.activeControl.valueType;
|
||||
}
|
||||
else
|
||||
{
|
||||
typeToUse_Trigger = lastActiveType_Trigger;
|
||||
}
|
||||
|
||||
if(typeToUse_Trigger == typeof(float))
|
||||
{
|
||||
lastActiveType_Trigger = typeof(float);
|
||||
float value = actionReferenceTrigger.action.ReadValue<float>();
|
||||
pinchValue.text = value.ToString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 393fd0a40b85a9a4b981076df200a2f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,290 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.OpenXR;
|
||||
using VIVE.HandTracking;
|
||||
[Obsolete("Use HandManager instead")]
|
||||
public static class FrameWork
|
||||
{
|
||||
private class HandData
|
||||
{
|
||||
public bool isStarted;
|
||||
public XrHandEXT hand;
|
||||
public ulong trackerHandle;
|
||||
public bool isActive;
|
||||
public int jointUpdatedFrame = -1;
|
||||
public XrHandJointLocationEXT[] joints = new XrHandJointLocationEXT[(int)XrHandJointEXT.XR_HAND_JOINT_MAX_ENUM_EXT];
|
||||
public XrHandJointVelocityEXT[] velocities = new XrHandJointVelocityEXT[(int)XrHandJointEXT.XR_HAND_JOINT_MAX_ENUM_EXT];
|
||||
|
||||
public bool isCreated { get { return trackerHandle != default; } }
|
||||
|
||||
public void ClearJoints()
|
||||
{
|
||||
Array.Clear(joints, 0, joints.Length);
|
||||
Array.Clear(velocities, 0, velocities.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private static HandTracking_OpenXR_API feature;
|
||||
private static bool isInitialized;
|
||||
private static bool isSystemSupported;
|
||||
private static ulong refSpace;
|
||||
private static HandData leftHandData = new HandData() { hand = XrHandEXT.XR_HAND_LEFT_EXT };
|
||||
private static HandData rightHandData = new HandData() { hand = XrHandEXT.XR_HAND_RIGHT_EXT };
|
||||
|
||||
private static bool isRefSpaceCreated { get { return refSpace != default; } }
|
||||
|
||||
private static HandData GetHandData(bool isLeft)
|
||||
{
|
||||
return isLeft ? leftHandData : rightHandData;
|
||||
}
|
||||
|
||||
public static bool Initialize()
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
if (feature == null)
|
||||
{
|
||||
feature = OpenXRSettings.Instance.GetFeature<HandTracking_OpenXR_API>();
|
||||
|
||||
if (feature != null)
|
||||
{
|
||||
// FIXME: Assume featuer instance won't be destroied and created to a new one
|
||||
feature.onSessionCreate += OnFeatureSessionCreate;
|
||||
feature.onSessionDestroy += OnFeatureSessionDestroy;
|
||||
feature.onSystemChange += OnFeatureSystemChange;
|
||||
}
|
||||
}
|
||||
|
||||
if (feature != null && feature.IsEnabledAndInitialized)
|
||||
{
|
||||
UpdateSystemSupported();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
return isInitialized;
|
||||
}
|
||||
|
||||
private static void OnFeatureSessionCreate(ulong xrSession)
|
||||
{
|
||||
TryCreateHandTracker(leftHandData);
|
||||
TryCreateHandTracker(rightHandData);
|
||||
}
|
||||
|
||||
private static void OnFeatureSessionDestroy(ulong xrSession)
|
||||
{
|
||||
DestroyHandTracker(leftHandData);
|
||||
DestroyHandTracker(rightHandData);
|
||||
DestroyRefSpace();
|
||||
}
|
||||
|
||||
private static void OnFeatureSystemChange(ulong systemId)
|
||||
{
|
||||
UpdateSystemSupported();
|
||||
}
|
||||
|
||||
private static void UpdateSystemSupported()
|
||||
{
|
||||
if (feature == null || !feature.IsEnabledAndInitialized)
|
||||
{
|
||||
isSystemSupported = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
isSystemSupported = feature.SystemSupportsHandTracking(out var result);
|
||||
|
||||
if (!isSystemSupported)
|
||||
{
|
||||
if (result != XrResult.XR_SUCCESS)
|
||||
{
|
||||
Debug.LogWarning("Fail SystemSupportsHandTracking: " + result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Hand tracking not supported by the system");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryCreateHandTracker(HandData handData)
|
||||
{
|
||||
if (!handData.isStarted) { return false; }
|
||||
if (!Initialize()) { return false; }
|
||||
if (!isSystemSupported) { return false; }
|
||||
if (!feature.IsSessionCreated) { return false; }
|
||||
|
||||
if (!handData.isCreated)
|
||||
{
|
||||
if (!feature.TryCreateHandTracker(handData.hand, out handData.trackerHandle, out var result))
|
||||
{
|
||||
handData.trackerHandle = default;
|
||||
Debug.LogWarning("Fail CreateHandTracker: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
return handData.isCreated;
|
||||
}
|
||||
|
||||
private static void DestroyHandTracker(HandData handData)
|
||||
{
|
||||
if (!handData.isCreated) { return; }
|
||||
if (!Initialize()) { return; }
|
||||
|
||||
feature.TryDestroyHandTracker(handData.trackerHandle, out _);
|
||||
handData.trackerHandle = default;
|
||||
handData.ClearJoints();
|
||||
}
|
||||
|
||||
private static bool InitializeRefSpace()
|
||||
{
|
||||
if (!Initialize()) { return false; }
|
||||
if (!isSystemSupported) { return false; }
|
||||
if (!feature.IsSessionCreated) { return false; }
|
||||
|
||||
if (!isRefSpaceCreated)
|
||||
{
|
||||
const XrReferenceSpaceType preferSpaceType = XrReferenceSpaceType.XR_REFERENCE_SPACE_TYPE_STAGE;
|
||||
XrReferenceSpaceType spaceType;
|
||||
if (!feature.TryGetSupportedReferenceSpaceType(preferSpaceType, out spaceType, out var result))
|
||||
{
|
||||
Debug.LogWarning("Fail GetSupportedReferenceSpaceType: " + result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!feature.TryCreateReferenceSpace(
|
||||
spaceType,
|
||||
new XrVector3f(0f, 0f, 0f),
|
||||
new XrQuaternionf(0f, 0f, 0f, 1f),
|
||||
out refSpace,
|
||||
out result))
|
||||
{
|
||||
refSpace = default;
|
||||
Debug.LogWarning("Fail CreateReferenceSpace: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isRefSpaceCreated;
|
||||
}
|
||||
|
||||
private static void DestroyRefSpace()
|
||||
{
|
||||
if (!isRefSpaceCreated) { return; }
|
||||
|
||||
if (Initialize())
|
||||
{
|
||||
if (!feature.TryDestroyReferenceSpace(refSpace, out var result))
|
||||
{
|
||||
Debug.LogWarning("Fail DestroyReferenceSpace: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
refSpace = default;
|
||||
}
|
||||
|
||||
public static void StartFrameWork(bool isLeft)
|
||||
{
|
||||
var handData = GetHandData(isLeft);
|
||||
handData.isStarted = true;
|
||||
|
||||
TryCreateHandTracker(handData);
|
||||
}
|
||||
|
||||
public static void StopFrameWork(bool isLeft)
|
||||
{
|
||||
var handData = GetHandData(isLeft);
|
||||
handData.isStarted = false;
|
||||
|
||||
DestroyHandTracker(handData);
|
||||
}
|
||||
|
||||
public static bool GetJointLocation(bool isleft, out XrHandJointLocationEXT[] joints, bool forceUpdate = false)
|
||||
{
|
||||
var handData = GetHandData(isleft);
|
||||
if (handData.isCreated)
|
||||
{
|
||||
if (forceUpdate || handData.jointUpdatedFrame != Time.frameCount)
|
||||
{
|
||||
handData.jointUpdatedFrame = Time.frameCount;
|
||||
|
||||
if (InitializeRefSpace())
|
||||
{
|
||||
if (!feature.TryLocateHandJoints(
|
||||
handData.trackerHandle,
|
||||
refSpace,
|
||||
out handData.isActive,
|
||||
handData.joints,
|
||||
out var result))
|
||||
{
|
||||
handData.isActive = false;
|
||||
Debug.LogWarning("Fail LocateHandJoints: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
joints = handData.joints;
|
||||
return handData.isActive;
|
||||
}
|
||||
|
||||
public static bool GetJointLocation(bool isleft, out XrHandJointLocationEXT[] joints,ref XrHandJointsMotionRangeEXT type, bool forceUpdate = false)
|
||||
{
|
||||
var handData = GetHandData(isleft);
|
||||
if (handData.isCreated)
|
||||
{
|
||||
if (forceUpdate || handData.jointUpdatedFrame != Time.frameCount)
|
||||
{
|
||||
handData.jointUpdatedFrame = Time.frameCount;
|
||||
|
||||
if (InitializeRefSpace())
|
||||
{
|
||||
if (!feature.TryLocateHandJoints(
|
||||
handData.trackerHandle,
|
||||
refSpace,
|
||||
ref type,
|
||||
out handData.isActive,
|
||||
handData.joints,
|
||||
out var result))
|
||||
{
|
||||
handData.isActive = false;
|
||||
Debug.LogWarning("Fail LocateHandJoints: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
joints = handData.joints;
|
||||
return handData.isActive;
|
||||
}
|
||||
|
||||
public static bool GetJointLocation(bool isleft, out XrHandJointLocationEXT[] joints, out XrHandJointVelocityEXT[] velocities, bool forceUpdate = false)
|
||||
{
|
||||
var handData = GetHandData(isleft);
|
||||
if (handData.isCreated)
|
||||
{
|
||||
if (forceUpdate || handData.jointUpdatedFrame != Time.frameCount)
|
||||
{
|
||||
handData.jointUpdatedFrame = Time.frameCount;
|
||||
|
||||
if (InitializeRefSpace())
|
||||
{
|
||||
if (!feature.TryLocateHandJoints(
|
||||
handData.trackerHandle,
|
||||
refSpace,
|
||||
out handData.isActive,
|
||||
handData.joints,
|
||||
handData.velocities,
|
||||
out var result))
|
||||
{
|
||||
handData.isActive = false;
|
||||
Debug.LogWarning("Fail LocateHandJoints: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
joints = handData.joints;
|
||||
velocities = handData.velocities;
|
||||
return handData.isActive;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89e4cae3bc180f14c906224f93d20210
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,152 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
|
||||
// version 1.4.1
|
||||
// from Assets/Samples/VIVE OpenXR Plugin - Windows/1.0.12/HandTracking Example/Scripts/InputMaster.inputactions
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Utilities;
|
||||
|
||||
public partial class @InputMaster : IInputActionCollection2, IDisposable
|
||||
{
|
||||
public InputActionAsset asset { get; }
|
||||
public @InputMaster()
|
||||
{
|
||||
asset = InputActionAsset.FromJson(@"{
|
||||
""name"": ""InputMaster"",
|
||||
""maps"": [
|
||||
{
|
||||
""name"": ""Keyboard"",
|
||||
""id"": ""94ee31f8-c9ac-4138-b5b9-ad5ecec1870d"",
|
||||
""actions"": [
|
||||
{
|
||||
""name"": ""SpacePress"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""2a246a3d-969f-4d95-8e12-9e0000e5b19c"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """",
|
||||
""initialStateCheck"": false
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""d6ea233e-905c-4913-a644-8a84098fea9f"",
|
||||
""path"": ""<Keyboard>/space"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": """",
|
||||
""action"": ""SpacePress"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
""controlSchemes"": []
|
||||
}");
|
||||
// Keyboard
|
||||
m_Keyboard = asset.FindActionMap("Keyboard", throwIfNotFound: true);
|
||||
m_Keyboard_SpacePress = m_Keyboard.FindAction("SpacePress", throwIfNotFound: true);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnityEngine.Object.Destroy(asset);
|
||||
}
|
||||
|
||||
public InputBinding? bindingMask
|
||||
{
|
||||
get => asset.bindingMask;
|
||||
set => asset.bindingMask = value;
|
||||
}
|
||||
|
||||
public ReadOnlyArray<InputDevice>? devices
|
||||
{
|
||||
get => asset.devices;
|
||||
set => asset.devices = value;
|
||||
}
|
||||
|
||||
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
|
||||
|
||||
public bool Contains(InputAction action)
|
||||
{
|
||||
return asset.Contains(action);
|
||||
}
|
||||
|
||||
public IEnumerator<InputAction> GetEnumerator()
|
||||
{
|
||||
return asset.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
asset.Enable();
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
asset.Disable();
|
||||
}
|
||||
public IEnumerable<InputBinding> bindings => asset.bindings;
|
||||
|
||||
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
|
||||
{
|
||||
return asset.FindAction(actionNameOrId, throwIfNotFound);
|
||||
}
|
||||
public int FindBinding(InputBinding bindingMask, out InputAction action)
|
||||
{
|
||||
return asset.FindBinding(bindingMask, out action);
|
||||
}
|
||||
|
||||
// Keyboard
|
||||
private readonly InputActionMap m_Keyboard;
|
||||
private IKeyboardActions m_KeyboardActionsCallbackInterface;
|
||||
private readonly InputAction m_Keyboard_SpacePress;
|
||||
public struct KeyboardActions
|
||||
{
|
||||
private @InputMaster m_Wrapper;
|
||||
public KeyboardActions(@InputMaster wrapper) { m_Wrapper = wrapper; }
|
||||
public InputAction @SpacePress => m_Wrapper.m_Keyboard_SpacePress;
|
||||
public InputActionMap Get() { return m_Wrapper.m_Keyboard; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
public bool enabled => Get().enabled;
|
||||
public static implicit operator InputActionMap(KeyboardActions set) { return set.Get(); }
|
||||
public void SetCallbacks(IKeyboardActions instance)
|
||||
{
|
||||
if (m_Wrapper.m_KeyboardActionsCallbackInterface != null)
|
||||
{
|
||||
@SpacePress.started -= m_Wrapper.m_KeyboardActionsCallbackInterface.OnSpacePress;
|
||||
@SpacePress.performed -= m_Wrapper.m_KeyboardActionsCallbackInterface.OnSpacePress;
|
||||
@SpacePress.canceled -= m_Wrapper.m_KeyboardActionsCallbackInterface.OnSpacePress;
|
||||
}
|
||||
m_Wrapper.m_KeyboardActionsCallbackInterface = instance;
|
||||
if (instance != null)
|
||||
{
|
||||
@SpacePress.started += instance.OnSpacePress;
|
||||
@SpacePress.performed += instance.OnSpacePress;
|
||||
@SpacePress.canceled += instance.OnSpacePress;
|
||||
}
|
||||
}
|
||||
}
|
||||
public KeyboardActions @Keyboard => new KeyboardActions(this);
|
||||
public interface IKeyboardActions
|
||||
{
|
||||
void OnSpacePress(InputAction.CallbackContext context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00c2bfc723925654087046942f18ab09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "InputMaster",
|
||||
"maps": [
|
||||
{
|
||||
"name": "Keyboard",
|
||||
"id": "94ee31f8-c9ac-4138-b5b9-ad5ecec1870d",
|
||||
"actions": [
|
||||
{
|
||||
"name": "SpacePress",
|
||||
"type": "Button",
|
||||
"id": "2a246a3d-969f-4d95-8e12-9e0000e5b19c",
|
||||
"expectedControlType": "Button",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"name": "",
|
||||
"id": "d6ea233e-905c-4913-a644-8a84098fea9f",
|
||||
"path": "<Keyboard>/space",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "SpacePress",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": []
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8c42cba5f401b94db94490595c0f4df
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 1
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class LineRender : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Root object of Line mesh")]
|
||||
public GameObject Line = null;
|
||||
[SerializeField] private LineRenderer GazeRayRenderer;
|
||||
|
||||
[SerializeField]
|
||||
private InputActionReference m_ActionReferencePose;
|
||||
public InputActionReference actionReferencePose { get => m_ActionReferencePose; set => m_ActionReferencePose = value; }
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Vector3 DirectionCombinedLocal;
|
||||
if (actionReferencePose != null && actionReferencePose.action != null
|
||||
&& actionReferencePose.action.enabled && actionReferencePose.action.controls.Count > 0)
|
||||
{
|
||||
//GazeRayRenderer.SetActive(true);
|
||||
UnityEngine.XR.OpenXR.Input.Pose poseval = actionReferencePose.action.ReadValue<UnityEngine.XR.OpenXR.Input.Pose>();
|
||||
Quaternion gazeRotation = poseval.rotation;
|
||||
Quaternion orientation = new Quaternion(
|
||||
1 * (gazeRotation.x),
|
||||
1 * (gazeRotation.y),
|
||||
1 * gazeRotation.z,
|
||||
1 * gazeRotation.w);
|
||||
DirectionCombinedLocal = orientation * Vector3.forward;
|
||||
Vector3 DirectionCombined = Camera.main.transform.TransformDirection(DirectionCombinedLocal);
|
||||
GazeRayRenderer.SetPosition(0, poseval.position);
|
||||
GazeRayRenderer.SetPosition(1, poseval.position + DirectionCombinedLocal * 4);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f20223b10be10d478250a03bb7ae27f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VIVE.HandTracking.Sample
|
||||
{
|
||||
public class ReadOnlyAttribute : PropertyAttribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
||||
public class ReadOnlyDrawer : PropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUI.GetPropertyHeight(property, label, true);
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a85838490cd239847a9f06ea17789601
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,190 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VIVE.HandTracking;
|
||||
|
||||
namespace VIVE.HandTracking.Sample
|
||||
{
|
||||
public class RenderHand : MonoBehaviour
|
||||
{
|
||||
// Links between keypoints, 2*i & 2*i+1 forms a link.
|
||||
// keypoint index: 1: palm, 2-5: thumb, 6-10: index, 11-15: middle, 16-20: ring, 21-25: pinky
|
||||
// fingers are counted from bottom to top
|
||||
private static int[] Connections = new int[] {
|
||||
1, 2, 1, 6, 1, 11, 1, 16, 1, 21, // palm and finger starts
|
||||
2, 6, 6, 11, 11, 16, 16, 21, // finger starts
|
||||
2, 3, 3, 4, 4, 5, // thumb
|
||||
6, 7, 7, 8, 8, 9, 9, 10, // index
|
||||
11, 12, 12, 13, 13, 14, 14, 15, // middle
|
||||
16, 17, 17, 18, 18, 19, 19, 20, // ring
|
||||
21, 22, 22, 23, 23, 24, 24, 25 // pinky
|
||||
};
|
||||
[Tooltip("Draw left hand if true, right hand otherwise")]
|
||||
public bool isLeft = false;
|
||||
[Tooltip("Use inferred or last-known posed when hand loses tracking if true.")]
|
||||
public bool allowUntrackedPose = false;
|
||||
[Tooltip("Default color of hand points")]
|
||||
public Color pointColor = Color.green;
|
||||
[Tooltip("Default color of links between keypoints in skeleton mode")]
|
||||
public Color linkColor = Color.white;
|
||||
[Tooltip("Material for hand points and links")]
|
||||
[SerializeField]
|
||||
private Material material = null;
|
||||
private XrHandJointsMotionRangeEXT MotionType = XrHandJointsMotionRangeEXT.XR_HAND_JOINTS_MOTION_RANGE_MAX_ENUM_EXT;
|
||||
[Tooltip("Type of hand joints range of motion")]
|
||||
[ReadOnly] public string HandJointsMotionRange;
|
||||
|
||||
private List<GameObject> points = new List<GameObject>();
|
||||
// list of links created (only for skeleton)
|
||||
private List<GameObject> links = new List<GameObject>();
|
||||
// Start is called before the first frame update
|
||||
private XrHandJointLocationEXT[] HandjointLocations = new
|
||||
XrHandJointLocationEXT[(int)XrHandJointEXT.XR_HAND_JOINT_MAX_ENUM_EXT];
|
||||
// shared material for all point objects
|
||||
private Material pointMat = null;
|
||||
// shared material for all link objects
|
||||
private Material linkMat = null;
|
||||
private void Start()
|
||||
{
|
||||
HandManager.StartFrameWork(isLeft);
|
||||
pointMat = new Material(material);
|
||||
if (isLeft)
|
||||
{
|
||||
pointColor = Color.blue;
|
||||
}
|
||||
else
|
||||
{
|
||||
pointColor = Color.red;
|
||||
}
|
||||
pointMat.color = pointColor;
|
||||
linkMat = new Material(material);
|
||||
linkMat.color = linkColor;
|
||||
|
||||
for (int i = 0; i < (int)XrHandJointEXT.XR_HAND_JOINT_MAX_ENUM_EXT; i++)
|
||||
{
|
||||
var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
go.name = ((XrHandJointEXT)i).ToString();
|
||||
go.transform.parent = transform;
|
||||
go.transform.localScale = Vector3.one * 0.012f;
|
||||
go.SetActive(false);
|
||||
points.Add(go);
|
||||
go.transform.position = new Vector3((float)i * 0.1f, 0, 0);
|
||||
// handle layer
|
||||
go.layer = gameObject.layer;
|
||||
// handle material
|
||||
go.GetComponent<Renderer>().sharedMaterial = pointMat;
|
||||
}
|
||||
|
||||
// create game objects for links between keypoints, only used in skeleton mode
|
||||
for (int i = 0; i < Connections.Length; i += 2)
|
||||
{
|
||||
var go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
|
||||
go.name = "link" + i;
|
||||
go.transform.parent = transform;
|
||||
go.transform.localScale = Vector3.one * 0.005f;
|
||||
go.SetActive(false);
|
||||
links.Add(go);
|
||||
// handle layer
|
||||
go.layer = gameObject.layer;
|
||||
// handle material
|
||||
go.GetComponent<Renderer>().sharedMaterial = linkMat;
|
||||
}
|
||||
}
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (HandManager.GetJointLocation(isLeft, out HandjointLocations, ref MotionType))
|
||||
{
|
||||
UpdateJointLocation();
|
||||
switch (MotionType)
|
||||
{
|
||||
case XrHandJointsMotionRangeEXT.XR_HAND_JOINTS_MOTION_RANGE_UNOBSTRUCTED_EXT:
|
||||
HandJointsMotionRange = "UNOBSTRUCTED";
|
||||
break;
|
||||
case XrHandJointsMotionRangeEXT.XR_HAND_JOINTS_MOTION_RANGE_CONFORMING_TO_CONTROLLER_EXT:
|
||||
HandJointsMotionRange = "CONTROLLER";
|
||||
break;
|
||||
default:
|
||||
HandJointsMotionRange = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
var go = points[i];
|
||||
go.SetActive(false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < links.Count; i++)
|
||||
{
|
||||
var link = links[i];
|
||||
link.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateJointLocation()
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
var go = points[i];
|
||||
XrQuaternionf orientation;
|
||||
XrVector3f position;
|
||||
float radius = HandjointLocations[i].radius;
|
||||
if (allowUntrackedPose) //Use inferred or last-known pose when lost tracking
|
||||
{
|
||||
orientation = HandjointLocations[i].pose.orientation;
|
||||
position = HandjointLocations[i].pose.position;
|
||||
go.transform.localPosition = new Vector3(position.x, position.y, -position.z);
|
||||
go.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((HandjointLocations[i].locationFlags & (ulong)XrSpaceLocationFlags.XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) != 0)
|
||||
{
|
||||
orientation = HandjointLocations[i].pose.orientation;
|
||||
}
|
||||
if ((HandjointLocations[i].locationFlags & (ulong)XrSpaceLocationFlags.XR_SPACE_LOCATION_POSITION_TRACKED_BIT) != 0)
|
||||
{
|
||||
position = HandjointLocations[i].pose.position;
|
||||
go.transform.localPosition = new Vector3(position.x, position.y, -position.z);
|
||||
go.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log("Lost tracking");
|
||||
go.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < links.Count; i++)
|
||||
{
|
||||
var link = links[i];
|
||||
var pose1 = points[Connections[i * 2]].transform.position;
|
||||
var pose2 = points[Connections[i * 2 + 1]].transform.position;
|
||||
|
||||
// calculate link position and rotation based on points on both end
|
||||
link.SetActive(true);
|
||||
link.transform.position = (pose1 + pose2) / 2;
|
||||
var direction = pose2 - pose1;
|
||||
link.transform.rotation = Quaternion.FromToRotation(Vector3.up, direction);
|
||||
link.transform.localScale = new Vector3(0.006f, direction.magnitude / 2f - 0.0051f, 0.006f);
|
||||
}
|
||||
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
HandManager.StopFrameWork(isLeft);
|
||||
UnityEngine.Debug.Log("OnDestroy");
|
||||
}
|
||||
|
||||
//public void setHandVisible(bool isVisible)
|
||||
//{
|
||||
// Hand.SetActive(isVisible);
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c57cc3ae07bcce42ba395c288cba794
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using VIVE.HandTracking;
|
||||
|
||||
namespace VIVE.HandTracking.Sample
|
||||
{
|
||||
public class RenderModel : MonoBehaviour
|
||||
{
|
||||
private readonly Quaternion zBackModelRotFix = Quaternion.AngleAxis(180f, Vector3.up);
|
||||
|
||||
public Transform[] nodes = new Transform[(int)XrHandJointEXT.XR_HAND_JOINT_MAX_ENUM_EXT];
|
||||
[Tooltip("Draw left hand if true, right hand otherwise")]
|
||||
public bool isLeft = false;
|
||||
[Tooltip("Use inferred or last-known posed when hand loses tracking if true.")]
|
||||
public bool allowUntrackedPose = false;
|
||||
[Tooltip("Root object of skinned mesh")]
|
||||
public GameObject Hand = null;
|
||||
private XrHandJointsMotionRangeEXT MotionType = XrHandJointsMotionRangeEXT.XR_HAND_JOINTS_MOTION_RANGE_MAX_ENUM_EXT;
|
||||
[Tooltip("Type of hand joints range of motion")]
|
||||
[ReadOnly]public string HandJointsMotionRange;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
HandManager.StartFrameWork(isLeft);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (HandManager.GetJointLocation(isLeft, out var joints, ref MotionType))
|
||||
{
|
||||
setHandVisible(true);
|
||||
|
||||
for (int i = (int)XrHandJointEXT.XR_HAND_JOINT_PALM_EXT; i < (int)XrHandJointEXT.XR_HAND_JOINT_MAX_ENUM_EXT; i++)
|
||||
{
|
||||
var posValid = (joints[i].locationFlags & (ulong)XrSpaceLocationFlags.XR_SPACE_LOCATION_POSITION_VALID_BIT) != 0;
|
||||
var posTracked = (joints[i].locationFlags & (ulong)XrSpaceLocationFlags.XR_SPACE_LOCATION_POSITION_TRACKED_BIT) != 0;
|
||||
var rotValid = (joints[i].locationFlags & (ulong)XrSpaceLocationFlags.XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) != 0;
|
||||
var rotTracked = (joints[i].locationFlags & (ulong)XrSpaceLocationFlags.XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) != 0;
|
||||
|
||||
var pos = new Vector3(joints[i].pose.position.x, joints[i].pose.position.y, -joints[i].pose.position.z);
|
||||
var rot = new Quaternion(-joints[i].pose.orientation.x, -joints[i].pose.orientation.y, joints[i].pose.orientation.z, joints[i].pose.orientation.w) * zBackModelRotFix;
|
||||
|
||||
if (posValid && (allowUntrackedPose || posTracked)) { nodes[i].position = transform.TransformPoint(pos); }
|
||||
if (rotValid && (allowUntrackedPose || rotTracked)) { nodes[i].rotation = transform.rotation * rot; }
|
||||
}
|
||||
switch (MotionType)
|
||||
{
|
||||
case XrHandJointsMotionRangeEXT.XR_HAND_JOINTS_MOTION_RANGE_UNOBSTRUCTED_EXT:
|
||||
HandJointsMotionRange = "UNOBSTRUCTED";
|
||||
break;
|
||||
case XrHandJointsMotionRangeEXT.XR_HAND_JOINTS_MOTION_RANGE_CONFORMING_TO_CONTROLLER_EXT:
|
||||
HandJointsMotionRange = "CONTROLLER";
|
||||
break;
|
||||
default:
|
||||
HandJointsMotionRange = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setHandVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
HandManager.StopFrameWork(isLeft);
|
||||
}
|
||||
|
||||
public void setHandVisible(bool isVisible)
|
||||
{
|
||||
Hand.SetActive(isVisible);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c19189c6a6028a74ab475048ebd154c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VIVE.HandTracking.Sample
|
||||
{
|
||||
public class SwitchHand : MonoBehaviour
|
||||
{
|
||||
public InputMaster inputMaster;
|
||||
public GameObject hand3D;
|
||||
public GameObject handSkeleton;
|
||||
private bool isSwitch = false;
|
||||
private void Awake()
|
||||
{
|
||||
inputMaster = new InputMaster();
|
||||
inputMaster.Enable();
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
float ispressed = inputMaster.Keyboard.SpacePress.ReadValue<float>();
|
||||
if (ispressed > 0.5)
|
||||
{
|
||||
if(!isSwitch)
|
||||
{
|
||||
UnityEngine.Debug.Log("press space");
|
||||
hand3D.SetActive(!hand3D.activeSelf);
|
||||
handSkeleton.SetActive(!handSkeleton.activeSelf);
|
||||
isSwitch = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isSwitch = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2642121393e03fd46ba257307ca9cb51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user