11// Copyright (c) Mixed Reality Toolkit Contributors
22// Licensed under the BSD 3-Clause
33
4+ using System . Collections . Generic ;
45using UnityEngine ;
6+ using UnityEngine . XR ;
7+ using UnityEngine . XR . Interaction . Toolkit ;
58
69#if MROPENXR_PRESENT && ( UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID )
710using 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