diff --git a/Assets/MRTK/Core/Definitions/Devices/MixedRealityHandTrackingProfile.cs b/Assets/MRTK/Core/Definitions/Devices/MixedRealityHandTrackingProfile.cs index ee75bf743fa..bdb0e77d250 100644 --- a/Assets/MRTK/Core/Definitions/Devices/MixedRealityHandTrackingProfile.cs +++ b/Assets/MRTK/Core/Definitions/Devices/MixedRealityHandTrackingProfile.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using Microsoft.MixedReality.Toolkit.Utilities; +using System; using UnityEngine; namespace Microsoft.MixedReality.Toolkit.Input @@ -37,6 +38,24 @@ public class MixedRealityHandTrackingProfile : BaseMixedRealityProfile /// public GameObject FingerTipPrefab => fingertipPrefab; + [SerializeField] + [Tooltip("The hand mesh material to use for system generated hand meshes")] + private Material systemHandMeshMaterial; + + /// + /// The hand mesh material to use for system generated hand meshes + /// + public Material SystemHandMeshMaterial => systemHandMeshMaterial; + + [SerializeField] + [Tooltip("The hand mesh material to use for rigged hand meshes")] + private Material riggedHandMeshMaterial; + + /// + /// The hand mesh material to use for rigged hand meshes + /// + 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; @@ -44,6 +63,7 @@ public class MixedRealityHandTrackingProfile : BaseMixedRealityProfile /// /// The hand mesh prefab to use to render the hand /// + [Obsolete("The GameObject which generates the system handmesh is now created at runtime. This prefab is not used")] public GameObject HandMeshPrefab => handMeshPrefab; /// diff --git a/Assets/MRTK/Core/Inspectors/Profiles/MixedRealityHandTrackingProfileInspector.cs b/Assets/MRTK/Core/Inspectors/Profiles/MixedRealityHandTrackingProfileInspector.cs index 9d6a28c657b..6e2ebf65183 100644 --- a/Assets/MRTK/Core/Inspectors/Profiles/MixedRealityHandTrackingProfileInspector.cs +++ b/Assets/MRTK/Core/Inspectors/Profiles/MixedRealityHandTrackingProfileInspector.cs @@ -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; @@ -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"); } @@ -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); diff --git a/Assets/MRTK/Core/Providers/Hands/BaseHandVisualizer.cs b/Assets/MRTK/Core/Providers/Hands/BaseHandVisualizer.cs index 790cdc0fe77..909859402e9 100644 --- a/Assets/MRTK/Core/Providers/Hands/BaseHandVisualizer.cs +++ b/Assets/MRTK/Core/Providers/Hands/BaseHandVisualizer.cs @@ -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(); - 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(); + handMeshFilter.EnsureComponent().material = handTrackingProfile.SystemHandMeshMaterial; + } +#pragma warning disable 0618 + else if (handTrackingProfile.HandMeshPrefab.IsNotNull()) + { + handMeshFilter = Instantiate(handTrackingProfile.HandMeshPrefab).GetComponent(); + } +#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) diff --git a/Assets/MRTK/Examples/Demos/PulseShader/Profile/PulseShaderHandTrackingProfile.asset b/Assets/MRTK/Examples/Demos/PulseShader/Profile/PulseShaderHandTrackingProfile.asset index 45c3e69e2b3..725cec255df 100644 --- a/Assets/MRTK/Examples/Demos/PulseShader/Profile/PulseShaderHandTrackingProfile.asset +++ b/Assets/MRTK/Examples/Demos/PulseShader/Profile/PulseShaderHandTrackingProfile.asset @@ -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 diff --git a/Assets/MRTK/SDK/Features/UX/Scripts/RiggedHandVisualizer/RiggedHandVisualizer.cs b/Assets/MRTK/SDK/Features/UX/Scripts/RiggedHandVisualizer/RiggedHandVisualizer.cs index 7b5ab801fd7..32ff7c998fb 100644 --- a/Assets/MRTK/SDK/Features/UX/Scripts/RiggedHandVisualizer/RiggedHandVisualizer.cs +++ b/Assets/MRTK/SDK/Features/UX/Scripts/RiggedHandVisualizer/RiggedHandVisualizer.cs @@ -101,13 +101,15 @@ public class RiggedHandVisualizer : BaseHandVisualizer /// public SkinnedMeshRenderer HandRenderer => handRenderer; - [SerializeField] - [Tooltip("Hand material to use for hand tracking hand mesh.")] + /// + /// Caching the hand material from CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.RiggedHandMeshMaterial + /// private Material handMaterial = null; /// /// Hand material to use for hand tracking hand mesh. /// + [Obsolete("Use the CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.RiggedHandMeshMaterial instead")] public Material HandMaterial => handMaterial; /// @@ -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; } diff --git a/Assets/MRTK/SDK/Profiles/DefaultMixedRealityHandTrackingProfile.asset b/Assets/MRTK/SDK/Profiles/DefaultMixedRealityHandTrackingProfile.asset index 8623dc856c3..a4773f8d9b4 100644 --- a/Assets/MRTK/SDK/Profiles/DefaultMixedRealityHandTrackingProfile.asset +++ b/Assets/MRTK/SDK/Profiles/DefaultMixedRealityHandTrackingProfile.asset @@ -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 diff --git a/Assets/MRTK/SDK/Profiles/HoloLens1/DefaultHoloLens1HandTrackingProfile.asset b/Assets/MRTK/SDK/Profiles/HoloLens1/DefaultHoloLens1HandTrackingProfile.asset index b072f017922..eadcbd666e1 100644 --- a/Assets/MRTK/SDK/Profiles/HoloLens1/DefaultHoloLens1HandTrackingProfile.asset +++ b/Assets/MRTK/SDK/Profiles/HoloLens1/DefaultHoloLens1HandTrackingProfile.asset @@ -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 diff --git a/Assets/MRTK/SDK/Profiles/HoloLens2/DefaultHoloLens2HandTrackingProfile.asset b/Assets/MRTK/SDK/Profiles/HoloLens2/DefaultHoloLens2HandTrackingProfile.asset index 95b573cd369..dec0c76c7fa 100644 --- a/Assets/MRTK/SDK/Profiles/HoloLens2/DefaultHoloLens2HandTrackingProfile.asset +++ b/Assets/MRTK/SDK/Profiles/HoloLens2/DefaultHoloLens2HandTrackingProfile.asset @@ -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