Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rigged hands in remoting #11267

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,11 @@ public class RiggedHandVisualizer : BaseHandVisualizer
/// </summary>
public SkinnedMeshRenderer HandRenderer => handRenderer;

/// <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;
public Material HandMaterial { get; private set; }

/// <summary>
/// Property name for modifying the mesh's appearance based on pinch strength
Expand All @@ -125,23 +120,23 @@ public class RiggedHandVisualizer : BaseHandVisualizer
/// <summary>
/// Precalculated values for LeapMotion testhand fingertip lengths
/// </summary>
private const float thumbFingerTipLength = 0.02167f;
private const float indexingerTipLength = 0.01582f;
private const float middleFingerTipLength = 0.0174f;
private const float ringFingerTipLength = 0.0173f;
private const float pinkyFingerTipLength = 0.01596f;
private const float ThumbFingerTipLength = 0.02167f;
private const float IndexFingerTipLength = 0.01582f;
private const float MiddleFingerTipLength = 0.0174f;
private const float RingFingerTipLength = 0.0173f;
private const float PinkyFingerTipLength = 0.01596f;

/// <summary>
/// Precalculated fingertip lengths used for scaling the fingertips of the skinnedmesh
/// to match with tracked hand fingertip size
/// </summary>
private Dictionary<TrackedHandJoint, float> fingerTipLengths = new Dictionary<TrackedHandJoint, float>()
{
{TrackedHandJoint.ThumbTip, thumbFingerTipLength },
{TrackedHandJoint.IndexTip, indexingerTipLength },
{TrackedHandJoint.MiddleTip, middleFingerTipLength },
{TrackedHandJoint.RingTip, ringFingerTipLength },
{TrackedHandJoint.PinkyTip, pinkyFingerTipLength }
{ TrackedHandJoint.ThumbTip, ThumbFingerTipLength },
{ TrackedHandJoint.IndexTip, IndexFingerTipLength },
{ TrackedHandJoint.MiddleTip, MiddleFingerTipLength },
{ TrackedHandJoint.RingTip, RingFingerTipLength },
{ TrackedHandJoint.PinkyTip, PinkyFingerTipLength }
};

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

/// <summary>
/// flag checking that the handRenderer was initialized with its own material
/// Flag checking that the handRenderer was initialized with its own material
/// </summary>
private bool handRendererInitialized = false;

Expand Down Expand Up @@ -268,10 +263,13 @@ protected override void Start()

// Give the hand mesh its own material to avoid modifying both hand materials when making property changes
MixedRealityHandTrackingProfile handTrackingProfile = CoreServices.InputSystem?.InputSystemProfile.HandTrackingProfile;

handMaterial = handTrackingProfile.RiggedHandMeshMaterial;
Material handMaterialInstance = new Material(handMaterial);
handRenderer.sharedMaterial = handMaterialInstance;
if (handTrackingProfile != null && handTrackingProfile.RiggedHandMeshMaterial != null)
{
#pragma warning disable CS0618 // Type or member is obsolete
HandMaterial = handTrackingProfile.RiggedHandMeshMaterial;
#pragma warning restore CS0618 // Type or member is obsolete
handRenderer.sharedMaterial = new Material(handTrackingProfile.RiggedHandMeshMaterial);
}
handRendererInitialized = true;
}

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

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

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

if (handMaterial != null && handRendererInitialized)
if (handTrackingProfile.RiggedHandMeshMaterial != null && handRendererInitialized)
{
float gripStrength = indexFingerCurl + middleFingerCurl + ringFingerCurl + pinkyFingerCurl;
gripStrength /= 4.0f;
gripStrength *= 0.25f;
gripStrength = gripStrength > 0.8f ? 1.0f : gripStrength;

pinchStrength = Mathf.Pow(Mathf.Max(pinchStrength, gripStrength), 2.0f);
Expand All @@ -391,7 +393,7 @@ protected override bool UpdateHandJoints()
// Only show this warning once
else if (!displayedMaterialPropertyWarning)
{
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));
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));
displayedMaterialPropertyWarning = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,7 @@ MonoBehaviour:
controllerType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKMotionController,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
handedness: 1
usePlatformModels: 1
platformModelMaterial: {fileID: 0}
overrideModel: {fileID: 0}
controllerVisualizationType:
reference: Microsoft.MixedReality.Toolkit.Input.WindowsMixedRealityControllerVisualizer,
Microsoft.MixedReality.Toolkit.SDK
- description: Windows Mixed Reality XRSDK Motion Controller
controllerType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKMotionController,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
handedness: 2
handedness: 3
usePlatformModels: 1
platformModelMaterial: {fileID: 0}
overrideModel: {fileID: 0}
Expand All @@ -55,40 +44,18 @@ MonoBehaviour:
controllerType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKArticulatedHand,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
handedness: 1
handedness: 3
usePlatformModels: 0
platformModelMaterial: {fileID: 0}
overrideModel: {fileID: 1227372834072826, guid: 378f91dbbff9e2343b27a467467750bf,
type: 3}
controllerVisualizationType:
reference: Microsoft.MixedReality.Toolkit.Input.BaseHandVisualizer, Microsoft.MixedReality.Toolkit
- description: Windows Mixed Reality XRSDK Articulated Hand
controllerType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityXRSDKArticulatedHand,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
handedness: 2
usePlatformModels: 0
platformModelMaterial: {fileID: 0}
overrideModel: {fileID: 1788309537287834, guid: 132c9402d5843aa4f94380840186fd41,
type: 3}
controllerVisualizationType:
reference: Microsoft.MixedReality.Toolkit.Input.BaseHandVisualizer, Microsoft.MixedReality.Toolkit
- description: HP Motion Controller
controllerType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.HPMotionController,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
handedness: 1
usePlatformModels: 1
platformModelMaterial: {fileID: 0}
overrideModel: {fileID: 0}
controllerVisualizationType:
reference: Microsoft.MixedReality.Toolkit.Input.WindowsMixedRealityControllerVisualizer,
Microsoft.MixedReality.Toolkit.SDK
- description: HP Motion Controller
controllerType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.HPMotionController,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
handedness: 2
handedness: 3
usePlatformModels: 1
platformModelMaterial: {fileID: 0}
overrideModel: {fileID: 0}
Expand Down