上传YomovSDK

This commit is contained in:
Sora丶kong
2026-03-03 03:15:46 +08:00
parent 9096da7e6c
commit eb97f31065
6477 changed files with 1932208 additions and 3 deletions

View File

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

View File

@@ -0,0 +1,395 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.XR.OpenXR.Input;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.XR;
using UnityEngine.InputSystem;
using System.Runtime.InteropServices;
using System;
#if UNITY_EDITOR
using UnityEditor;
#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 UnityEngine.XR.OpenXR.Features.Interactions
{
/// <summary>
/// This <see cref="OpenXRInteractionFeature"/> enables the use of HTC Vive Trackers interaction profiles in OpenXR.
/// </summary>
#if UNITY_EDITOR
[UnityEditor.XR.OpenXR.Features.OpenXRFeature(
UiName = "HTC VIVE Tracker Profile",
BuildTargetGroups = new[] { BuildTargetGroup.Standalone, BuildTargetGroup.WSA },
Company = "MASSIVE",
Desc = "Allows for mapping input to the HTC Vive Tracker interaction profile.",
DocumentationLink = Constants.k_DocumentationManualURL,
OpenxrExtensionStrings = HTCViveTrackerProfile.extensionName,
Version = "0.0.1",
Category = UnityEditor.XR.OpenXR.Features.FeatureCategory.Interaction,
FeatureId = featureId)]
#endif
public class HTCViveTrackerProfile : OpenXRInteractionFeature
{
/// <summary>
/// The feature id string. This is used to give the feature a well known id for reference.
/// </summary>
public const string featureId = "com.massive.openxr.feature.input.htcvivetracker";
/// <summary>
/// The interaction profile string used to reference the <a href="https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#:~:text=in%20this%20case.-,VIVE%20Tracker%20interaction%20profile,-Interaction%20profile%20path">HTC Vive Tracker</a>.
/// </summary>
public const string profile = "/interaction_profiles/htc/vive_tracker_htcx";
/// <summary>
/// The name of the OpenXR extension that supports the Vive Tracker
/// </summary>
public const string extensionName = "XR_HTCX_vive_tracker_interaction";
private const string kLayoutName = "ViveTracker";
private const string kDeviceLocalizedName = "HTC Vive Tracker OpenXR";
/// <summary>
/// OpenXR user path definitions for the tracker.
/// </summary>
public static class TrackerUserPaths
{
/// <summary>
/// Path for user left foot
/// </summary>
public const string leftFoot = "/user/vive_tracker_htcx/role/left_foot";
/// <summary>
/// Path for user roght foot
/// </summary>
public const string rightFoot = "/user/vive_tracker_htcx/role/right_foot";
/// <summary>
/// Path for user left shoulder
/// </summary>
public const string leftShoulder = "/user/vive_tracker_htcx/role/left_shoulder";
/// <summary>
/// Path for user right shoulder
/// </summary>
public const string rightShoulder = "/user/vive_tracker_htcx/role/right_shoulder";
/// <summary>
/// Path for user left elbow
/// </summary>
public const string leftElbow = "/user/vive_tracker_htcx/role/left_elbow";
/// <summary>
/// Path for user right elbow
/// </summary>
public const string rightElbow = "/user/vive_tracker_htcx/role/right_elbow";
/// <summary>
/// Path for user left knee
/// </summary>
public const string leftKnee = "/user/vive_tracker_htcx/role/left_knee";
/// <summary>
/// Path for user right knee
/// </summary>
public const string rightKnee = "/user/vive_tracker_htcx/role/right_knee";
/// <summary>
/// Path for user waist
/// </summary>
public const string waist = "/user/vive_tracker_htcx/role/waist";
/// <summary>
/// Path for user chest
/// </summary>
public const string chest = "/user/vive_tracker_htcx/role/chest";
/// <summary>
/// Path for user custom camera
/// </summary>
public const string camera = "/user/vive_tracker_htcx/role/camera";
/// <summary>
/// Path for user keyboard
/// </summary>
public const string keyboard = "/user/vive_tracker_htcx/role/keyboard";
}
/// <summary>
/// OpenXR component path definitions for the tracker.
/// </summary>
public static class TrackerComponentPaths
{
/// <summary>
/// Constant for a pose interaction binding '.../input/grip/pose' OpenXR Input Binding. Used by input subsystem to bind actions to physical inputs.
/// </summary>
public const string grip = "/input/grip/pose";
}
/// <summary>
/// A base Input System device for XR Trackers, based off the TrackedDevice
/// </summary>
[InputControlLayout(isGenericTypeOfDevice = true, displayName = "XR Tracker")]
public class XRTracker : TrackedDevice
{
}
/// <summary>
/// An Input System device based off the <a href="https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#_htc_vive_controller_profile">HTC Vive Tracker</a>.
/// </summary>
[Preserve, InputControlLayout(displayName = "HTC Vive Tracker (OpenXR)", commonUsages = new[] { "Left Foot", "Right Foot", "Left Shoulder", "Right Shoulder", "Left Elbow", "Right Elbow", "Left Knee", "Right Knee", "Waist", "Chest", "Camera", "Keyboard" })]
public class XRViveTracker : XRTracker
{
/// <summary>
/// A <see cref="PoseControl"/> that represents information from the <see cref="HTCViveTrackerProfile.grip"/> OpenXR binding.
/// </summary>
[Preserve, InputControl(offset = 0, aliases = new[] { "device", "gripPose" }, usage = "Device", noisy = true)]
public PoseControl devicePose { get; private set; }
/// <summary>
/// A [Vector3Control](xref:UnityEngine.InputSystem.Controls.Vector3Control) required for back compatibility with the XRSDK layouts. This is the device position. For the Oculus Touch device, this is both the grip and the pointer position. This value is equivalent to mapping devicePose/position.
/// </summary>
[Preserve, InputControl(offset = 8, alias = "gripPosition", noisy = true)]
new public Vector3Control devicePosition { get; private set; }
/// <summary>
/// A [QuaternionControl](xref:UnityEngine.InputSystem.Controls.QuaternionControl) required for backwards compatibility with the XRSDK layouts. This is the device orientation. For the Oculus Touch device, this is both the grip and the pointer rotation. This value is equivalent to mapping devicePose/rotation.
/// </summary>
[Preserve, InputControl(offset = 20, alias = "gripOrientation", noisy = true)]
new public QuaternionControl deviceRotation { get; private set; }
[Preserve, InputControl(offset = 60)]
new public ButtonControl isTracked { get; private set; }
[Preserve, InputControl(offset = 64)]
new public IntegerControl trackingState { get; private set; }
/// <inheritdoc cref="OpenXRDevice"/>
protected override void FinishSetup()
{
base.FinishSetup();
devicePose = GetChildControl<PoseControl>("devicePose");
devicePosition = GetChildControl<Vector3Control>("devicePosition");
deviceRotation = GetChildControl<QuaternionControl>("deviceRotation");
isTracked = GetChildControl<ButtonControl>("isTracked");
trackingState = GetChildControl<IntegerControl>("trackingState");
var capabilities = description.capabilities;
var deviceDescriptor = XRDeviceDescriptor.FromJson(capabilities);
if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftFoot) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Left Foot");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightFoot) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Right Foot");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftShoulder) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Left Shoulder");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightShoulder) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Right Shoulder");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftElbow) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Left Elbow");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightElbow) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Right Elbow");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftKnee) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Left Knee");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightKnee) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Right Knee");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerWaist) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Waist");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerChest) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Chest");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerCamera) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Camera");
else if ((deviceDescriptor.characteristics & (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerKeyboard) != 0)
InputSystem.InputSystem.SetDeviceUsage(this, "Keyboard");
Debug.Log("Device added");
}
}
/// <summary>
/// Registers the <see cref="ViveTracker"/> layout with the Input System.
/// </summary>
protected override void RegisterDeviceLayout()
{
InputSystem.InputSystem.RegisterLayout<XRTracker>();
InputSystem.InputSystem.RegisterLayout(typeof(XRViveTracker),
matches: new InputDeviceMatcher()
.WithInterface(XRUtilities.InterfaceMatchAnyVersion)
.WithProduct(kDeviceLocalizedName));
}
/// <summary>
/// Removes the <see cref="ViveTracker"/> layout from the Input System.
/// </summary>
protected override void UnregisterDeviceLayout()
{
InputSystem.InputSystem.RemoveLayout(nameof(XRViveTracker));
InputSystem.InputSystem.RemoveLayout(nameof(XRTracker));
}
#if UNITY_XR_OPENXR_1_9_1
/// <summary>
/// Return interaction profile type. XRViveTracker profile is Device type.
/// </summary>
/// <returns>Interaction profile type.</returns>
protected override InteractionProfileType GetInteractionProfileType()
{
return typeof(XRViveTracker).IsSubclassOf(typeof(XRController)) ? InteractionProfileType.XRController : InteractionProfileType.Device;
}
/// <summary>
/// Return device layer out string used for registering device VIVEFocus3Controller in InputSystem.
/// </summary>
/// <returns>Device layout string.</returns>
protected override string GetDeviceLayoutName()
{
return kLayoutName;
}
#endif
//
// Summary:
// A set of bit flags describing XR.InputDevice characteristics.
//"Left Foot", "Right Foot", "Left Shoulder", "Right Shoulder", "Left Elbow", "Right Elbow", "Left Knee", "Right Knee", "Waist", "Chest", "Camera", "Keyboard"
[Flags]
public enum InputDeviceTrackerCharacteristics : uint
{
TrackerLeftFoot = 0x1000u,
TrackerRightFoot = 0x2000u,
TrackerLeftShoulder = 0x4000u,
TrackerRightShoulder = 0x8000u,
TrackerLeftElbow = 0x10000u,
TrackerRightElbow = 0x20000u,
TrackerLeftKnee = 0x40000u,
TrackerRightKnee = 0x80000u,
TrackerWaist = 0x100000u,
TrackerChest = 0x200000u,
TrackerCamera = 0x400000u,
TrackerKeyboard = 0x800000u
}
/// <inheritdoc/>
protected override void RegisterActionMapsWithRuntime()
{
ActionMapConfig actionMap = new ActionMapConfig()
{
name = "htcvivetracker",
localizedName = kDeviceLocalizedName,
desiredInteractionProfile = profile,
manufacturer = "HTC",
serialNumber = "",
deviceInfos = new List<DeviceConfig>()
{
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftFoot,
userPath = TrackerUserPaths.leftFoot
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightFoot,
userPath = TrackerUserPaths.rightFoot
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftShoulder,
userPath = TrackerUserPaths.leftShoulder
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightShoulder,
userPath = TrackerUserPaths.rightShoulder
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftElbow,
userPath = TrackerUserPaths.leftElbow
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightElbow,
userPath = TrackerUserPaths.rightElbow
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerLeftKnee,
userPath = TrackerUserPaths.leftKnee
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerRightKnee,
userPath = TrackerUserPaths.rightKnee
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerWaist,
userPath = TrackerUserPaths.waist
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerChest,
userPath = TrackerUserPaths.chest
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerCamera,
userPath = TrackerUserPaths.camera
},
new DeviceConfig()
{
characteristics = (InputDeviceCharacteristics.TrackedDevice) | (InputDeviceCharacteristics)InputDeviceTrackerCharacteristics.TrackerKeyboard,
userPath = TrackerUserPaths.keyboard
}
},
actions = new List<ActionConfig>()
{
new ActionConfig()
{
name = "devicePose",
localizedName = "Device Pose",
type = ActionType.Pose,
usages = new List<string>()
{
"Device",
},
bindings = new List<ActionBinding>()
{
new ActionBinding()
{
interactionPath = TrackerComponentPaths.grip,
interactionProfileName = profile,
}
}
},
}
};
AddActionMap(actionMap);
}
protected override bool OnInstanceCreate(ulong xrInstance)
{
bool res = base.OnInstanceCreate(xrInstance);
if (OpenXRRuntime.IsExtensionEnabled("XR_HTCX_vive_tracker_interaction"))
{
Debug.Log("HTC Vive Tracker Extension Enabled");
}
else
{
Debug.Log("HTC Vive Tracker Extension Not Enabled");
}
return res;
}
}
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,47 @@
# 12.70. XR_HTC_vive_wrist_tracker_interaction
## Name String
XR_HTC_vive_wrist_tracker_interaction
## Revision
1
## Overview
This extension provides an XrPath for getting device input from a VIVE wrist tracker to enable its interactions. VIVE wrist tracker is a tracked device mainly worn on user<65><72>s wrist for pose tracking. Besides this use case, user also can tie it to a physical object to track its object pose, e.g. tie on a gun.
## 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,352 @@
// Copyright HTC Corporation All Rights Reserved.
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;
using System.Text;
#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",
Hidden = true,
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 = "https://registry.khronos.org/OpenXR/specs/1.1/html/xrspec.html#XR_HTC_vive_wrist_tracker_interaction",
Version = "1.0.0",
OpenxrExtensionStrings = kOpenxrExtensionString,
Category = FeatureCategory.Interaction,
FeatureId = featureId)]
#endif
public class ViveWristTracker : OpenXRInteractionFeature
{
#region Log
const string LOG_TAG = "VIVE.OpenXR.Tracker.ViveWristTracker ";
StringBuilder m_sb = null;
StringBuilder sb
{
get
{
if (m_sb == null) { m_sb = new StringBuilder(); }
return m_sb;
}
}
void DEBUG(StringBuilder msg) { Debug.LogFormat("{0} {1}", LOG_TAG, msg); }
#endregion
/// <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
{
#region Log
const string LOG_TAG = "VIVE.OpenXR.Tracker.ViveWristTracker.WristTrackerDevice ";
StringBuilder m_sb = null;
StringBuilder sb
{
get
{
if (m_sb == null) { m_sb = new StringBuilder(); }
return m_sb;
}
}
void DEBUG(StringBuilder msg) { Debug.LogFormat("{0} {1}", LOG_TAG, msg); }
#endregion
/// <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()
{
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");
sb.Clear().Append(" FinishSetup() device interfaceName: ").Append(description.interfaceName)
.Append(", deviceClass: ").Append(description.deviceClass)
.Append(", product: ").Append(description.product)
.Append(", serial: ").Append(description.serial);
DEBUG(sb);
}
}
#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)
{
m_XrInstanceCreated = true;
m_XrInstance = xrInstance;
sb.Clear().Append(" OnInstanceCreate() " + m_XrInstance); DEBUG(sb);
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()
{
sb.Clear().Append("RegisterDeviceLayout() ").Append(kLayoutName).Append(", product: ").Append(kDeviceLocalizedName); DEBUG(sb);
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()
{
sb.Clear().Append("UnregisterDeviceLayout() ").Append(kLayoutName); DEBUG(sb);
InputSystem.RemoveLayout(kLayoutName);
}
#if UNITY_XR_OPENXR_1_9_1
/// <summary>
/// Return interaction profile type. WristTrackerDevice profile is Device type.
/// </summary>
/// <returns>Interaction profile type.</returns>
protected override InteractionProfileType GetInteractionProfileType()
{
return typeof(WristTrackerDevice).IsSubclassOf(typeof(XRController)) ? InteractionProfileType.XRController : InteractionProfileType.Device;
}
/// <summary>
/// Return device layer out string used for registering device WristTrackerDevice in InputSystem.
/// </summary>
/// <returns>Device layout string.</returns>
protected override string GetDeviceLayoutName()
{
return kLayoutName;
}
#endif
/// <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:

View File

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

View File

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

View File

@@ -0,0 +1,38 @@
# 12.2. XR_HTC_vive_xr_tracker_interaction
## Name String
XR_HTC_vive_xr_tracker_interaction
## Revision
1
## Overview
This extension provides an XrPath for getting device input from VIVE XR tracker to enable its interactions. VIVE XR tracker is the tracked device which can be bound to the physical objects to make them trackable. VIVE XR tracker is a generic name means the series of various tracked devices, not just meaning one specific type of hardware. For example, VIVE XR tracker can be bound to user<65><72>s hands or feet to track the motion of human body. It also can be bound to any other objects that the user wants to track and interact with.
## VIVE Wrist Tracker input
### Interaction profile path:
- /interaction_profiles/htc/vive_xr_tracker
### Valid for user paths:
- /user/xr_tracker_htc/vive_self_tracker_0
- /user/xr_tracker_htc/vive_self_tracker_1
- /user/xr_tracker_htc/vive_self_tracker_2
- /user/xr_tracker_htc/vive_self_tracker_3
- /user/xr_tracker_htc/vive_self_tracker_4
### Supported input source
- <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 XR Tracker" to "Project Settings > XR Plugin-in Management > OpenXR > Android Tab > Interaction Profiles", you can use the following Input Action Pathes.
- <ViveXRTracker>{TrackerN}/devicePose: Tracker N's pose.
- <ViveXRTracker>{TrackerN}/isTracked: Tracker N's pose is tracked.
- <ViveXRTracker>{TrackerN}/trackingState: Tracker N's tracking state.
- <ViveXRTracker>{TrackerN}/devicePosition: Tracker N's position.
- <ViveXRTracker>{TrackerN}/deviceRotation: Tracker N's rotation.
Refer to the <Vive XR OpenXR sample path>/Toolkits/Commons/ActionMap/InputActions.inputActions about the "Input Action Path" usage and the sample <Vive XR OpenXR sample path>/Toolkits/Input/OpenXRInput.unity.

View File

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

View File

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

View File

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