From b7ffbfdc6c6e0026f792b791b8be94d5748b74e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Fejzagi=C4=87?= Date: Tue, 22 Sep 2020 14:16:52 +0200 Subject: [PATCH] Add support for input and gestures for hand controllers (#72) * updated wmr controller data provider * removed commented out class * added controller data provider reference to the controller * updated references * fixed references * Added default controller definitions * updated the controller data provider inspector fixed naming for controller definition * updated hand data provider profile inspector * removed redundant inspector * cleaned up the controller interaction mappings a bit * updated references * updated controller instance creation * added default constructor * updated TryRenderController method * removed asset menu * fixed compiler error * Remove obsolete SetupDefaultIntreactions (#65) * updated reference * added WMR Camera Data Provider * updated WMR Camera Data Provider * updated camera rig reference * updated icon * moved WMR Camera data provider into correct file location * updated data provider constructors * added service parent reference * Change requests for controller provider inspectors (#67) * Update indent levels for WMR settings * Cache GUIContent * Adjust WMR to recent core changes * Update due to rename * Cleanup usings * Added rig reset override * reverted changes * removed unused reference * added camera profile * Updated windows controller type name to get the controller textures to show up correctly based on the type name * fixed reference to renamed controller class * fixed more type references * Resolve merge issues * Reset some unrelated file changes * Fix namespace * Moved WMR hand data provider profile asset * Fix WMR namespace compiler error * Cleanup namespace * Move default wmr data provider profile from SDK * Update profile references * Introduce hand rendering mode * Implement runtime rendering mode switch * Update converter to define platform capabilities * Update wmr to use post processor * Fix build errors due to removal of base converter * Rename joints * Point to new hand controller profiles * Pass handedness to pose recognizer * Fix build errors * Update WMR converter to latest changes * Update wmr hand data provider * Temp update WindowsApiChecker * Fix joint-root offset calculation * Finally fix freaking joint conversion * Cleanup code * Commit new controller GUIDs * Implement pointer pose override for WMR platform * Remove DOTNETWINRT_PRESENT usage Co-authored-by: Stephen Hodgson --- ...owsMixedRealityCameraProviderProfile.asset | 2 +- .../WindowsMixedRealityController.meta | 8 + .../WindowsMixedRealityController/Left.meta | 2 +- .../Left/GripPressProfile.asset.meta | 2 +- .../Left/InvertDualAxisProcessor.asset.meta | 2 +- .../Left/MenuPressProfile.asset.meta | 2 +- .../Left/SpatialGripProfile.asset.meta | 2 +- .../Left/SpatialPointerProfile.asset.meta | 2 +- .../Left/ThumbstickClickProfile.asset.meta | 2 +- .../Left/ThumbstickPositionProfile.asset.meta | 2 +- .../Left/TouchpadPositionProfile.asset.meta | 2 +- .../Left/TouchpadPressProfile.asset.meta | 2 +- .../Left/TouchpadTouchProfile.asset.meta | 2 +- .../Left/TriggerPositionProfile.asset.meta | 2 +- .../TriggerPress(Select)Profile.asset.meta | 2 +- .../Left/TriggerTouchProfile.asset.meta | 2 +- .../Left/TriggerTouchedProfile.asset.meta | 2 +- .../WindowsMixedRealityController/Right.meta | 2 +- .../Right/GripPressProfile.asset.meta | 2 +- .../Right/InvertDualAxisProcessor.asset.meta | 2 +- .../Right/MenuPressProfile.asset.meta | 2 +- .../Right/SpatialGripProfile.asset.meta | 2 +- .../Right/SpatialPointerProfile.asset.meta | 2 +- .../Right/ThumbstickClickProfile.asset.meta | 2 +- .../ThumbstickPositionProfile.asset.meta | 2 +- .../Right/TouchpadPositionProfile.asset.meta | 2 +- .../Right/TouchpadPressProfile.asset.meta | 2 +- .../Right/TouchpadTouchProfile.asset.meta | 2 +- .../Right/TriggerPositionProfile.asset.meta | 2 +- .../TriggerPress(Select)Profile.asset.meta | 2 +- .../Right/TriggerTouchProfile.asset.meta | 2 +- .../Right/TriggerTouchedProfile.asset.meta | 2 +- ...RealityControllerDataProviderProfile.asset | 2 +- ...ityHandControllerDataProviderProfile.asset | 7 +- .../Extensions/HandJointKindExtensions.cs | 37 +- .../Extensions/InteractionSourceExtensions.cs | 16 +- ...ndowsMixedRealityControllerDataProvider.cs | 18 +- ...sMixedRealityHandControllerDataProvider.cs | 93 +++-- .../Runtime/Utilities/WindowsApiChecker.cs | 91 ++--- .../WindowsMixedRealityHandDataConverter.cs | 350 +++++++++++++----- ...ndowsMixedRealityHandDataConverter.cs.meta | 2 +- 41 files changed, 437 insertions(+), 249 deletions(-) create mode 100644 XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController.meta diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/CameraSystem/WindowsMixedRealityCameraProviderProfile.asset b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/CameraSystem/WindowsMixedRealityCameraProviderProfile.asset index b2c53a0..ac1cba3 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/CameraSystem/WindowsMixedRealityCameraProviderProfile.asset +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/CameraSystem/WindowsMixedRealityCameraProviderProfile.asset @@ -17,7 +17,7 @@ MonoBehaviour: cameraClearFlagsOpaqueDisplay: 1 backgroundColorOpaqueDisplay: {r: 0, g: 0, b: 0, a: 1} opaqueQualityLevel: 0 - nearClipPlaneTransparentDisplay: 0.2 + nearClipPlaneTransparentDisplay: 0.05 cameraClearFlagsTransparentDisplay: 2 backgroundColorTransparentDisplay: {r: 0, g: 0, b: 0, a: 0} transparentQualityLevel: 0 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController.meta new file mode 100644 index 0000000..7fe0835 --- /dev/null +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 94af4f07a9a69dc4ba11073dc9267ed9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left.meta index 968aa69..b8445d5 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e5d2741f23dcb3c49b091a09fc40dbc0 +guid: e556001044e780a43b929eb51ae23944 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/GripPressProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/GripPressProfile.asset.meta index da3580c..d4a3106 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/GripPressProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/GripPressProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7e4ecf81e5712754c8d245537978d758 +guid: 4cde54435873b4649b69d7f5c77e5fe0 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/InvertDualAxisProcessor.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/InvertDualAxisProcessor.asset.meta index d91c46d..5821931 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/InvertDualAxisProcessor.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/InvertDualAxisProcessor.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2158a760049510f429c34a8e131a1e69 +guid: 31f74fdbae4feb14fa28be1dd9378cef NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/MenuPressProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/MenuPressProfile.asset.meta index dff31d5..f263500 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/MenuPressProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/MenuPressProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8374fc38e78c9174f812db35adecc959 +guid: 939aa56150ed8a348b53e8636d4edf7a NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialGripProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialGripProfile.asset.meta index be86160..9863b4a 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialGripProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialGripProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b10b88729da78e243b99b30e15b3f810 +guid: bbf83b0f6936bdf40b55fc01d191c970 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialPointerProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialPointerProfile.asset.meta index f349025..d5481f3 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialPointerProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/SpatialPointerProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4eabae8f23a506948894ceab3ed56bed +guid: 669d97502770bc241ac25834fa793d8b NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickClickProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickClickProfile.asset.meta index 57842db..e3b3fa1 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickClickProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickClickProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f19cadd37dae8c7449b4bf2a9ec8f262 +guid: 7229007b181ce2c49b64a1cbef700c9c NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickPositionProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickPositionProfile.asset.meta index 127a897..1ae96c2 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickPositionProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/ThumbstickPositionProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2394acc9efbc4a649bbc8a4af8279a85 +guid: 55cf4c87b304d984cb995fad4018170d NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPositionProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPositionProfile.asset.meta index edd4b68..bdb1e91 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPositionProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPositionProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2e61fbdb1f55b0146a52033f2ebbfbff +guid: 22a2efc24b920ad4cbcbee8b6e65ac66 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPressProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPressProfile.asset.meta index 19883b9..31a4a2a 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPressProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadPressProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3070249a19481544a88c8edb12bdb4f1 +guid: 1884d4e0b33e32d42b5731289987b2de NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadTouchProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadTouchProfile.asset.meta index 364823b..8fffb50 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadTouchProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TouchpadTouchProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 49266328add1c764e8b882e1e9bb89d4 +guid: e8f950a1a00bbc14e9a42deae23de196 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPositionProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPositionProfile.asset.meta index 17604e9..7fecbb5 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPositionProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPositionProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c6849f14c4d742d4e918c4ce1bf2b4b4 +guid: dc9d8c00038c2d84dbea53fc8935af15 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPress(Select)Profile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPress(Select)Profile.asset.meta index 353ff1f..482f280 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPress(Select)Profile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerPress(Select)Profile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f244c21bf0106a64a903950d2fbd60f9 +guid: d08f6946e2676bb4389eaa9fec6f1267 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchProfile.asset.meta index 1e47474..3f0539d 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cb57613c9a29a204a9e53a5f084d876b +guid: 9133bba4e3a8d0e42864e49a5f6e3416 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchedProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchedProfile.asset.meta index 4dea359..5e35506 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchedProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Left/TriggerTouchedProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 20ebd784cd7d33c4c8e046ad905f8fd6 +guid: 4740f843e007bc244aa4ee60fe62e49d NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right.meta index eac945f..4a2ef50 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7b6c25febbe774f4c808d5b48d138001 +guid: 0bfd33d5f032e0d4da10d7a85399006c folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/GripPressProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/GripPressProfile.asset.meta index 40391c0..8d6a661 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/GripPressProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/GripPressProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 57cf8e3c0f0470e418fee2c4919c460a +guid: a74a73b1c5abdb049a73a9b44b0b2e98 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/InvertDualAxisProcessor.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/InvertDualAxisProcessor.asset.meta index 15898eb..4a2a13d 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/InvertDualAxisProcessor.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/InvertDualAxisProcessor.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9c40de59f43b08245b4e74f7dc6b14bc +guid: 936774fa4f963834a8f2417be8b8d9c1 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/MenuPressProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/MenuPressProfile.asset.meta index 59bcb22..5ff34eb 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/MenuPressProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/MenuPressProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4c6a577ebcde56343807fd5d3c50dd77 +guid: 6b662c7eddb36704581ea73260d9ed0c NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialGripProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialGripProfile.asset.meta index 746b9ba..0494599 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialGripProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialGripProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ee806d7f585c7c34295c77499684b046 +guid: ef9ee042babf1684cbaf525774f40d9d NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialPointerProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialPointerProfile.asset.meta index e394795..1dea9ef 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialPointerProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/SpatialPointerProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2383d0f88b769e842b742f8a8b099c6d +guid: eb4fddd7eb87b124f841b007e0f01ae5 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickClickProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickClickProfile.asset.meta index f0bf02e..b4ddc09 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickClickProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickClickProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 72cf9cede81a0d6469e667e7f9f4d627 +guid: f6de46af1ba79f241847d39062c2bb6e NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickPositionProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickPositionProfile.asset.meta index 6044ce2..2d9d545 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickPositionProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/ThumbstickPositionProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1b5e85d560958ac4f8c261cc0700fe68 +guid: 7ee0442e6d1cead47a8e89301c4d343f NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPositionProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPositionProfile.asset.meta index 9c240ac..67fdb62 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPositionProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPositionProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 02554fe515e77724899f40f0f966b7f0 +guid: 171ce182a979c7f4896da13d78d014fe NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPressProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPressProfile.asset.meta index afe0997..58609c7 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPressProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadPressProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f5364f5a5cacf724eb351a12b08175fc +guid: 61ea3544727361e418900f4806d00403 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadTouchProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadTouchProfile.asset.meta index 3f9c4ef..ebbf6f6 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadTouchProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TouchpadTouchProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4719f6b4b88c2f24cb711ef28f16b7ee +guid: e2dbd828dced4f14eba72f7870e73bba NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPositionProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPositionProfile.asset.meta index 36b380d..b94619a 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPositionProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPositionProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 38db213a242a3864dbb2410d676c2324 +guid: 9ebeb5e994087954bb05781c9c477f3e NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPress(Select)Profile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPress(Select)Profile.asset.meta index bdfd1ca..75dc746 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPress(Select)Profile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerPress(Select)Profile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: be34017cfd537b94cbeab39839f72881 +guid: 0f2de0b794676bd4c9615ec012cd4457 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchProfile.asset.meta index 4e8bd41..e6f9996 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cba0ece867acec34eb29efc6f74dc7ff +guid: c6ad2eb197ef03f4588c20d33cbb7bc4 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchedProfile.asset.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchedProfile.asset.meta index 1d3641f..0149eea 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchedProfile.asset.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityController/Right/TriggerTouchedProfile.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6b556181d2b71654486e12acfeaf4c70 +guid: 0d36a94dafc81494c90b9c942153d142 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityControllerDataProviderProfile.asset b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityControllerDataProviderProfile.asset index d2e4007..594ac75 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityControllerDataProviderProfile.asset +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityControllerDataProviderProfile.asset @@ -11,7 +11,7 @@ MonoBehaviour: m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: fe9eeb08f95b1c1419ad17953d9a48ee, type: 3} m_Name: WindowsMixedRealityControllerDataProviderProfile - m_EditorClassIdentifier: + m_EditorClassIdentifier: hasSetupDefaults: 1 controllerMappingProfiles: - {fileID: 11400000, guid: aaa9b82b55ce7834bb43c9d726ff893e, type: 2} diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityHandControllerDataProviderProfile.asset b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityHandControllerDataProviderProfile.asset index 510a1c6..2201dbc 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityHandControllerDataProviderProfile.asset +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Profiles~/Contollers/WindowsMixedRealityHandControllerDataProviderProfile.asset @@ -14,9 +14,10 @@ MonoBehaviour: m_EditorClassIdentifier: hasSetupDefaults: 1 controllerMappingProfiles: - - {fileID: 11400000, guid: b43ff1b6f37e65946b1abc7e50af105f, type: 2} - - {fileID: 11400000, guid: 6c775257f26873e459a492f28125e129, type: 2} - handMeshingEnabled: 0 + - {fileID: 11400000, guid: dd499836e4b82f14da2f414aad1fed8b, type: 2} + - {fileID: 11400000, guid: 78bf44d2b6970a74ea2721883b0b22bc, type: 2} + renderingMode: 1 handPhysicsEnabled: 0 useTriggers: 0 boundsMode: 0 + trackedPoses: [] diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/HandJointKindExtensions.cs b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/HandJointKindExtensions.cs index 15e261f..caae038 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/HandJointKindExtensions.cs +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/HandJointKindExtensions.cs @@ -3,6 +3,7 @@ #if WINDOWS_UWP +using System; using Windows.Perception.People; using XRTK.Definitions.Controllers.Hands; @@ -18,36 +19,36 @@ public static TrackedHandJoint ToTrackedHandJoint(this HandJointKind handJointKi case HandJointKind.Wrist: return TrackedHandJoint.Wrist; - case HandJointKind.ThumbMetacarpal: return TrackedHandJoint.ThumbMetacarpalJoint; - case HandJointKind.ThumbProximal: return TrackedHandJoint.ThumbProximalJoint; - case HandJointKind.ThumbDistal: return TrackedHandJoint.ThumbDistalJoint; + case HandJointKind.ThumbMetacarpal: return TrackedHandJoint.ThumbMetacarpal; + case HandJointKind.ThumbProximal: return TrackedHandJoint.ThumbProximal; + case HandJointKind.ThumbDistal: return TrackedHandJoint.ThumbDistal; case HandJointKind.ThumbTip: return TrackedHandJoint.ThumbTip; case HandJointKind.IndexMetacarpal: return TrackedHandJoint.IndexMetacarpal; - case HandJointKind.IndexProximal: return TrackedHandJoint.IndexKnuckle; - case HandJointKind.IndexIntermediate: return TrackedHandJoint.IndexMiddleJoint; - case HandJointKind.IndexDistal: return TrackedHandJoint.IndexDistalJoint; + case HandJointKind.IndexProximal: return TrackedHandJoint.IndexProximal; + case HandJointKind.IndexIntermediate: return TrackedHandJoint.IndexIntermediate; + case HandJointKind.IndexDistal: return TrackedHandJoint.IndexDistal; case HandJointKind.IndexTip: return TrackedHandJoint.IndexTip; case HandJointKind.MiddleMetacarpal: return TrackedHandJoint.MiddleMetacarpal; - case HandJointKind.MiddleProximal: return TrackedHandJoint.MiddleKnuckle; - case HandJointKind.MiddleIntermediate: return TrackedHandJoint.MiddleMiddleJoint; - case HandJointKind.MiddleDistal: return TrackedHandJoint.MiddleDistalJoint; + case HandJointKind.MiddleProximal: return TrackedHandJoint.MiddleProximal; + case HandJointKind.MiddleIntermediate: return TrackedHandJoint.MiddleIntermediate; + case HandJointKind.MiddleDistal: return TrackedHandJoint.MiddleDistal; case HandJointKind.MiddleTip: return TrackedHandJoint.MiddleTip; case HandJointKind.RingMetacarpal: return TrackedHandJoint.RingMetacarpal; - case HandJointKind.RingProximal: return TrackedHandJoint.RingKnuckle; - case HandJointKind.RingIntermediate: return TrackedHandJoint.RingMiddleJoint; - case HandJointKind.RingDistal: return TrackedHandJoint.RingDistalJoint; + case HandJointKind.RingProximal: return TrackedHandJoint.RingProximal; + case HandJointKind.RingIntermediate: return TrackedHandJoint.RingIntermediate; + case HandJointKind.RingDistal: return TrackedHandJoint.RingDistal; case HandJointKind.RingTip: return TrackedHandJoint.RingTip; - case HandJointKind.LittleMetacarpal: return TrackedHandJoint.PinkyMetacarpal; - case HandJointKind.LittleProximal: return TrackedHandJoint.PinkyKnuckle; - case HandJointKind.LittleIntermediate: return TrackedHandJoint.PinkyMiddleJoint; - case HandJointKind.LittleDistal: return TrackedHandJoint.PinkyDistalJoint; - case HandJointKind.LittleTip: return TrackedHandJoint.PinkyTip; + case HandJointKind.LittleMetacarpal: return TrackedHandJoint.LittleMetacarpal; + case HandJointKind.LittleProximal: return TrackedHandJoint.LittleProximal; + case HandJointKind.LittleIntermediate: return TrackedHandJoint.LittleIntermediate; + case HandJointKind.LittleDistal: return TrackedHandJoint.LittleDistal; + case HandJointKind.LittleTip: return TrackedHandJoint.LittleTip; - default: return TrackedHandJoint.None; + default: throw new ArgumentOutOfRangeException($"{typeof(HandJointKind).Name}.{handJointKind} could not be mapped to {typeof(TrackedHandJoint).Name}"); } } } diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/InteractionSourceExtensions.cs b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/InteractionSourceExtensions.cs index d94376d..5d3eab0 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/InteractionSourceExtensions.cs +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Extensions/InteractionSourceExtensions.cs @@ -42,7 +42,13 @@ public static void StartHaptics(this InteractionSource interactionSource, float public static void StartHaptics(this InteractionSource interactionSource, float intensity, float durationInSeconds) { - if (!WindowsApiChecker.UniversalApiContractV4_IsAvailable && !Application.isEditor) + // GetForCurrentView and GetDetectedSourcesAtTimestamp were both introduced in the same Windows version. + // We need only check for one of them. + if ((!WindowsApiChecker.IsMethodAvailable( + "Windows.UI.Input.Spatial", + "SpatialInteractionManager", + "GetForCurrentView") || + !WindowsApiChecker.IsTypeAvailable("Windows.Devices.Haptics", "SimpleHapticsController")) && !Application.isEditor) { return; } @@ -82,7 +88,13 @@ public static void StartHaptics(this InteractionSource interactionSource, float public static void StopHaptics(this InteractionSource interactionSource) { - if (!WindowsApiChecker.UniversalApiContractV4_IsAvailable && !Application.isEditor) + // GetForCurrentView and GetDetectedSourcesAtTimestamp were both introduced in the same Windows version. + // We need only check for one of them. + if ((!WindowsApiChecker.IsMethodAvailable( + "Windows.UI.Input.Spatial", + "SpatialInteractionManager", + "GetForCurrentView") || + !WindowsApiChecker.IsTypeAvailable("Windows.Devices.Haptics", "SimpleHapticsController")) && !Application.isEditor) { return; } diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityControllerDataProvider.cs b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityControllerDataProvider.cs index 752e3b2..b7f57e1 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityControllerDataProvider.cs +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityControllerDataProvider.cs @@ -440,10 +440,24 @@ private WindowsMixedRealityMotionController GetController(InteractionSource inte private static async void TryRenderControllerModel(InteractionSource interactionSource, WindowsMixedRealityMotionController controller) { #if WINDOWS_UWP - if (!UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque) { return; } + if (!UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque) + { + return; + } + IRandomAccessStreamWithContentType stream = null; - if (!WindowsApiChecker.UniversalApiContractV5_IsAvailable) { return; } + if (!WindowsApiChecker.IsMethodAvailable( + "Windows.UI.Input.Spatial", + "SpatialInteractionManager", + "GetForCurrentView") || + !WindowsApiChecker.IsMethodAvailable( + "Windows.UI.Input.Spatial", + "SpatialInteractionController", + "TryGetRenderableModelAsync")) + { + return; + } await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, DispatchedHandler); diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityHandControllerDataProvider.cs b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityHandControllerDataProvider.cs index aa1f4db..f2c6a65 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityHandControllerDataProvider.cs +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Providers/Controllers/WindowsMixedRealityHandControllerDataProvider.cs @@ -6,6 +6,7 @@ using XRTK.Interfaces.InputSystem; using XRTK.Providers.Controllers.Hands; using XRTK.WindowsMixedReality.Profiles; +using XRTK.WindowsMixedReality.Utilities; #if WINDOWS_UWP @@ -16,10 +17,10 @@ using Windows.Perception; using Windows.UI.Input.Spatial; using XRTK.Definitions.Devices; -using XRTK.Definitions.Utilities; using XRTK.Services; using XRTK.WindowsMixedReality.Extensions; -using XRTK.WindowsMixedReality.Utilities; +using XRTK.Definitions.Controllers.Hands; +using XRTK.Definitions.Utilities; #endif // WINDOWS_UWP @@ -37,11 +38,18 @@ public class WindowsMixedRealityHandControllerDataProvider : BaseHandControllerD public WindowsMixedRealityHandControllerDataProvider(string name, uint priority, WindowsMixedRealityHandControllerDataProviderProfile profile, IMixedRealityInputSystem parentService) : base(name, priority, profile, parentService) { + handDataProvider = new WindowsMixedRealityHandDataConverter(); + postProcessor = new HandDataPostProcessor(TrackedPoses) + { + PlatformProvidesPointerPose = true + }; } + private readonly WindowsMixedRealityHandDataConverter handDataProvider; + private readonly HandDataPostProcessor postProcessor; + #if WINDOWS_UWP - private readonly WindowsMixedRealityHandDataConverter handDataConverter = new WindowsMixedRealityHandDataConverter(); private readonly Dictionary activeControllers = new Dictionary(); private SpatialInteractionManager spatialInteractionManager = null; @@ -68,62 +76,41 @@ private SpatialInteractionManager SpatialInteractionManager #region IMixedRealityControllerDataProvider lifecycle implementation - /// - public override void Initialize() - { - base.Initialize(); - WindowsMixedRealityHandDataConverter.HandMeshingEnabled = HandMeshingEnabled; - } - /// public override void Update() { base.Update(); - // Update existing controllers or create a new one if needed. - var sources = GetCurrentSources(); - - if (sources == null) - { - return; - } - bool isLeftHandTracked = false; bool isRightHandTracked = false; - for (int i = 0; i < sources.Count; i++) + if (TryGetCurrentHandSources(out var sources)) { - var sourceState = sources[i]; - var spatialInteractionSource = sourceState.Source; - - if (spatialInteractionSource.Handedness == SpatialInteractionSourceHandedness.Left) + for (int i = 0; i < sources.Count; i++) { - isLeftHandTracked = true; + var sourceState = sources[i]; + var spatialInteractionSource = sourceState.Source; + var handedness = spatialInteractionSource.Handedness.ToHandedness(); - if (TryGetController(spatialInteractionSource.Handedness.ToHandedness(), out var leftHandController)) + if (!TryGetController(handedness, out MixedRealityHandController controller)) { - leftHandController.UpdateController(handDataConverter.GetHandData(sourceState)); + controller = CreateController(spatialInteractionSource); } - else - { - leftHandController = CreateController(spatialInteractionSource); - leftHandController.UpdateController(handDataConverter.GetHandData(sourceState)); - } - } - if (spatialInteractionSource.Handedness == SpatialInteractionSourceHandedness.Right) - { - isRightHandTracked = true; - - if (TryGetController(spatialInteractionSource.Handedness.ToHandedness(), out var rightHandController)) - { - rightHandController.UpdateController(handDataConverter.GetHandData(sourceState)); - } - else + if (handDataProvider.TryGetHandData(sourceState, RenderingMode == HandRenderingMode.Mesh, out var handData)) { - rightHandController = CreateController(spatialInteractionSource); - rightHandController.UpdateController(handDataConverter.GetHandData(sourceState)); + if (handedness == Handedness.Left) + { + isLeftHandTracked = true; + } + else if (handedness == Handedness.Right) + { + isRightHandTracked = true; + } } + + handData = postProcessor.PostProcess(handedness, handData); + controller.UpdateController(handData); } } @@ -159,23 +146,31 @@ public override void Disable() /// Reads currently detected input sources by the current instance. /// /// List of sources. Can be null. - private IReadOnlyList GetCurrentSources() + private bool TryGetCurrentHandSources(out IReadOnlyList sources) { // Articulated hand support is only present in the 18362 version and beyond Windows // SDK (which contains the V8 drop of the Universal API Contract). In particular, // the HandPose related APIs are only present on this version and above. - if (XRTK.WindowsMixedReality.Utilities.WindowsApiChecker.UniversalApiContractV8_IsAvailable && SpatialInteractionManager != null) + // GetForCurrentView and GetDetectedSourcesAtTimestamp were both introduced in the same Windows version. + // We need only check for one of them. + if (WindowsApiChecker.IsMethodAvailable( + "Windows.UI.Input.Spatial", + "SpatialInteractionManager", + "GetForCurrentView") && + SpatialInteractionManager != null) { var perceptionTimestamp = PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now); - var sources = SpatialInteractionManager.GetDetectedSourcesAtTimestamp(perceptionTimestamp); + var allSources = SpatialInteractionManager.GetDetectedSourcesAtTimestamp(perceptionTimestamp); - if (sources != null) + if (allSources != null) { - return sources.Where(s => s.Source.Kind == SpatialInteractionSourceKind.Hand).ToList(); + sources = allSources.Where(s => s.Source.Kind == SpatialInteractionSourceKind.Hand).ToList(); + return true; } } - return null; + sources = null; + return false; } private bool TryGetController(Handedness handedness, out MixedRealityHandController controller) diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsApiChecker.cs b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsApiChecker.cs index 965e94c..34b3276 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsApiChecker.cs +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsApiChecker.cs @@ -1,65 +1,72 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using UnityEngine; +#if WINDOWS_UWP +using Windows.Foundation.Metadata; +#endif // WINDOWS_UWP namespace XRTK.WindowsMixedReality.Utilities { /// /// Helper class for determining if a Windows API contract is available. /// - /// See https://docs.microsoft.com/en-us/uwp/extension-sdks/windows-universal-sdk + /// See https://docs.microsoft.com/uwp/extension-sdks/windows-universal-sdk /// for a full list of contracts. public static class WindowsApiChecker { - [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] - public static void CheckApiContracts() + /// + /// Checks to see if the requested method is present on the current platform. + /// + /// The namespace (ex: "Windows.UI.Input.Spatial") containing the class. + /// The name of the class containing the method (ex: "SpatialInteractionMananger"). + /// The name of the method (ex: "IsSourceKindSupported"). + /// True if the method is available and can be called. Otherwise, false. + public static bool IsMethodAvailable( + string namespaceName, + string className, + string methodName) { #if WINDOWS_UWP - UniversalApiContractV8_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent(nameof(Windows.Foundation.UniversalApiContract), 8); - UniversalApiContractV7_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent(nameof(Windows.Foundation.UniversalApiContract), 7); - UniversalApiContractV6_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent(nameof(Windows.Foundation.UniversalApiContract), 6); - UniversalApiContractV5_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent(nameof(Windows.Foundation.UniversalApiContract), 5); - UniversalApiContractV4_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent(nameof(Windows.Foundation.UniversalApiContract), 4); - UniversalApiContractV3_IsAvailable = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent(nameof(Windows.Foundation.UniversalApiContract), 3); + return ApiInformation.IsMethodPresent($"{namespaceName}.{className}", methodName); #else - UniversalApiContractV8_IsAvailable = false; - UniversalApiContractV7_IsAvailable = false; - UniversalApiContractV6_IsAvailable = false; - UniversalApiContractV5_IsAvailable = false; - UniversalApiContractV4_IsAvailable = false; - UniversalApiContractV3_IsAvailable = false; -#endif + return false; +#endif // WINDOWS_UWP } /// - /// Is the Universal API Contract v8.0 Available? - /// - public static bool UniversalApiContractV8_IsAvailable { get; private set; } - - /// - /// Is the Universal API Contract v7.0 Available? - /// - public static bool UniversalApiContractV7_IsAvailable { get; private set; } - - /// - /// Is the Universal API Contract v6.0 Available? - /// - public static bool UniversalApiContractV6_IsAvailable { get; private set; } - - /// - /// Is the Universal API Contract v5.0 Available? + /// Checks to see if the requested property is present on the current platform. /// - public static bool UniversalApiContractV5_IsAvailable { get; private set; } - - /// - /// Is the Universal API Contract v4.0 Available? - /// - public static bool UniversalApiContractV4_IsAvailable { get; private set; } + /// The namespace (ex: "Windows.UI.Input.Spatial") containing the class. + /// The name of the class containing the method (ex: "SpatialPointerPose"). + /// The name of the method (ex: "Eyes"). + /// True if the property is available and can be called. Otherwise, false. + public static bool IsPropertyAvailable( + string namespaceName, + string className, + string propertyName) + { +#if WINDOWS_UWP + return ApiInformation.IsPropertyPresent($"{namespaceName}.{className}", propertyName); +#else + return false; +#endif // WINDOWS_UWP + } /// - /// Is the Universal API Contract v3.0 Available? + /// Checks to see if the requested type is present on the current platform. /// - public static bool UniversalApiContractV3_IsAvailable { get; private set; } + /// The namespace (ex: "Windows.UI.Input.Spatial") containing the class. + /// The name of the class containing the method (ex: "SpatialPointerPose"). + /// True if the type is available and can be called. Otherwise, false. + public static bool IsTypeAvailable( + string namespaceName, + string typeName) + { +#if WINDOWS_UWP + return ApiInformation.IsTypePresent($"{namespaceName}.{typeName}"); +#else + return false; +#endif // WINDOWS_UWP + } } -} +} \ No newline at end of file diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs index 933c883..58c9db2 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs @@ -1,6 +1,8 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using XRTK.Definitions.Controllers.Hands; + #if WINDOWS_UWP using System; @@ -8,27 +10,39 @@ using UnityEngine; using Windows.Perception.People; using Windows.UI.Input.Spatial; -using XRTK.Definitions.Controllers.Hands; -using XRTK.Definitions.Utilities; -using XRTK.Extensions; using XRTK.Services; using XRTK.WindowsMixedReality.Extensions; +using XRTK.Extensions; +using XRTK.Definitions.Devices; +using XRTK.Definitions.Utilities; + +#endif // WINDOWS_UWP namespace XRTK.WindowsMixedReality.Utilities { /// - /// Converts windows mixed reality hand data to . + /// Converts windows mixed reality hand data to XRTK's . /// public sealed class WindowsMixedRealityHandDataConverter { +#if WINDOWS_UWP + /// - /// Gets or sets whether hand mesh data should be read and converted. + /// Destructor. /// - public static bool HandMeshingEnabled { get; set; } + ~WindowsMixedRealityHandDataConverter() + { + if (!conversionProxyRootTransform.IsNull()) + { + conversionProxyTransforms.Clear(); + conversionProxyRootTransform.Destroy(); + } + } - private readonly Vector3[] unityJointPositions = new Vector3[jointIndices.Length]; - private readonly Quaternion[] unityJointOrientations = new Quaternion[jointIndices.Length]; + private Transform conversionProxyRootTransform; + private readonly Dictionary conversionProxyTransforms = new Dictionary(); private readonly Dictionary handMeshObservers = new Dictionary(); + private readonly MixedRealityPose[] jointPoses = new MixedRealityPose[HandData.JointCount]; private int[] handMeshTriangleIndices = null; private bool hasRequestedHandMeshObserverLeftHand = false; @@ -69,116 +83,228 @@ public sealed class WindowsMixedRealityHandDataConverter /// Gets updated hand data for the current frame. /// /// Platform provided current input source state for the hand. - /// Platform agnostics hand data. - public HandData GetHandData(SpatialInteractionSourceState spatialInteractionSourceState) + /// If set, hand mesh information will be included in . + /// The output . + /// True, if data conversion was a success. + public bool TryGetHandData(SpatialInteractionSourceState spatialInteractionSourceState, bool includeMeshData, out HandData handData) { + // Here we check whether the hand is being tracked at all by the WMR system. HandPose handPose = spatialInteractionSourceState.TryGetHandPose(); - HandData updatedHandData = new HandData + if (handPose == null) + { + handData = default; + return false; + } + + // The hand is being tracked, next we verify it meets our confidence requirements to consider + // it tracked. + var platformJointPoses = new JointPose[jointIndices.Length]; + handData = new HandData { - IsTracked = handPose != null, - TimeStamp = DateTimeOffset.UtcNow.Ticks + TrackingState = handPose.TryGetJoints(WindowsMixedRealityUtilities.SpatialCoordinateSystem, jointIndices, platformJointPoses) ? TrackingState.Tracked : TrackingState.NotTracked, + UpdatedAt = DateTimeOffset.UtcNow.Ticks }; - if (updatedHandData.IsTracked) + // If the hand is tracked per requirements, we get updated joint data + // and other data needed for updating the hand controller's state. + if (handData.TrackingState == TrackingState.Tracked) { - // Accessing the hand mesh data involves copying quite a bit of data, so only do it if application requests it. - if (HandMeshingEnabled) - { - if (!handMeshObservers.ContainsKey(spatialInteractionSourceState.Source.Handedness) && - !HasRequestedHandMeshObserver(spatialInteractionSourceState.Source.Handedness)) - { - SetHandMeshObserver(spatialInteractionSourceState); - } + handData.RootPose = GetHandRootPose(platformJointPoses); + handData.Joints = GetJointPoses(platformJointPoses, handData.RootPose); + handData.PointerPose = GetPointerPose(spatialInteractionSourceState); - if (handMeshObservers.TryGetValue(spatialInteractionSourceState.Source.Handedness, out var handMeshObserver) && handMeshTriangleIndices == null) + if (includeMeshData && TryGetUpdatedHandMeshData(spatialInteractionSourceState, handPose, out HandMeshData data)) + { + handData.Mesh = data; + } + else + { + // if hand mesh visualization is disabled make sure to destroy our hand mesh observer + // if it has already been created. + if (handMeshObservers.ContainsKey(spatialInteractionSourceState.Source.Handedness)) { - var indexCount = handMeshObserver.TriangleIndexCount; - var indices = new ushort[indexCount]; - handMeshObserver.GetTriangleIndices(indices); - handMeshTriangleIndices = new int[indexCount]; - Array.Copy(indices, handMeshTriangleIndices, (int)handMeshObserver.TriangleIndexCount); - - // Compute neutral pose - var neutralPoseVertices = new Vector3[handMeshObserver.VertexCount]; - var neutralPose = handMeshObserver.NeutralPose; - var vertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; - var handMeshVertexState = handMeshObserver.GetVertexStateForPose(neutralPose); - handMeshVertexState.GetVertices(vertexAndNormals); - - for (int i = 0; i < handMeshObserver.VertexCount; i++) + if (spatialInteractionSourceState.Source.Handedness == SpatialInteractionSourceHandedness.Left) { - neutralPoseVertices[i] = vertexAndNormals[i].Position.ToUnity(); + hasRequestedHandMeshObserverLeftHand = false; } - - // Compute UV mapping - InitializeHandMeshUVs(neutralPoseVertices); - } - - if (handMeshObserver != null && handMeshTriangleIndices != null) - { - var vertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; - var handMeshVertexState = handMeshObserver.GetVertexStateForPose(handPose); - handMeshVertexState.GetVertices(vertexAndNormals); - - var meshTransform = handMeshVertexState.CoordinateSystem.TryGetTransformTo(WindowsMixedRealityUtilities.SpatialCoordinateSystem); - if (meshTransform.HasValue) + else if (spatialInteractionSourceState.Source.Handedness == SpatialInteractionSourceHandedness.Right) { - System.Numerics.Matrix4x4.Decompose(meshTransform.Value, out var scale, out var rotation, out var translation); - - var handMeshVertices = new Vector3[handMeshObserver.VertexCount]; - var handMeshNormals = new Vector3[handMeshObserver.VertexCount]; - - for (int i = 0; i < handMeshObserver.VertexCount; i++) - { - handMeshVertices[i] = vertexAndNormals[i].Position.ToUnity(); - handMeshNormals[i] = vertexAndNormals[i].Normal.ToUnity(); - } - - updatedHandData.Mesh = new HandMeshData( - handMeshVertices, - handMeshTriangleIndices, - handMeshNormals, - handMeshUVs, - translation.ToUnity(), - rotation.ToUnity()); + hasRequestedHandMeshObserverRightHand = false; } + + handMeshObservers.Remove(spatialInteractionSourceState.Source.Handedness); } + + handData.Mesh = HandMeshData.Empty; } - else if (handMeshObservers.ContainsKey(spatialInteractionSourceState.Source.Handedness)) + } + + // Even if the hand is being tracked by the system but the confidence did not + // meet our requirements, we return true. This allows the hand controller and visualizers + // to react to tracking loss and keep the hand up for a given time before destroying the controller. + return true; + } + + /// + /// Gets updated joint s for all s of a hand. + /// + /// s retrieved from the platform. + /// The hand's root . + /// Joint s in ascending order. + private MixedRealityPose[] GetJointPoses(JointPose[] platformJointPoses, MixedRealityPose handRootPose) + { + for (int i = 0; i < platformJointPoses.Length; i++) + { + var handJoint = jointIndices[i].ToTrackedHandJoint(); + jointPoses[(int)handJoint] = GetJointPose(handJoint, handRootPose, platformJointPoses[i]); + } + + return jointPoses; + } + + /// + /// Gets a single joint's relative to the hand root pose. + /// + /// The Id for the joint to get a for. + /// The hand's root . Joint poses are always relative to the root pose. + /// retrieved from the platform. + /// Joint relative to the hand's root pose. + private MixedRealityPose GetJointPose(TrackedHandJoint trackedHandJoint, MixedRealityPose handRootPose, JointPose jointPose) + { + var jointTransform = GetProxyTransform(trackedHandJoint); + var playspaceTransform = MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform; + + if (trackedHandJoint == TrackedHandJoint.Wrist) + { + jointTransform.localPosition = handRootPose.Position; + jointTransform.localRotation = handRootPose.Rotation; + } + else + { + jointTransform.parent = playspaceTransform; + jointTransform.localPosition = playspaceTransform.InverseTransformPoint(playspaceTransform.position + playspaceTransform.rotation * jointPose.Position.ToUnity()); + jointTransform.localRotation = Quaternion.Inverse(playspaceTransform.rotation) * playspaceTransform.rotation * jointPose.Orientation.ToUnity(); + jointTransform.parent = conversionProxyRootTransform; + } + + return new MixedRealityPose( + conversionProxyRootTransform.InverseTransformPoint(jointTransform.position), + Quaternion.Inverse(conversionProxyRootTransform.rotation) * jointTransform.rotation); + } + + /// + /// Gets the hand's root in playspace. + /// + /// s retrieved from the platform. + /// The hand's . + private MixedRealityPose GetHandRootPose(JointPose[] platformJointPoses) + { + // For WMR we use the wrist pose as the hand root pose. + var wristPose = platformJointPoses[(int)HandJointKind.Wrist]; + var wristProxyTransform = GetProxyTransform(TrackedHandJoint.Wrist); + + // Convert to playspace. + var playspaceTransform = MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform; + wristProxyTransform.position = playspaceTransform.InverseTransformPoint(playspaceTransform.position + playspaceTransform.rotation * wristPose.Position.ToUnity()); + wristProxyTransform.rotation = Quaternion.Inverse(playspaceTransform.rotation) * playspaceTransform.rotation * wristPose.Orientation.ToUnity(); + + return new MixedRealityPose(wristProxyTransform.position, wristProxyTransform.rotation); + } + + /// + /// Gets the hand's spatial pointer in playspace. + /// + /// Current snapshot of the hand. + /// The hand's in playspace. + private MixedRealityPose GetPointerPose(SpatialInteractionSourceState spatialInteractionSourceState) + { + var spatialPointerPose = spatialInteractionSourceState.TryGetPointerPose(WindowsMixedRealityUtilities.SpatialCoordinateSystem); + if (spatialPointerPose != null) + { + var interactionSourcePose = spatialPointerPose.TryGetInteractionSourcePose(spatialInteractionSourceState.Source); + if (interactionSourcePose != null) { - // if hand mesh visualization is disabled make sure to destroy our hand mesh observer if it has already been created - if (spatialInteractionSourceState.Source.Handedness == SpatialInteractionSourceHandedness.Left) - { - hasRequestedHandMeshObserverLeftHand = false; - } - else if (spatialInteractionSourceState.Source.Handedness == SpatialInteractionSourceHandedness.Right) - { - hasRequestedHandMeshObserverRightHand = false; - } + var playspaceTransform = MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform; + var pointerPosition = playspaceTransform.InverseTransformPoint(playspaceTransform.position + playspaceTransform.rotation * interactionSourcePose.Position.ToUnity()); + var pointerRotation = Quaternion.Inverse(playspaceTransform.rotation) * playspaceTransform.rotation * interactionSourcePose.Orientation.ToUnity(); + + return new MixedRealityPose(pointerPosition, pointerRotation); + } + } + + return MixedRealityPose.ZeroIdentity; + } + + /// + /// Attempts to get updated hand mesh data. + /// + /// Platform provided current input source state for the hand. + /// Hand pose information retrieved for joint conversion. + /// Mesh information retrieved in case of success. + /// True, if mesh data could be loaded. + private bool TryGetUpdatedHandMeshData(SpatialInteractionSourceState spatialInteractionSourceState, HandPose handPose, out HandMeshData data) + { + if (!handMeshObservers.ContainsKey(spatialInteractionSourceState.Source.Handedness) && + !HasRequestedHandMeshObserver(spatialInteractionSourceState.Source.Handedness)) + { + SetHandMeshObserver(spatialInteractionSourceState); + } - handMeshObservers.Remove(spatialInteractionSourceState.Source.Handedness); + if (handMeshObservers.TryGetValue(spatialInteractionSourceState.Source.Handedness, out var handMeshObserver) && handMeshTriangleIndices == null) + { + var indexCount = handMeshObserver.TriangleIndexCount; + var indices = new ushort[indexCount]; + handMeshObserver.GetTriangleIndices(indices); + handMeshTriangleIndices = new int[indexCount]; + Array.Copy(indices, handMeshTriangleIndices, (int)handMeshObserver.TriangleIndexCount); + + // Compute neutral pose + var neutralPoseVertices = new Vector3[handMeshObserver.VertexCount]; + var neutralPose = handMeshObserver.NeutralPose; + var vertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; + var handMeshVertexState = handMeshObserver.GetVertexStateForPose(neutralPose); + handMeshVertexState.GetVertices(vertexAndNormals); + + for (int i = 0; i < handMeshObserver.VertexCount; i++) + { + neutralPoseVertices[i] = vertexAndNormals[i].Position.ToUnity(); } - JointPose[] jointPoses = new JointPose[jointIndices.Length]; - if (handPose.TryGetJoints(WindowsMixedRealityUtilities.SpatialCoordinateSystem, jointIndices, jointPoses)) + // Compute UV mapping + InitializeHandMeshUVs(neutralPoseVertices); + } + + if (handMeshObserver != null && handMeshTriangleIndices != null) + { + var vertexAndNormals = new HandMeshVertex[handMeshObserver.VertexCount]; + var handMeshVertexState = handMeshObserver.GetVertexStateForPose(handPose); + handMeshVertexState.GetVertices(vertexAndNormals); + + var meshTransform = handMeshVertexState.CoordinateSystem.TryGetTransformTo(WindowsMixedRealityUtilities.SpatialCoordinateSystem); + if (meshTransform.HasValue) { - for (int i = 0; i < jointPoses.Length; i++) - { - unityJointOrientations[i] = jointPoses[i].Orientation.ToUnity(); - unityJointPositions[i] = jointPoses[i].Position.ToUnity(); + System.Numerics.Matrix4x4.Decompose(meshTransform.Value, out var scale, out var rotation, out var translation); - // We want the controller to follow the Playspace, so fold in the playspace transform here to - // put the controller pose into world space. - unityJointPositions[i] = MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform.TransformPoint(unityJointPositions[i]); - unityJointOrientations[i] = MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform.rotation * unityJointOrientations[i]; + var handMeshVertices = new Vector3[handMeshObserver.VertexCount]; + var handMeshNormals = new Vector3[handMeshObserver.VertexCount]; - TrackedHandJoint handJoint = jointIndices[i].ToTrackedHandJoint(); - updatedHandData.Joints[(int)handJoint] = new MixedRealityPose(unityJointPositions[i], unityJointOrientations[i]); + for (int i = 0; i < handMeshObserver.VertexCount; i++) + { + handMeshVertices[i] = vertexAndNormals[i].Position.ToUnity(); + handMeshNormals[i] = vertexAndNormals[i].Normal.ToUnity(); } + + data = new HandMeshData( + handMeshVertices, + handMeshTriangleIndices, + handMeshNormals, + handMeshUVs); + + return true; } } - return updatedHandData; + return false; } private void InitializeHandMeshUVs(Vector3[] neutralPoseVertices) @@ -237,13 +363,37 @@ private async void SetHandMeshObserver(SpatialInteractionSourceState sourceState hasRequestedHandMeshObserverRightHand = sourceState.Source.Handedness == SpatialInteractionSourceHandedness.Right; } - private bool HasRequestedHandMeshObserver(SpatialInteractionSourceHandedness handedness) + private bool HasRequestedHandMeshObserver(SpatialInteractionSourceHandedness handedness) => + handedness == SpatialInteractionSourceHandedness.Left ? + hasRequestedHandMeshObserverLeftHand : + handedness == SpatialInteractionSourceHandedness.Right && hasRequestedHandMeshObserverRightHand; + + private Transform GetProxyTransform(TrackedHandJoint handJointKind) { - return handedness == SpatialInteractionSourceHandedness.Left - ? hasRequestedHandMeshObserverLeftHand - : handedness == SpatialInteractionSourceHandedness.Right && hasRequestedHandMeshObserverRightHand; + if (conversionProxyRootTransform.IsNull()) + { + conversionProxyRootTransform = new GameObject("WMR Hand Conversion Proxy").transform; + conversionProxyRootTransform.transform.SetParent(MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform, false); + conversionProxyRootTransform.gameObject.SetActive(false); + } + + if (handJointKind == TrackedHandJoint.Wrist) + { + return conversionProxyRootTransform; + } + + if (conversionProxyTransforms.ContainsKey(handJointKind)) + { + return conversionProxyTransforms[handJointKind]; + } + + var transform = new GameObject($"WMR Hand {handJointKind} Proxy").transform; + transform.SetParent(MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform, false); + conversionProxyTransforms.Add(handJointKind, transform); + + return transform; } +#endif // WINDOWS_UWP } -} -#endif // WINDOWS_UWP \ No newline at end of file +} \ No newline at end of file diff --git a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs.meta b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs.meta index c94c07a..5ffb85d 100644 --- a/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs.meta +++ b/XRTK.WindowsMixedReality/Packages/com.xrtk.wmr/Runtime/Utilities/WindowsMixedRealityHandDataConverter.cs.meta @@ -8,4 +8,4 @@ MonoImporter: icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} userData: assetBundleName: - assetBundleVariant: + assetBundleVariant: \ No newline at end of file