Skip to content

Commit

Permalink
Merge pull request #10608 from RogPodge/HandTrackingProfileRefactor
Browse files Browse the repository at this point in the history
HandTracking Profile Hand Mesh Refactor
  • Loading branch information
David Kline committed May 23, 2022
2 parents d39f98c + 707633c commit 7a3db3a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Utilities;
using System;
using UnityEngine;

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

[SerializeField]
[Tooltip("The hand mesh material to use for system generated hand meshes")]
private Material systemHandMeshMaterial;

/// <summary>
/// The hand mesh material to use for system generated hand meshes
/// </summary>
public Material SystemHandMeshMaterial => systemHandMeshMaterial;

[SerializeField]
[Tooltip("The hand mesh material to use for rigged hand meshes")]
private Material riggedHandMeshMaterial;

/// <summary>
/// The hand mesh material to use for rigged hand meshes
/// </summary>
public Material RiggedHandMeshMaterial => riggedHandMeshMaterial;

[SerializeField]
[Tooltip("If this is not null and hand system supports hand meshes, use this mesh to render hand mesh.")]
private GameObject handMeshPrefab = null;

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

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class MixedRealityHandTrackingProfileInspector : BaseMixedRealityToolkitC
private SerializedProperty jointPrefab;
private SerializedProperty palmPrefab;
private SerializedProperty fingertipPrefab;
private SerializedProperty handMeshPrefab;
private SerializedProperty systemHandMeshMaterial;
private SerializedProperty riggedHandMeshMaterial;
private SerializedProperty handMeshVisualizationModes;
private SerializedProperty handJointVisualizationModes;

Expand All @@ -27,7 +28,8 @@ protected override void OnEnable()
jointPrefab = serializedObject.FindProperty("jointPrefab");
fingertipPrefab = serializedObject.FindProperty("fingertipPrefab");
palmPrefab = serializedObject.FindProperty("palmPrefab");
handMeshPrefab = serializedObject.FindProperty("handMeshPrefab");
systemHandMeshMaterial = serializedObject.FindProperty("systemHandMeshMaterial");
riggedHandMeshMaterial = serializedObject.FindProperty("riggedHandMeshMaterial");
handMeshVisualizationModes = serializedObject.FindProperty("handMeshVisualizationModes");
handJointVisualizationModes = serializedObject.FindProperty("handJointVisualizationModes");
}
Expand All @@ -47,7 +49,8 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(jointPrefab);
EditorGUILayout.PropertyField(palmPrefab);
EditorGUILayout.PropertyField(fingertipPrefab);
EditorGUILayout.PropertyField(handMeshPrefab);
EditorGUILayout.PropertyField(systemHandMeshMaterial);
EditorGUILayout.PropertyField(riggedHandMeshMaterial);

EditorGUILayout.LabelField("Visualization settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(handMeshVisualizationModes);
Expand Down
28 changes: 22 additions & 6 deletions Assets/MRTK/Core/Providers/Hands/BaseHandVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,29 @@ protected virtual void UpdateHandMesh()

bool newMesh = handMeshFilter == null;

if (newMesh &&
CoreServices.InputSystem?.InputSystemProfile != null &&
CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile != null &&
CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.HandMeshPrefab != null)
IMixedRealityInputSystem inputSystem = CoreServices.InputSystem;
MixedRealityHandTrackingProfile handTrackingProfile = inputSystem?.InputSystemProfile != null ? inputSystem.InputSystemProfile.HandTrackingProfile : null;
if (newMesh && handTrackingProfile != null)
{
handMeshFilter = Instantiate(CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.HandMeshPrefab).GetComponent<MeshFilter>();
lastHandMeshVerticesCount = handMeshFilter.mesh.vertices.Length;
// Create the hand mesh in the scene and assign the proper material to it
if(handTrackingProfile.SystemHandMeshMaterial.IsNotNull())
{
handMeshFilter = new GameObject("System Hand Mesh").EnsureComponent<MeshFilter>();
handMeshFilter.EnsureComponent<MeshRenderer>().material = handTrackingProfile.SystemHandMeshMaterial;
}
#pragma warning disable 0618
else if (handTrackingProfile.HandMeshPrefab.IsNotNull())
{
handMeshFilter = Instantiate(handTrackingProfile.HandMeshPrefab).GetComponent<MeshFilter>();
}
#pragma warning restore 0618

// Initialize the hand mesh if we generated it successfully
if (handMeshFilter != null)
{
lastHandMeshVerticesCount = handMeshFilter.mesh.vertices.Length;
handMeshFilter.transform.parent = transform;
}
}

if (handMeshFilter != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ MonoBehaviour:
type: 3}
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
type: 3}
systemHandMeshMaterial: {fileID: 2100000, guid: 8898ca407d928454d876a616ba1be32e,
type: 2}
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
type: 2}
handMeshPrefab: {fileID: 1887883006053652, guid: 308140ab26e8edd4f920cadc10af5c4f,
type: 3}
handMeshVisualizationModes: -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ public class RiggedHandVisualizer : BaseHandVisualizer
/// </summary>
public SkinnedMeshRenderer HandRenderer => handRenderer;

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

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

/// <summary>
Expand Down Expand Up @@ -265,7 +267,10 @@ protected override void Start()
}

// Give the hand mesh its own material to avoid modifying both hand materials when making property changes
var handMaterialInstance = new Material(handMaterial);
MixedRealityHandTrackingProfile handTrackingProfile = CoreServices.InputSystem?.InputSystemProfile.HandTrackingProfile;

handMaterial = handTrackingProfile.RiggedHandMeshMaterial;
Material handMaterialInstance = new Material(handMaterial);
handRenderer.sharedMaterial = handMaterialInstance;
handRendererInitialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ MonoBehaviour:
type: 3}
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
type: 3}
systemHandMeshMaterial: {fileID: 2100000, guid: 45082b98567b3d44ca3bdbe39f46041a,
type: 2}
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
type: 2}
handMeshPrefab: {fileID: 1887883006053652, guid: a86f479797fea8f4189f924b3b6ad979,
type: 3}
handMeshVisualizationModes: -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ MonoBehaviour:
type: 3}
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
type: 3}
systemHandMeshMaterial: {fileID: 2100000, guid: 45082b98567b3d44ca3bdbe39f46041a,
type: 2}
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
type: 2}
handMeshPrefab: {fileID: 1887883006053652, guid: a86f479797fea8f4189f924b3b6ad979,
type: 3}
handMeshVisualizationModes: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ MonoBehaviour:
type: 3}
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
type: 3}
systemHandMeshMaterial: {fileID: 2100000, guid: 45082b98567b3d44ca3bdbe39f46041a,
type: 2}
riggedHandMeshMaterial: {fileID: 2100000, guid: 46180a965b426614f97a7239d1248a1a,
type: 2}
handMeshPrefab: {fileID: 1887883006053652, guid: a86f479797fea8f4189f924b3b6ad979,
type: 3}
handMeshVisualizationModes: 1
Expand Down

0 comments on commit 7a3db3a

Please sign in to comment.