I’m working on a Unity project using MRTK3 for Hololens 2. I want to measure the distance between two pinch points in hand interaction, display a line between these points using a Line Renderer, and show the distance using TextMeshPro.
I tried using the IMixedRealityHandJointHandler interface and MixedRealityPose type from MRTK2, but these don’t seem to be available in MRTK3. I’m getting errors like The type or namespace name 'MixedRealityPose' could not be found.
Here’s the code I tried:
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;
public class MeasurePinchDistance : MonoBehaviour, IMixedRealityHandJointHandler
{
private Vector3 pinchPoint1;
private Vector3 pinchPoint2;
private bool isPinching = false;
public void OnHandJointsUpdated(InputEventData<IDictionary<TrackedHandJoint, MixedRealityPose>> eventData)
{
if (eventData.Handedness == Handedness.Right)
{
var handPose = eventData.InputData[TrackedHandJoint.IndexTip];
if (handPose.Position.y > 0.5f && !isPinching)
{
isPinching = true;
pinchPoint1 = handPose.Position;
}
else if (handPose.Position.y <= 0.5f && isPinching)
{
isPinching = false;
pinchPoint2 = handPose.Position;
Debug.Log("Distance between pinch points: " + Vector3.Distance(pinchPoint1, pinchPoint2));
}
}
}
}
Can anyone help me modify this script for MRTK3 or suggest an alternative approach?
I tried the code above. I also mentioned the errors I keep getting.
The namespaces used by MRTK 3 and MRTK 2 are different. Regarding obtaining joints in MRTK 3, please refer to the examples in this document - Hand tracking - MRTK3 | Microsoft Learn.