Skip to content

Commit 7503ecc

Browse files
authored
Fix rigged hands in remoting (#11267)
* Add some null checks and minor optimizations * Formatting * Don't render the rigged hand unless the display is opaque * Clean up some asset declarations
1 parent 1644cb0 commit 7503ecc

File tree

2 files changed

+33
-64
lines changed

2 files changed

+33
-64
lines changed

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

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

104-
/// <summary>
105-
/// Caching the hand material from CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.RiggedHandMeshMaterial
106-
/// </summary>
107-
private Material handMaterial = null;
108-
109104
/// <summary>
110105
/// Hand material to use for hand tracking hand mesh.
111106
/// </summary>
112107
[Obsolete("Use the CoreServices.InputSystem.InputSystemProfile.HandTrackingProfile.RiggedHandMeshMaterial instead")]
113-
public Material HandMaterial => handMaterial;
108+
public Material HandMaterial { get; private set; }
114109

115110
/// <summary>
116111
/// Property name for modifying the mesh's appearance based on pinch strength
@@ -125,23 +120,23 @@ public class RiggedHandVisualizer : BaseHandVisualizer
125120
/// <summary>
126121
/// Precalculated values for LeapMotion testhand fingertip lengths
127122
/// </summary>
128-
private const float thumbFingerTipLength = 0.02167f;
129-
private const float indexingerTipLength = 0.01582f;
130-
private const float middleFingerTipLength = 0.0174f;
131-
private const float ringFingerTipLength = 0.0173f;
132-
private const float pinkyFingerTipLength = 0.01596f;
123+
private const float ThumbFingerTipLength = 0.02167f;
124+
private const float IndexFingerTipLength = 0.01582f;
125+
private const float MiddleFingerTipLength = 0.0174f;
126+
private const float RingFingerTipLength = 0.0173f;
127+
private const float PinkyFingerTipLength = 0.01596f;
133128

134129
/// <summary>
135130
/// Precalculated fingertip lengths used for scaling the fingertips of the skinnedmesh
136131
/// to match with tracked hand fingertip size
137132
/// </summary>
138133
private Dictionary<TrackedHandJoint, float> fingerTipLengths = new Dictionary<TrackedHandJoint, float>()
139134
{
140-
{TrackedHandJoint.ThumbTip, thumbFingerTipLength },
141-
{TrackedHandJoint.IndexTip, indexingerTipLength },
142-
{TrackedHandJoint.MiddleTip, middleFingerTipLength },
143-
{TrackedHandJoint.RingTip, ringFingerTipLength },
144-
{TrackedHandJoint.PinkyTip, pinkyFingerTipLength }
135+
{ TrackedHandJoint.ThumbTip, ThumbFingerTipLength },
136+
{ TrackedHandJoint.IndexTip, IndexFingerTipLength },
137+
{ TrackedHandJoint.MiddleTip, MiddleFingerTipLength },
138+
{ TrackedHandJoint.RingTip, RingFingerTipLength },
139+
{ TrackedHandJoint.PinkyTip, PinkyFingerTipLength }
145140
};
146141

147142
/// <summary>
@@ -163,7 +158,7 @@ private Quaternion UserBoneRotation
163158
protected readonly Transform[] riggedVisualJointsArray = new Transform[ArticulatedHandPose.JointCount];
164159

165160
/// <summary>
166-
/// flag checking that the handRenderer was initialized with its own material
161+
/// Flag checking that the handRenderer was initialized with its own material
167162
/// </summary>
168163
private bool handRendererInitialized = false;
169164

@@ -268,10 +263,13 @@ protected override void Start()
268263

269264
// Give the hand mesh its own material to avoid modifying both hand materials when making property changes
270265
MixedRealityHandTrackingProfile handTrackingProfile = CoreServices.InputSystem?.InputSystemProfile.HandTrackingProfile;
271-
272-
handMaterial = handTrackingProfile.RiggedHandMeshMaterial;
273-
Material handMaterialInstance = new Material(handMaterial);
274-
handRenderer.sharedMaterial = handMaterialInstance;
266+
if (handTrackingProfile != null && handTrackingProfile.RiggedHandMeshMaterial != null)
267+
{
268+
#pragma warning disable CS0618 // Type or member is obsolete
269+
HandMaterial = handTrackingProfile.RiggedHandMeshMaterial;
270+
#pragma warning restore CS0618 // Type or member is obsolete
271+
handRenderer.sharedMaterial = new Material(handTrackingProfile.RiggedHandMeshMaterial);
272+
}
275273
handRendererInitialized = true;
276274
}
277275

@@ -294,8 +292,10 @@ protected override bool UpdateHandJoints()
294292
// The base class takes care of updating all of the joint data
295293
_ = base.UpdateHandJoints();
296294

297-
// Exit early and disable the rigged hand model if we've gotten a hand mesh from the underlying platform
298-
if (ReceivingPlatformHandMesh || MixedRealityHand.IsNull())
295+
// Exit early and disable the rigged hand model if we've gotten a hand mesh from the underlying platform or the display is transparent
296+
if (ReceivingPlatformHandMesh
297+
|| MixedRealityHand.IsNull()
298+
|| (!XRSubsystemHelpers.DisplaySubsystem?.displayOpaque ?? false))
299299
{
300300
HandRenderer.enabled = false;
301301
return false;
@@ -304,8 +304,10 @@ protected override bool UpdateHandJoints()
304304
IMixedRealityInputSystem inputSystem = CoreServices.InputSystem;
305305
MixedRealityHandTrackingProfile handTrackingProfile = inputSystem?.InputSystemProfile != null ? inputSystem.InputSystemProfile.HandTrackingProfile : null;
306306

307-
// Only runs if render hand mesh is true
308-
bool renderHandmesh = handTrackingProfile != null && handTrackingProfile.EnableHandMeshVisualization && MixedRealityHand.TryGetJoint(TrackedHandJoint.Palm, out _);
307+
// Only render the hand mesh if visualization is enabled and the hand joints are tracked
308+
bool renderHandmesh = handTrackingProfile != null
309+
&& handTrackingProfile.EnableHandMeshVisualization
310+
&& MixedRealityHand.TryGetJoint(TrackedHandJoint.Palm, out _);
309311
HandRenderer.enabled = renderHandmesh;
310312
if (renderHandmesh)
311313
{
@@ -376,10 +378,10 @@ protected override bool UpdateHandJoints()
376378
float ringFingerCurl = HandPoseUtils.RingFingerCurl(Controller.ControllerHandedness);
377379
float pinkyFingerCurl = HandPoseUtils.PinkyFingerCurl(Controller.ControllerHandedness);
378380

379-
if (handMaterial != null && handRendererInitialized)
381+
if (handTrackingProfile.RiggedHandMeshMaterial != null && handRendererInitialized)
380382
{
381383
float gripStrength = indexFingerCurl + middleFingerCurl + ringFingerCurl + pinkyFingerCurl;
382-
gripStrength /= 4.0f;
384+
gripStrength *= 0.25f;
383385
gripStrength = gripStrength > 0.8f ? 1.0f : gripStrength;
384386

385387
pinchStrength = Mathf.Pow(Mathf.Max(pinchStrength, gripStrength), 2.0f);
@@ -391,7 +393,7 @@ protected override bool UpdateHandJoints()
391393
// Only show this warning once
392394
else if (!displayedMaterialPropertyWarning)
393395
{
394-
Debug.LogWarning(String.Format("The property {0} for reacting to pinch strength was not found. A material with this property is required to visualize pinch strength.", pinchStrengthMaterialProperty));
396+
Debug.LogWarning(string.Format("The property {0} for reacting to pinch strength was not found. A material with this property is required to visualize pinch strength.", pinchStrengthMaterialProperty));
395397
displayedMaterialPropertyWarning = true;
396398
}
397399
}

Assets/MRTK/SDK/Profiles/ObsoleteMixedRealityXRSDKControllerVisualizationProfile.asset

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,7 @@ MonoBehaviour:
3333
controllerType:
3434
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKMotionController,
3535
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
36-
handedness: 1
37-
usePlatformModels: 1
38-
platformModelMaterial: {fileID: 0}
39-
overrideModel: {fileID: 0}
40-
controllerVisualizationType:
41-
reference: Microsoft.MixedReality.Toolkit.Input.WindowsMixedRealityControllerVisualizer,
42-
Microsoft.MixedReality.Toolkit.SDK
43-
- description: Windows Mixed Reality XRSDK Motion Controller
44-
controllerType:
45-
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKMotionController,
46-
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
47-
handedness: 2
36+
handedness: 3
4837
usePlatformModels: 1
4938
platformModelMaterial: {fileID: 0}
5039
overrideModel: {fileID: 0}
@@ -55,40 +44,18 @@ MonoBehaviour:
5544
controllerType:
5645
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKArticulatedHand,
5746
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
58-
handedness: 1
47+
handedness: 3
5948
usePlatformModels: 0
6049
platformModelMaterial: {fileID: 0}
6150
overrideModel: {fileID: 1227372834072826, guid: 378f91dbbff9e2343b27a467467750bf,
6251
type: 3}
6352
controllerVisualizationType:
6453
reference: Microsoft.MixedReality.Toolkit.Input.BaseHandVisualizer, Microsoft.MixedReality.Toolkit
65-
- description: Windows Mixed Reality XRSDK Articulated Hand
66-
controllerType:
67-
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKArticulatedHand,
68-
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
69-
handedness: 2
70-
usePlatformModels: 0
71-
platformModelMaterial: {fileID: 0}
72-
overrideModel: {fileID: 1788309537287834, guid: 132c9402d5843aa4f94380840186fd41,
73-
type: 3}
74-
controllerVisualizationType:
75-
reference: Microsoft.MixedReality.Toolkit.Input.BaseHandVisualizer, Microsoft.MixedReality.Toolkit
76-
- description: HP Motion Controller
77-
controllerType:
78-
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.HPMotionController,
79-
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
80-
handedness: 1
81-
usePlatformModels: 1
82-
platformModelMaterial: {fileID: 0}
83-
overrideModel: {fileID: 0}
84-
controllerVisualizationType:
85-
reference: Microsoft.MixedReality.Toolkit.Input.WindowsMixedRealityControllerVisualizer,
86-
Microsoft.MixedReality.Toolkit.SDK
8754
- description: HP Motion Controller
8855
controllerType:
8956
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.HPMotionController,
9057
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
91-
handedness: 2
58+
handedness: 3
9259
usePlatformModels: 1
9360
platformModelMaterial: {fileID: 0}
9461
overrideModel: {fileID: 0}

0 commit comments

Comments
 (0)