Exemplo n.º 1
0
        /// <summary>
        /// Gets the position of where grasp happens
        /// For sixdof it's just the pointer origin
        /// for hand it's the average of index and thumb.
        /// </summary>
        public bool TryGetNearGraspPoint(out Vector3 result)
        {
            // For now, assume that anything that is a sphere pointer is a hand
            // TODO: have a way to determine if this is a fully articulated hand and return
            // ray origin if it's a sixdof
            if (Controller != null && Controller is IMixedRealityHand)
            {
                HandJointUtils.TryGetJointPose(TrackedHandJoint.IndexTip, Controller.ControllerHandedness, out MixedRealityPose index);
                HandJointUtils.TryGetJointPose(TrackedHandJoint.ThumbTip, Controller.ControllerHandedness, out MixedRealityPose thumb);
                if (index != null && thumb != null)
                {
                    // result = 0.5f * (index.position + thumb.position);
                    result = index.Position;
                    return(true);
                }
            }
            else
            {
                result = Position;
                return(true);
            }

            result = Vector3.zero;
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries and get's hand joints based on the current pointer.
        /// </summary>
        /// <param name="joint">The joint type to get.</param>
        /// <param name="position">Out parameter filled with joint position, otherwise
        /// <see href="https://docs.unity3d.com/ScriptReference/Vector3-zero.html">Vector3.zero</see></param>
        /// <param name="rotation">Out parameter filled with joint rotation, otherwise
        /// <see href="https://docs.unity3d.com/ScriptReference/Quaternion-identity.html">Quaternion.identity</see></param>
        /// <returns></returns>
        protected bool TryGetJoint(TrackedHandJoint joint, out Vector3 position, out Quaternion rotation)
        {
            if (Pointer != null && Pointer.Controller != null)
            {
                if (HandJointUtils.TryGetJointPose(joint, Pointer.Controller.ControllerHandedness, out MixedRealityPose handJoint))
                {
                    position = handJoint.Position;
                    rotation = handJoint.Rotation;

                    return(true);
                }
            }

            position = Vector3.zero;
            rotation = Quaternion.identity;

            return(false);
        }
        public void RecordHandStop()
        {
            MixedRealityPose[] jointPoses = new MixedRealityPose[jointCount];
            for (int i = 0; i < jointCount; ++i)
            {
                HandJointUtils.TryGetJointPose <WindowsMixedRealityArticulatedHand>((TrackedHandJoint)i, recordingHand, out jointPoses[i]);
            }

            ArticulatedHandPose pose = new ArticulatedHandPose();

            pose.ParseFromJointPoses(jointPoses, recordingHand, Quaternion.identity, offset);

            recordingHand = Handedness.None;

            var filename = String.Format("{0}-{1}.json", OutputFileName, DateTime.UtcNow.ToString("yyyyMMdd-HHmmss"));

            StoreRecordedHandPose(pose.ToJson(), filename);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Record a keyframe at the given time for a hand with the given handedness it is tracked.
        /// </summary>
        private bool RecordInputHandData(Handedness handedness)
        {
            float time    = Time.time;
            var   profile = InputRecordingProfile;

            var hand = HandJointUtils.FindHand(handedness);

            if (hand == null)
            {
                recordingBuffer.AddHandStateKey(time, handedness, false, false);
                return(false);
            }

            bool isTracked = (hand.TrackingState == TrackingState.Tracked);

            // Extract extra information from current interactions
            bool isPinching = false;

            for (int i = 0; i < hand.Interactions?.Length; i++)
            {
                var interaction = hand.Interactions[i];
                switch (interaction.InputType)
                {
                case DeviceInputType.Select:
                    isPinching = interaction.BoolData;
                    break;
                }
            }

            recordingBuffer.AddHandStateKey(time, handedness, isTracked, isPinching);

            if (isTracked)
            {
                for (int i = 0; i < jointCount; ++i)
                {
                    if (hand.TryGetJoint((TrackedHandJoint)i, out MixedRealityPose jointPose))
                    {
                        recordingBuffer.AddHandJointKey(time, handedness, (TrackedHandJoint)i, jointPose, profile.JointPositionThreshold, profile.JointRotationThreshold);
                    }
                }
            }

            return(true);
        }
        void Update()
        {
            if (UnityEngine.Input.GetKeyDown(KeyCode.F9))
            {
                HandJointUtils.TryGetJointPose(ReferenceJoint, Handedness.Left, out MixedRealityPose joint);
                offset = joint.Position;
            }
            if (UnityEngine.Input.GetKeyUp(KeyCode.F9))
            {
                RecordPose(Handedness.Left);
            }

            if (UnityEngine.Input.GetKeyDown(KeyCode.F10))
            {
                HandJointUtils.TryGetJointPose(ReferenceJoint, Handedness.Right, out MixedRealityPose joint);
                offset = joint.Position;
            }
            if (UnityEngine.Input.GetKeyUp(KeyCode.F10))
            {
                RecordPose(Handedness.Right);
            }
        }
 private void RecordHandStart(Handedness handedness)
 {
     HandJointUtils.TryGetJointPose <WindowsMixedRealityArticulatedHand>(ReferenceJoint, handedness, out MixedRealityPose joint);
     offset        = joint.Position;
     recordingHand = handedness;
 }
 private void GetJointPosition(Vector3[] positions, TrackedHandJoint jointId, Handedness handedness)
 {
     HandJointUtils.TryGetJointPose(jointId, handedness, out MixedRealityPose joint);
     positions[(int)jointId] = joint.Position;
 }