version 2.0.0

This commit is contained in:
srl87
2023-09-14 18:17:47 +08:00
parent 13e9d00b37
commit ca21423a06
953 changed files with 125887 additions and 21229 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ceb6bae4c2ad8b429f23dcab89cf251
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
# 12.70. XR_HTC_vive_wrist_tracker_interaction
## Name String
XR_HTC_vive_wrist_tracker_interaction
## Revision
1
## VIVE Wrist Tracker input
### Interaction profile path:
- /interaction_profiles/htc/vive_wrist_tracker
### Valid for user paths:
- /user/wrist_htc/left
- /user/wrist_htc/right
### Supported input source
- On /user/wrist_htc/left only:
- <20>K/input/menu/click
- <20>K/input/x/click
- On /user/wrist_htc/right only:
- <20>K/input/system/click (may not be available for application use)
- <20>K/input/a/click
- <20>K/input/entity_htc/pose
The entity_htc pose allows the applications to recognize the origin of a tracked input device, especially for the wearable devices which are not held in the user<65><72>s hand. The entity_htc pose is defined as follows:
- The entity position: The center position of the tracked device.
- The entity orientation: Oriented with +Y up, +X to the right, and -Z forward.
## VIVE Plugin
After adding the "VIVE Focus3 Wrist Tracker" to "Project Settings > XR Plugin-in Management > OpenXR > Android Tab > Interaction Profiles", you can use the following Input Action Pathes.
### Left Hand
- <ViveWristTracker>{LeftHand}/primaryButton: Left tracker primary button pressed state.
- <ViveWristTracker>{LeftHand}/menu: Left tracker menu button pressed state.
- <ViveWristTracker>{LeftHand}/devicePose: Left tracker pose.
- <ViveWristTracker>{LeftHand}/devicePose/isTracked: Left tracker tracking state.
### Right Hand
- <ViveWristTracker>{RightHand}/primaryButton: Right tracker primary button pressed state.
- <ViveWristTracker>{RightHand}/menu: Right tracker menu button pressed state.
- <ViveWristTracker>{RightHand}/devicePose: Right tracker pose.
- <ViveWristTracker>{RightHand}/devicePose/isTracked: Right tracker tracking state.
Refer to the <VIVE OpenXR sample path>/Plugin/Input/ActionMap/InputActions.inputActions about the "Input Action Path" usage and the sample <VIVE OpenXR sample path>/Plugin/Input/OpenXRInput.unity.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f5730a6cbe3d89f408a7cd52289f7d3f
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 83afdfd52871d724b87c568b98638daa
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,324 @@
// "VIVE SDK
// © 2020 HTC Corporation. All Rights Reserved.
//
// Unless otherwise required by copyright law and practice,
// upon the execution of HTC SDK license agreement,
// HTC grants you access to and use of the VIVE SDK(s).
// You shall fully comply with all of HTCs SDK license agreement terms and
// conditions signed by you and all SDK and API requirements,
// specifications, and documentation provided by HTC to You."
using UnityEngine.Scripting;
using UnityEngine.XR.OpenXR.Features;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.XR;
using UnityEngine.InputSystem.Controls;
using UnityEngine.XR.OpenXR;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Collections.Generic;
using UnityEngine.XR;
using UnityEngine.XR.OpenXR.Input;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.XR.OpenXR.Features;
#endif
#if USE_INPUT_SYSTEM_POSE_CONTROL // Scripting Define Symbol added by using OpenXR Plugin 1.6.0.
using PoseControl = UnityEngine.InputSystem.XR.PoseControl;
#else
using PoseControl = UnityEngine.XR.OpenXR.Input.PoseControl;
#endif
namespace VIVE.OpenXR.Tracker
{
/// <summary>
/// This <see cref="OpenXRInteractionFeature"/> enables the use of wrist tracker interaction profiles in OpenXR. It enables XR_HTC_vive_wrist_tracker_interaction in the underyling runtime.
/// This creates a new <see cref="InputDevice"/> with the <see cref="InputDeviceCharacteristics.TrackedDevice"/> characteristic.
/// </summary>
#if UNITY_EDITOR
[OpenXRFeature(UiName = "VIVE XR Wrist Tracker",
BuildTargetGroups = new[] { BuildTargetGroup.Android , BuildTargetGroup.Standalone},
Company = "HTC",
Desc = "Support for enabling the wrist tracker interaction profile. Will register the controller map for wrist tracker if enabled.",
DocumentationLink = "..\\Documentation",
Version = "1.0.0",
OpenxrExtensionStrings = kOpenxrExtensionString,
Category = FeatureCategory.Interaction,
FeatureId = featureId)]
#endif
public class ViveWristTracker : OpenXRInteractionFeature
{
const string LOG_TAG = "VIVE.OpenXR.Tracker.ViveWristTracker";
void DEBUG(string msg) { Debug.Log(LOG_TAG + " " + msg); }
void WARNING(string msg) { Debug.LogWarning(LOG_TAG + " " + msg); }
/// <summary>
/// OpenXR specification <see href="https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#XR_HTC_vive_wrist_tracker_interaction">12.72. XR_HTC_vive_wrist_tracker_interaction</see>.
/// </summary>
public const string kOpenxrExtensionString = "XR_HTC_vive_wrist_tracker_interaction";
/// <summary>
/// The feature id string. This is used to give the feature a well known id for reference.
/// </summary>
public const string featureId = "vive.openxr.feature.tracker";
/// <summary>The interaction profile string used to reference the wrist tracker interaction input device.</summary>
private const string profile = "/interaction_profiles/htc/vive_wrist_tracker";
private const string leftWrist = "/user/wrist_htc/left";
private const string rightWrist = "/user/wrist_htc/right";
// Available Bindings
// Left Hand Only
/// <summary>
/// Constant for a boolean interaction binding '.../input/x/click' OpenXR Input Binding. Used by input subsystem to bind actions to physical inputs. This binding is only available for the <see cref="leftWrist"/> user path.
/// </summary>
public const string buttonX = "/input/x/click";
/// <summary>
/// Constant for a boolean interaction binding '.../input/menu/click' OpenXR Input Binding. Used by input subsystem to bind actions to physical inputs. This binding is only available for the <see cref="leftWrist"/> user path.
/// </summary>
public const string menu = "/input/menu/click";
// Right Hand Only
/// <summary>
/// Constant for a boolean interaction binding '.../input/a/click' OpenXR Input Binding. Used by input subsystem to bind actions to physical inputs. This binding is only available for the <see cref="rightWrist"/> user path.
/// </summary>
public const string buttonA = "/input/a/click";
/// <summary>
/// Constant for a boolean interaction binding '.../input/system/click' OpenXR Input Binding. Used by input subsystem to bind actions to physical inputs. This binding is only available for the <see cref="rightWrist"/> user path.
/// </summary>
public const string system = "/input/system/click";
// Both Hands
/// <summary>
/// Constant for a pose interaction binding '.../input/entity_htc/pose' OpenXR Input Binding. Used by input subsystem to bind actions to physical inputs.
/// </summary>
public const string entityPose = "/input/entity_htc/pose";
[Preserve, InputControlLayout(displayName = "Vive Wrist Tracker (OpenXR)", commonUsages = new[] { "LeftHand", "RightHand" }, isGenericTypeOfDevice = true)]
public class WristTrackerDevice : OpenXRDevice
{
const string LOG_TAG = "VIVE.OpenXR.Tracker.ViveWristTracker.WristTrackerDevice";
void DEBUG(string msg) { Debug.Log(LOG_TAG + " " + msg); }
/// <summary>
/// A <see href="https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Controls.ButtonControl.html">ButtonControl</see> that represents the <see cref="buttonA"/> <see cref="buttonX"/> OpenXR bindings, depending on handedness.
/// </summary>
[Preserve, InputControl(aliases = new[] { "A", "X", "buttonA", "buttonX" }, usage = "PrimaryButton")]
public ButtonControl primaryButton { get; private set; }
/// <summary>
/// A <see cref="PoseControl"/> that represents the <see cref="entityPose"/> OpenXR binding. The entity pose represents the location of the tracker.
/// </summary>
[Preserve, InputControl(offset = 0, aliases = new[] { "device", "entityPose" }, usage = "Device")]
public PoseControl devicePose { get; private set; }
/// <summary>
/// A <see href="https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Controls.ButtonControl.html">ButtonControl</see> required for backwards compatibility with the XRSDK layouts. This represents the overall tracking state of the device. This value is equivalent to mapping devicePose/isTracked.
/// </summary>
[Preserve, InputControl(offset = 24, usage = "IsTracked")]
public ButtonControl isTracked { get; private set; }
/// <summary>
/// A <see href="https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Controls.IntegerControl.html">IntegerControl</see> required for backwards compatibility with the XRSDK layouts. This represents the bit flag set to indicate what data is valid. This value is equivalent to mapping devicePose/trackingState.
/// </summary>
[Preserve, InputControl(offset = 28, usage = "TrackingState")]
public IntegerControl trackingState { get; private set; }
/// <summary>
/// A <see href="https://docs.unity3d.com/Packages/com.unity.inputsystem@0.1/api/UnityEngine.Experimental.Input.Controls.Vector3Control.html">Vector3Control</see> required for backwards compatibility with the XRSDK layouts. This is the device position. For the VIVE XR device, this is both the device and the pointer position. This value is equivalent to mapping devicePose/position.
/// </summary>
[Preserve, InputControl(offset = 32, alias = "gripPosition")]
public Vector3Control devicePosition { get; private set; }
/// <summary>
/// A <see href="https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Controls.QuaternionControl.html">QuaternionControl</see> required for backwards compatibility with the XRSDK layouts. This is the device orientation. For the VIVE XR device, this is both the device and the pointer rotation. This value is equivalent to mapping devicePose/rotation.
/// </summary>
[Preserve, InputControl(offset = 44, alias = "gripOrientation")]
public QuaternionControl deviceRotation { get; private set; }
/// <summary>
/// A <see href="https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Controls.ButtonControl.html">ButtonControl</see> that represents the <see cref="ViveWristTracker.menu"/> OpenXR bindings, depending on handedness.
/// </summary>
[Preserve, InputControl(aliases = new[] { "menuButton" }, usage = "MenuButton")]
public ButtonControl menu { get; private set; }
/// <summary>
/// Internal call used to assign controls to the the correct element.
/// </summary>
protected override void FinishSetup()
{
/*for (int i = 0; i < InputSystem.devices.Count; i++)
{
var description = InputSystem.devices[i].description;
DEBUG("FinishSetup() device[" + i + "], interfaceName: " + description.interfaceName
+ ", deviceClass: " + description.deviceClass
+ ", product: " + description.product);
}*/
base.FinishSetup();
primaryButton = GetChildControl<ButtonControl>("primaryButton");
menu = GetChildControl<ButtonControl>("menu");
devicePose = GetChildControl<PoseControl>("devicePose");
isTracked = GetChildControl<ButtonControl>("isTracked");
trackingState = GetChildControl<IntegerControl>("trackingState");
devicePosition = GetChildControl<Vector3Control>("devicePosition");
deviceRotation = GetChildControl<QuaternionControl>("deviceRotation");
}
}
#pragma warning disable
private bool m_XrInstanceCreated = false;
#pragma warning restore
private XrInstance m_XrInstance = 0;
/// <summary>
/// Called when <see href="https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#xrCreateInstance">xrCreateInstance</see> is done.
/// </summary>
/// <param name="xrInstance">The created instance.</param>
/// <returns>True for valid <see cref="XrInstance">XrInstance</see></returns>
protected override bool OnInstanceCreate(ulong xrInstance)
{
// Requires the eye tracking extension
/*if (!OpenXRRuntime.IsExtensionEnabled(kOpenxrExtensionString))
{
WARNING("OnInstanceCreate() " + kOpenxrExtensionString + " is NOT enabled.");
return false;
}*/
m_XrInstanceCreated = true;
m_XrInstance = xrInstance;
DEBUG("OnInstanceCreate() " + m_XrInstance);
return base.OnInstanceCreate(xrInstance);
}
private const string kLayoutName = "ViveWristTracker";
private const string kDeviceLocalizedName = "Vive Wrist Tracker OpenXR";
/// <summary>
/// Registers the <see cref="WristTrackerDevice"/> layout with the Input System.
/// </summary>
protected override void RegisterDeviceLayout()
{
InputSystem.RegisterLayout(typeof(WristTrackerDevice),
kLayoutName,
matches: new InputDeviceMatcher()
.WithInterface(XRUtilities.InterfaceMatchAnyVersion)
.WithProduct(kDeviceLocalizedName));
}
/// <summary>
/// Removes the <see cref="WristTrackerDevice"/> layout from the Input System.
/// </summary>
protected override void UnregisterDeviceLayout()
{
InputSystem.RemoveLayout(kLayoutName);
}
/// <summary>
/// Registers action maps to Unity XR.
/// </summary>
protected override void RegisterActionMapsWithRuntime()
{
ActionMapConfig actionMap = new ActionMapConfig()
{
name = "vivewristtracker",
localizedName = kDeviceLocalizedName,
desiredInteractionProfile = profile,
manufacturer = "HTC",
serialNumber = "",
deviceInfos = new List<DeviceConfig>()
{
new DeviceConfig()
{
characteristics = InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Left,
userPath = leftWrist // "/user/wrist_htc/left"
},
new DeviceConfig()
{
characteristics = InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Right,
userPath = rightWrist // "/user/wrist_htc/right"
}
},
actions = new List<ActionConfig>()
{
// X / A Press
new ActionConfig()
{
name = "primaryButton",
localizedName = "Primary Pressed",
type = ActionType.Binary,
usages = new List<string>()
{
"PrimaryButton"
},
bindings = new List<ActionBinding>()
{
new ActionBinding()
{
interactionPath = buttonX,
interactionProfileName = profile,
userPaths = new List<string>() { leftWrist }
},
new ActionBinding()
{
interactionPath = buttonA,
interactionProfileName = profile,
userPaths = new List<string>() { rightWrist }
},
}
},
// Menu
new ActionConfig()
{
name = "menu",
localizedName = "Menu",
type = ActionType.Binary,
usages = new List<string>()
{
"MenuButton"
},
bindings = new List<ActionBinding>()
{
new ActionBinding()
{
interactionPath = menu,
interactionProfileName = profile,
userPaths = new List<string>() { leftWrist }
},
new ActionBinding()
{
interactionPath = system,
interactionProfileName = profile,
userPaths = new List<string>() { rightWrist }
},
}
},
// Device Pose
new ActionConfig()
{
name = "devicePose",
localizedName = "Grip Pose",
type = ActionType.Pose,
usages = new List<string>()
{
"Device"
},
bindings = new List<ActionBinding>()
{
new ActionBinding()
{
interactionPath = entityPose,
interactionProfileName = profile,
}
}
}
}
};
AddActionMap(actionMap);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c438b3d1db2d7e4fb133eab8345e6bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: