|
8 | 8 | #endif // MSFT_OPENXR_0_2_0_OR_NEWER |
9 | 9 |
|
10 | 10 | using Microsoft.MixedReality.Toolkit.Input; |
| 11 | +using Unity.Profiling; |
11 | 12 |
|
12 | 13 | namespace Microsoft.MixedReality.Toolkit.XRSDK.OpenXR |
13 | 14 | { |
@@ -66,49 +67,54 @@ private OpenXRHandMeshProvider(HandMeshTracker handMeshTracker, Utilities.Handed |
66 | 67 | /// <param name="inputSource">Implementation of the hand input source.</param> |
67 | 68 | public void SetInputSource(IMixedRealityInputSource inputSource) => this.inputSource = inputSource; |
68 | 69 |
|
| 70 | + private static readonly ProfilerMarker UpdateHandMeshPerfMarker = new ProfilerMarker($"[MRTK] {nameof(OpenXRHandMeshProvider)}.UpdateHandMesh"); |
| 71 | + |
69 | 72 | /// <summary> |
70 | 73 | /// Updates the hand mesh based on the current state of the hand. |
71 | 74 | /// </summary> |
72 | 75 | public void UpdateHandMesh() |
73 | 76 | { |
74 | 77 | #if MSFT_OPENXR_0_2_0_OR_NEWER |
75 | | - MixedRealityInputSystemProfile inputSystemProfile = CoreServices.InputSystem?.InputSystemProfile; |
76 | | - MixedRealityHandTrackingProfile handTrackingProfile = inputSystemProfile != null ? inputSystemProfile.HandTrackingProfile : null; |
77 | | - |
78 | | - if (handTrackingProfile == null || !handTrackingProfile.EnableHandMeshVisualization) |
| 78 | + using (UpdateHandMeshPerfMarker.Auto()) |
79 | 79 | { |
80 | | - // If hand mesh visualization is disabled make sure to clean up if we've already initialized |
81 | | - if (handMeshUVs != null) |
| 80 | + MixedRealityInputSystemProfile inputSystemProfile = CoreServices.InputSystem?.InputSystemProfile; |
| 81 | + MixedRealityHandTrackingProfile handTrackingProfile = inputSystemProfile != null ? inputSystemProfile.HandTrackingProfile : null; |
| 82 | + |
| 83 | + if (handTrackingProfile == null || !handTrackingProfile.EnableHandMeshVisualization) |
82 | 84 | { |
83 | | - // Notify that hand mesh has been updated (cleared) |
84 | | - CoreServices.InputSystem?.RaiseHandMeshUpdated(inputSource, handedness, new HandMeshInfo()); |
85 | | - handMeshUVs = null; |
| 85 | + // If hand mesh visualization is disabled make sure to clean up if we've already initialized |
| 86 | + if (handMeshUVs != null) |
| 87 | + { |
| 88 | + // Notify that hand mesh has been updated (cleared) |
| 89 | + CoreServices.InputSystem?.RaiseHandMeshUpdated(inputSource, handedness, new HandMeshInfo()); |
| 90 | + handMeshUVs = null; |
| 91 | + } |
| 92 | + return; |
86 | 93 | } |
87 | | - return; |
88 | | - } |
89 | 94 |
|
90 | | - if (handMeshUVs == null && handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, neutralPoseMesh, HandPoseType.ReferenceOpenPalm)) |
91 | | - { |
92 | | - handMeshUVs = InitializeUVs(neutralPoseMesh.vertices); |
93 | | - } |
94 | | - |
95 | | - if (handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, mesh) && handMeshTracker.TryLocateHandMesh(FrameTime.OnUpdate, out Pose pose)) |
96 | | - { |
97 | | - mesh.GetVertices(vertices); |
98 | | - mesh.GetNormals(normals); |
99 | | - mesh.GetTriangles(triangles, 0); |
| 95 | + if (handMeshUVs == null && handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, neutralPoseMesh, HandPoseType.ReferenceOpenPalm)) |
| 96 | + { |
| 97 | + handMeshUVs = InitializeUVs(neutralPoseMesh.vertices); |
| 98 | + } |
100 | 99 |
|
101 | | - HandMeshInfo handMeshInfo = new HandMeshInfo |
| 100 | + if (handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, mesh) && handMeshTracker.TryLocateHandMesh(FrameTime.OnUpdate, out Pose pose)) |
102 | 101 | { |
103 | | - vertices = vertices.ToArray(), |
104 | | - normals = normals.ToArray(), |
105 | | - triangles = triangles.ToArray(), |
106 | | - uvs = handMeshUVs, |
107 | | - position = pose.position, |
108 | | - rotation = pose.rotation |
109 | | - }; |
110 | | - |
111 | | - CoreServices.InputSystem?.RaiseHandMeshUpdated(inputSource, handedness, handMeshInfo); |
| 102 | + mesh.GetVertices(vertices); |
| 103 | + mesh.GetNormals(normals); |
| 104 | + mesh.GetTriangles(triangles, 0); |
| 105 | + |
| 106 | + HandMeshInfo handMeshInfo = new HandMeshInfo |
| 107 | + { |
| 108 | + vertices = vertices.ToArray(), |
| 109 | + normals = normals.ToArray(), |
| 110 | + triangles = triangles.ToArray(), |
| 111 | + uvs = handMeshUVs, |
| 112 | + position = pose.position, |
| 113 | + rotation = pose.rotation |
| 114 | + }; |
| 115 | + |
| 116 | + CoreServices.InputSystem?.RaiseHandMeshUpdated(inputSource, handedness, handMeshInfo); |
| 117 | + } |
112 | 118 | } |
113 | 119 | } |
114 | 120 |
|
|
0 commit comments