Skip to content

Commit 7a3db3a

Browse files
author
David Kline
authored
Merge pull request #10608 from RogPodge/HandTrackingProfileRefactor
HandTracking Profile Hand Mesh Refactor
2 parents d39f98c + 707633c commit 7a3db3a

File tree

8 files changed

+72
-12
lines changed

8 files changed

+72
-12
lines changed

Assets/MRTK/Core/Definitions/Devices/MixedRealityHandTrackingProfile.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.MixedReality.Toolkit.Utilities;
5+
using System;
56
using UnityEngine;
67

78
namespace Microsoft.MixedReality.Toolkit.Input
@@ -37,13 +38,32 @@ public class MixedRealityHandTrackingProfile : BaseMixedRealityProfile
3738
/// </summary>
3839
public GameObject FingerTipPrefab => fingertipPrefab;
3940

41+
[SerializeField]
42+
[Tooltip("The hand mesh material to use for system generated hand meshes")]
43+
private Material systemHandMeshMaterial;
44+
45+
/// <summary>
46+
/// The hand mesh material to use for system generated hand meshes
47+
/// </summary>
48+
public Material SystemHandMeshMaterial => systemHandMeshMaterial;
49+
50+
[SerializeField]
51+
[Tooltip("The hand mesh material to use for rigged hand meshes")]
52+
private Material riggedHandMeshMaterial;
53+
54+
/// <summary>
55+
/// The hand mesh material to use for rigged hand meshes
56+
/// </summary>
57+
public Material RiggedHandMeshMaterial => riggedHandMeshMaterial;
58+
4059
[SerializeField]
4160
[Tooltip("If this is not null and hand system supports hand meshes, use this mesh to render hand mesh.")]
4261
private GameObject handMeshPrefab = null;
4362

4463
/// <summary>
4564
/// The hand mesh prefab to use to render the hand
4665
/// </summary>
66+
[Obsolete("The GameObject which generates the system handmesh is now created at runtime. This prefab is not used")]
4767
public GameObject HandMeshPrefab => handMeshPrefab;
4868

4969
/// <summary>

Assets/MRTK/Core/Inspectors/Profiles/MixedRealityHandTrackingProfileInspector.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class MixedRealityHandTrackingProfileInspector : BaseMixedRealityToolkitC
1313
private SerializedProperty jointPrefab;
1414
private SerializedProperty palmPrefab;
1515
private SerializedProperty fingertipPrefab;
16-
private SerializedProperty handMeshPrefab;
16+
private SerializedProperty systemHandMeshMaterial;
17+
private SerializedProperty riggedHandMeshMaterial;
1718
private SerializedProperty handMeshVisualizationModes;
1819
private SerializedProperty handJointVisualizationModes;
1920

@@ -27,7 +28,8 @@ protected override void OnEnable()
2728
jointPrefab = serializedObject.FindProperty("jointPrefab");
2829
fingertipPrefab = serializedObject.FindProperty("fingertipPrefab");
2930
palmPrefab = serializedObject.FindProperty("palmPrefab");
30-
handMeshPrefab = serializedObject.FindProperty("handMeshPrefab");
31+
systemHandMeshMaterial = serializedObject.FindProperty("systemHandMeshMaterial");
32+
riggedHandMeshMaterial = serializedObject.FindProperty("riggedHandMeshMaterial");
3133
handMeshVisualizationModes = serializedObject.FindProperty("handMeshVisualizationModes");
3234
handJointVisualizationModes = serializedObject.FindProperty("handJointVisualizationModes");
3335
}
@@ -47,7 +49,8 @@ public override void OnInspectorGUI()
4749
EditorGUILayout.PropertyField(jointPrefab);
4850
EditorGUILayout.PropertyField(palmPrefab);
4951
EditorGUILayout.PropertyField(fingertipPrefab);
50-
EditorGUILayout.PropertyField(handMeshPrefab);
52+
EditorGUILayout.PropertyField(systemHandMeshMaterial);
53+
EditorGUILayout.PropertyField(riggedHandMeshMaterial);
5154

5255
EditorGUILayout.LabelField("Visualization settings", EditorStyles.boldLabel);
5356
EditorGUILayout.PropertyField(handMeshVisualizationModes);

Assets/MRTK/Core/Providers/Hands/BaseHandVisualizer.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,29 @@ protected virtual void UpdateHandMesh()
252252

253253
bool newMesh = handMeshFilter == null;
254254

255-
if (newMesh &&
256-
CoreServices.InputSystem?.InputSystemProfile != null &&
257-
CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile != null &&
258-
CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.HandMeshPrefab != null)
255+
IMixedRealityInputSystem inputSystem = CoreServices.InputSystem;
256+
MixedRealityHandTrackingProfile handTrackingProfile = inputSystem?.InputSystemProfile != null ? inputSystem.InputSystemProfile.HandTrackingProfile : null;
257+
if (newMesh && handTrackingProfile != null)
259258
{
260-
handMeshFilter = Instantiate(CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.HandMeshPrefab).GetComponent<MeshFilter>();
261-
lastHandMeshVerticesCount = handMeshFilter.mesh.vertices.Length;
259+
// Create the hand mesh in the scene and assign the proper material to it
260+
if(handTrackingProfile.SystemHandMeshMaterial.IsNotNull())
261+
{
262+
handMeshFilter = new GameObject("System Hand Mesh").EnsureComponent<MeshFilter>();
263+
handMeshFilter.EnsureComponent<MeshRenderer>().material = handTrackingProfile.SystemHandMeshMaterial;
264+
}
265+
#pragma warning disable 0618
266+
else if (handTrackingProfile.HandMeshPrefab.IsNotNull())
267+
{
268+
handMeshFilter = Instantiate(handTrackingProfile.HandMeshPrefab).GetComponent<MeshFilter>();
269+
}
270+
#pragma warning restore 0618
271+
272+
// Initialize the hand mesh if we generated it successfully
273+
if (handMeshFilter != null)
274+
{
275+
lastHandMeshVerticesCount = handMeshFilter.mesh.vertices.Length;
276+
handMeshFilter.transform.parent = transform;
277+
}
262278
}
263279

264280
if (handMeshFilter != null)

Assets/MRTK/Examples/Demos/PulseShader/Profile/PulseShaderHandTrackingProfile.asset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ MonoBehaviour:
1919
type: 3}
2020
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
2121
type: 3}
22+
systemHandMeshMaterial: {fileID: 2100000, guid: 8898ca407d928454d876a616ba1be32e,
23+
type: 2}
24+
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
25+
type: 2}
2226
handMeshPrefab: {fileID: 1887883006053652, guid: 308140ab26e8edd4f920cadc10af5c4f,
2327
type: 3}
2428
handMeshVisualizationModes: -1

Assets/MRTK/SDK/Features/UX/Scripts/RiggedHandVisualizer/RiggedHandVisualizer.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ public class RiggedHandVisualizer : BaseHandVisualizer
101101
/// </summary>
102102
public SkinnedMeshRenderer HandRenderer => handRenderer;
103103

104-
[SerializeField]
105-
[Tooltip("Hand material to use for hand tracking hand mesh.")]
104+
/// <summary>
105+
/// Caching the hand material from CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.RiggedHandMeshMaterial
106+
/// </summary>
106107
private Material handMaterial = null;
107108

108109
/// <summary>
109110
/// Hand material to use for hand tracking hand mesh.
110111
/// </summary>
112+
[Obsolete("Use the CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.RiggedHandMeshMaterial instead")]
111113
public Material HandMaterial => handMaterial;
112114

113115
/// <summary>
@@ -265,7 +267,10 @@ protected override void Start()
265267
}
266268

267269
// Give the hand mesh its own material to avoid modifying both hand materials when making property changes
268-
var handMaterialInstance = new Material(handMaterial);
270+
MixedRealityHandTrackingProfile handTrackingProfile = CoreServices.InputSystem?.InputSystemProfile.HandTrackingProfile;
271+
272+
handMaterial = handTrackingProfile.RiggedHandMeshMaterial;
273+
Material handMaterialInstance = new Material(handMaterial);
269274
handRenderer.sharedMaterial = handMaterialInstance;
270275
handRendererInitialized = true;
271276
}

Assets/MRTK/SDK/Profiles/DefaultMixedRealityHandTrackingProfile.asset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ MonoBehaviour:
1919
type: 3}
2020
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
2121
type: 3}
22+
systemHandMeshMaterial: {fileID: 2100000, guid: 45082b98567b3d44ca3bdbe39f46041a,
23+
type: 2}
24+
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
25+
type: 2}
2226
handMeshPrefab: {fileID: 1887883006053652, guid: a86f479797fea8f4189f924b3b6ad979,
2327
type: 3}
2428
handMeshVisualizationModes: -1

Assets/MRTK/SDK/Profiles/HoloLens1/DefaultHoloLens1HandTrackingProfile.asset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ MonoBehaviour:
1919
type: 3}
2020
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
2121
type: 3}
22+
systemHandMeshMaterial: {fileID: 2100000, guid: 45082b98567b3d44ca3bdbe39f46041a,
23+
type: 2}
24+
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
25+
type: 2}
2226
handMeshPrefab: {fileID: 1887883006053652, guid: a86f479797fea8f4189f924b3b6ad979,
2327
type: 3}
2428
handMeshVisualizationModes: 0

Assets/MRTK/SDK/Profiles/HoloLens2/DefaultHoloLens2HandTrackingProfile.asset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ MonoBehaviour:
1919
type: 3}
2020
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
2121
type: 3}
22+
systemHandMeshMaterial: {fileID: 2100000, guid: 45082b98567b3d44ca3bdbe39f46041a,
23+
type: 2}
24+
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
25+
type: 2}
2226
handMeshPrefab: {fileID: 1887883006053652, guid: a86f479797fea8f4189f924b3b6ad979,
2327
type: 3}
2428
handMeshVisualizationModes: 1

0 commit comments

Comments
 (0)