/// <summary> /// Update this hand's internal state with the Mixed Reality OpenXR HandJointLocation array. /// </summary> /// <param name="locations">The locations from a <see cref="HandTracker"/>.</param> public void UpdateHandJoints(HandJointLocation[] locations) { // If the hand was previously disabled, this is the first new update and it should be re-enabled if (!handRoot.activeSelf) { handRoot.SetActive(true); } foreach (HandJoint handJoint in HandJoints) { if (!handJointGameObjects.ContainsKey(handJoint)) { if (InstantiateJointPrefab(out GameObject jointObject)) { ColorJointObject(jointObject, handJoint, GetIndexOnFinger(handJoint)); } handJointGameObjects[handJoint] = jointObject; } GameObject handJointGameObject = handJointGameObjects[handJoint]; HandJointLocation handJointLocation = locations[(int)handJoint]; handJointGameObject.transform.SetPositionAndRotation(handJointLocation.Pose.position, handJointLocation.Pose.rotation); handJointGameObject.transform.localScale = Vector3.one * handJointLocation.Radius; } }
private void Apply(Transform jointTransform, HandJoint joint) { if (jointTransform == null) { return; } HandJointLocation location = handJointLocations[(int)joint]; Quaternion rot = location.Pose.rotation * Reorientation(handProxy); jointTransform.rotation = rot; }
private void ApplyWrist(Transform jointTransform, HandJoint joint) { if (jointTransform == null) { return; } HandJointLocation location = handJointLocations[(int)joint]; Quaternion rot = location.Pose.rotation * Reorientation(handProxy); Vector3 pos = location.Pose.position; jointTransform.SetPositionAndRotation(pos, rot); }
public void UpdateHandJoints(Hand hand, ref MixedRealityPose[] jointPoses) { #if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA) if (handTracker != null && handTracker.TryLocateHandJoints(FrameTime.OnUpdate, locations)) { if (jointPoses == null) { jointPoses = new MixedRealityPose[ArticulatedHandPose.JointCount]; } foreach (HandJoint handJoint in HandJoints) { HandJointLocation handJointLocation = locations[(int)handJoint]; // We want input sources to follow the playspace, so fold in the playspace transform here to // put the pose into world space. Vector3 position = MixedRealityPlayspace.TransformPoint(handJointLocation.Pose.position); Quaternion rotation = MixedRealityPlayspace.Rotation * handJointLocation.Pose.rotation; jointPoses[ConvertToArrayIndex(handJoint)] = new MixedRealityPose(position, rotation); } #else if (jointPoses == null) { jointPoses = new MixedRealityPose[ArticulatedHandPose.JointCount]; } foreach (HandFinger finger in HandFingers) { if (hand.TryGetRootBone(out Bone rootBone) && TryReadHandJoint(rootBone, out MixedRealityPose rootPose)) { jointPoses[(int)TrackedHandJoint.Palm] = rootPose; } if (hand.TryGetFingerBones(finger, fingerBones)) { for (int i = 0; i < fingerBones.Count; i++) { if (TryReadHandJoint(fingerBones[i], out MixedRealityPose pose)) { jointPoses[ConvertToArrayIndex(finger, i)] = pose; } } } #endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA) } }
/// <summary> /// Update the hand data from the device. /// </summary> /// <param name="interactionSourceState">The InteractionSourceState retrieved from the platform.</param> private void UpdateHandData(InputDevice inputDevice) { using (UpdateHandDataPerfMarker.Auto()) { #if MSFT_OPENXR if (handTracker != null && handTracker.TryLocateHandJoints(FrameTime.OnUpdate, locations)) { foreach (HandJoint handJoint in HandJoints) { HandJointLocation handJointLocation = locations[(int)handJoint]; // We want input sources to follow the playspace, so fold in the playspace transform here to // put the pose into world space. Vector3 position = MixedRealityPlayspace.TransformPoint(handJointLocation.Position); Quaternion rotation = MixedRealityPlayspace.Rotation * handJointLocation.Rotation; unityJointPoses[ConvertToTrackedHandJoint(handJoint)] = new MixedRealityPose(position, rotation); } #else if (inputDevice.TryGetFeatureValue(CommonUsages.handData, out Hand hand)) { foreach (HandFinger finger in handFingers) { if (hand.TryGetRootBone(out Bone rootBone)) { ReadHandJoint(TrackedHandJoint.Wrist, rootBone); } if (hand.TryGetFingerBones(finger, fingerBones)) { for (int i = 0; i < fingerBones.Count; i++) { ReadHandJoint(ConvertToTrackedHandJoint(finger, i), fingerBones[i]); } } } #endif // MSFT_OPENXR handDefinition?.UpdateHandJoints(unityJointPoses); } } }
public void UpdateHandJoints(InputDevice inputDevice, Dictionary <TrackedHandJoint, MixedRealityPose> jointPoses) { #if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA) if (handTracker != null && handTracker.TryLocateHandJoints(FrameTime.OnUpdate, locations)) { foreach (HandJoint handJoint in HandJoints) { HandJointLocation handJointLocation = locations[(int)handJoint]; // We want input sources to follow the playspace, so fold in the playspace transform here to // put the pose into world space. Vector3 position = MixedRealityPlayspace.TransformPoint(handJointLocation.Pose.position); Quaternion rotation = MixedRealityPlayspace.Rotation * handJointLocation.Pose.rotation; jointPoses[ConvertToTrackedHandJoint(handJoint)] = new MixedRealityPose(position, rotation); } #else if (inputDevice.TryGetFeatureValue(CommonUsages.handData, out Hand hand)) { foreach (HandFinger finger in HandFingers) { if (hand.TryGetRootBone(out Bone rootBone) && TryReadHandJoint(rootBone, out MixedRealityPose rootPose)) { jointPoses[TrackedHandJoint.Palm] = rootPose; } if (hand.TryGetFingerBones(finger, fingerBones)) { for (int i = 0; i < fingerBones.Count; i++) { if (TryReadHandJoint(fingerBones[i], out MixedRealityPose pose)) { jointPoses[ConvertToTrackedHandJoint(finger, i)] = pose; } } } } #endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA) } }