Skip to content

Commit cd2cd12

Browse files
committed
Add AXR hand mesh support
stash Update OpenXRHandsSubsystem.cs
1 parent db8dfd2 commit cd2cd12

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

org.mixedrealitytoolkit.input/Subsystems/Hands/UnityHandsSubsystem.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ private XRHand GetTrackedHand()
215215
}
216216
}
217217

218-
XRHand hand = HandNode == XRNode.LeftHand ? xrHandSubsystem.leftHand : xrHandSubsystem.rightHand;
219-
return hand;
218+
return HandNode == XRNode.LeftHand ? xrHandSubsystem.leftHand : xrHandSubsystem.rightHand;
220219
}
221220
}
222221

org.mixedrealitytoolkit.input/Visualizers/PlatformHandVisualizer/PlatformHandMeshVisualizer.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright (c) Mixed Reality Toolkit Contributors
22
// Licensed under the BSD 3-Clause
33

4+
using System.Collections.Generic;
45
using UnityEngine;
6+
using UnityEngine.XR;
7+
using UnityEngine.XR.Interaction.Toolkit;
58

69
#if MROPENXR_PRESENT && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
710
using Microsoft.MixedReality.OpenXR;
@@ -28,6 +31,8 @@ public class PlatformHandMeshVisualizer : HandMeshVisualizer
2831
private Mesh neutralPoseMesh;
2932
private bool initializedUVs = false;
3033

34+
private XRMeshSubsystem meshSubsystem = null;
35+
3136
/// <inheritdoc/>
3237
protected override void OnEnable()
3338
{
@@ -41,10 +46,23 @@ protected override void OnEnable()
4146
}
4247

4348
#if UNITY_OPENXR_PRESENT
44-
if (UnityEngine.XR.OpenXR.OpenXRRuntime.IsExtensionEnabled("XR_MSFT_hand_tracking_mesh"))
49+
if (UnityEngine.XR.OpenXR.OpenXRRuntime.IsExtensionEnabled("XR_ANDROID_hand_mesh"))
50+
{
51+
List<XRMeshSubsystem> meshSubsystems = new List<XRMeshSubsystem>();
52+
SubsystemManager.GetSubsystems(meshSubsystems);
53+
foreach (XRMeshSubsystem subsystem in meshSubsystems)
54+
{
55+
if (subsystem.subsystemDescriptor.id == "AndroidXRHandMeshProvider")
56+
{
57+
meshSubsystem = subsystem;
58+
break;
59+
}
60+
}
61+
}
62+
else if (UnityEngine.XR.OpenXR.OpenXRRuntime.IsExtensionEnabled("XR_MSFT_hand_tracking_mesh"))
4563
{
4664
#if MROPENXR_PRESENT && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
47-
handMeshTracker = HandNode == UnityEngine.XR.XRNode.LeftHand ? HandMeshTracker.Left : HandMeshTracker.Right;
65+
handMeshTracker = HandNode == XRNode.LeftHand ? HandMeshTracker.Left : HandMeshTracker.Right;
4866
#endif
4967
}
5068
else
@@ -56,8 +74,33 @@ protected override void OnEnable()
5674

5775
protected void Update()
5876
{
77+
if (meshSubsystem != null)
78+
{
79+
List<MeshInfo> meshInfos = new List<MeshInfo>();
80+
if (meshSubsystem.TryGetMeshInfos(meshInfos))
81+
{
82+
int handMeshIndex = HandNode == XRNode.LeftHand ? 0 : 1;
83+
84+
if (meshInfos[handMeshIndex].ChangeState == MeshChangeState.Added
85+
|| meshInfos[handMeshIndex].ChangeState == MeshChangeState.Updated)
86+
{
87+
meshSubsystem.GenerateMeshAsync(meshInfos[handMeshIndex].MeshId, meshFilter.mesh,
88+
null, MeshVertexAttributes.Normals, result => { });
89+
90+
if (!handRenderer.enabled)
91+
{
92+
handRenderer.enabled = true;
93+
}
94+
}
95+
}
96+
else if (handRenderer.enabled)
97+
{
98+
handRenderer.enabled = false;
99+
}
100+
}
101+
59102
#if MROPENXR_PRESENT && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
60-
if (!ShouldRenderHand() ||
103+
else if (!ShouldRenderHand() ||
61104
!handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, meshFilter.mesh) ||
62105
!handMeshTracker.TryLocateHandMesh(FrameTime.OnUpdate, out Pose pose))
63106
{

0 commit comments

Comments
 (0)