forked from microsoft/OpenXR-Unity-MixedReality-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandMesh.cs
56 lines (49 loc) · 1.6 KB
/
HandMesh.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
namespace Microsoft.MixedReality.OpenXR.BasicSample
{
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
public class HandMesh : MonoBehaviour
{
[SerializeField, Tooltip("The hand this mesh should represent.")]
private Handedness handedness;
private Mesh mesh;
private MeshFilter meshFilter;
private MeshRenderer meshRenderer;
private HandMeshTracker handMeshTracker;
private void Awake()
{
handMeshTracker = handedness == Handedness.Left ? HandMeshTracker.Left : HandMeshTracker.Right;
meshFilter = gameObject.GetComponent<MeshFilter>();
meshRenderer = gameObject.GetComponent<MeshRenderer>();
mesh = meshFilter.mesh;
}
private void Update()
{
if (mesh == null)
{
return;
}
if (handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, mesh))
{
if (!meshRenderer.enabled)
{
meshRenderer.enabled = true;
}
if (handMeshTracker.TryLocateHandMesh(FrameTime.OnUpdate, out Pose pose))
{
transform.SetPositionAndRotation(pose.position, pose.rotation);
}
}
else
{
if (meshRenderer.enabled)
{
meshRenderer.enabled = false;
}
}
}
}
}