Skip to content

Commit b0c1b7d

Browse files
committed
reworked the handtracking profile to distinguish between rigged and system mesh visualizations
1 parent 92009fc commit b0c1b7d

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ public class MixedRealityHandTrackingProfile : BaseMixedRealityProfile
3737
/// </summary>
3838
public GameObject FingerTipPrefab => fingertipPrefab;
3939

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

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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,16 @@ public virtual void OnHandMeshUpdated(InputEventData<HandMeshInfo> eventData)
192192

193193
bool newMesh = handMeshFilter == null;
194194

195+
IMixedRealityInputSystem inputSystem = CoreServices.InputSystem;
196+
MixedRealityHandTrackingProfile handTrackingProfile = inputSystem?.InputSystemProfile != null ? inputSystem.InputSystemProfile.HandTrackingProfile : null;
195197
if (newMesh &&
196-
CoreServices.InputSystem?.InputSystemProfile != null &&
197-
CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile != null &&
198-
CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.HandMeshPrefab != null)
198+
handTrackingProfile != null &&
199+
handTrackingProfile.SystemHandMeshMaterial != null)
199200
{
200-
handMeshFilter = Instantiate(CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.HandMeshPrefab).GetComponent<MeshFilter>();
201+
// Create the hand mesh in the scene and assign the proper material to it
202+
handMeshFilter = new GameObject("System Hand Mesh").EnsureComponent<MeshFilter>();
203+
handMeshFilter.EnsureComponent<MeshRenderer>().material = CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.SystemHandMeshMaterial;
204+
201205
lastHandMeshVerticesCount = handMeshFilter.mesh.vertices.Length;
202206
}
203207

@@ -236,6 +240,7 @@ public virtual void OnHandMeshUpdated(InputEventData<HandMeshInfo> eventData)
236240
}
237241

238242
handMeshFilter.transform.SetPositionAndRotation(eventData.InputData.position, eventData.InputData.rotation);
243+
handMeshFilter.transform.parent = transform;
239244
}
240245
}
241246
}

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
}

0 commit comments

Comments
 (0)