/// <summary> /// Adds the joint poses calculated from the Leap Motion Controller to the jointPoses Dictionary. /// </summary> private void SetJointPoses() { foreach (TrackedHandJoint joint in TrackedHandJointEnum) { if (attachmentHand != null && attachmentHand.isTracked) { // Is the current joint a metacarpal bool isMetacarpal = metacarpals.Contains(joint); // AttachmentPointFlags does not include metacarpals. if (isMetacarpal) { MixedRealityPose metacarpalPose = GetMetacarpalPose(joint); jointPoses[joint] = metacarpalPose; } else { AttachmentPointFlags leapAttachmentFlag = ConvertMRTKJointToLeapJoint(joint); // Get the pose of the leap joint AttachmentPointBehaviour leapJoint = attachmentHand.GetBehaviourForPoint(leapAttachmentFlag); // Set the pose calculated by the leap motion to a mixed reality pose MixedRealityPose pose = new MixedRealityPose(leapJoint.transform.position, leapJoint.transform.rotation); jointPoses[joint] = pose; } } else { jointPoses[joint] = MixedRealityPose.ZeroIdentity; } } }
// Use this for initialization void Start() { _thisFinger = GetComponent <AttachmentPointBehaviour>(); if (_palm != null && _thisFinger != null) { Initialize(); } }
private void onUpdateFrame(Frame frame) { if (frame == null) { Debug.Log("Frame null"); } var hand = frame.Hands.Query() .FirstOrDefault(h => h.IsLeft == (whichHand == Chirality.Left)); bool shouldStream = false; Pose streamPose = Pose.identity; if (hand != null) { _isHandTracked = true; if (enabled && gameObject.activeInHierarchy) { Vector3 pointPosition; Quaternion pointRotation; AttachmentPointBehaviour.GetLeapHandPointData(hand, attachmentPoint, out pointPosition, out pointRotation); // Replace wrist rotation data with that from the palm for now. if (attachmentPoint == AttachmentPointFlags.Wrist && usePalmRotationForWrist) { Vector3 unusedPos; AttachmentPointBehaviour.GetLeapHandPointData(hand, AttachmentPointFlags.Palm, out unusedPos, out pointRotation); } if (attachmentPoint == AttachmentPointFlags.Wrist) { // TODO: Fix wrist position for edit-time hands. // Artificially shift the wrist position down because for some reason it's // not so great. if (!Application.isPlaying) { pointPosition -= pointRotation * Vector3.forward * 0.02f; } } this.transform.position = pointPosition; this.transform.rotation = pointRotation; streamPose = new Pose(pointPosition, pointRotation); var streamOffset = Pose.identity; if (usePoseStreamOffset && poseStreamOffsetSource != null) { streamOffset = poseStreamOffsetSource.transform.ToWorldPose() .From(streamPose); } streamPose = streamPose.Then(streamOffset); shouldStream = true; } } else { _isHandTracked = false; } // Pose Stream data. shouldStream &= doPoseStream; shouldStream &= Application.isPlaying; shouldStream &= this.enabled && gameObject.activeInHierarchy; if (!shouldStream && _isStreamOpen) { OnClose(); _isStreamOpen = false; } if (shouldStream && !_isStreamOpen) { OnOpen(); _isStreamOpen = true; } if (shouldStream) { OnSend(streamPose); } }
private void Awake() { _attachment = GetComponent <AttachmentPointBehaviour>(); _HandLeftPositionId = Shader.PropertyToID("_HandLeftPosition"); _HandRightPositionId = Shader.PropertyToID("_HandRightPosition"); }