Example #1
0
        protected virtual void ComputeBestSnapAddress(ref SnapAddress snapAddress)
        {
            IEnumerable<HandGrabInteractable> interactables = HandGrabInteractable.Registry.List(this);
            float bestFingerScore = -1f;
            float bestPoseScore = -1f;

            foreach (HandGrabInteractable interactable in interactables)
            {
                float fingerScore = 1.0f;
                if (!HandGrab.ComputeShouldSelect(this, interactable, out GrabTypeFlags selectingGrabTypes))
                {
                    fingerScore = HandGrab.ComputeHandGrabScore(this, interactable, out selectingGrabTypes);
                }
                if (fingerScore < bestFingerScore)
                {
                    continue;
                }

                bool usePinchPoint = CanSnapToPinchPoint(interactable, selectingGrabTypes);
                Pose grabPoint = usePinchPoint ? _trackedPinchPose : _trackedGripPose;
                bool poseFound = interactable.CalculateBestPose(grabPoint, Hand.Scale, Hand.Handedness,
                    ref _cachedBestHandPose, ref _cachedBestSnapPoint,
                    out bool usesHandPose, out float poseScore);

                if (!poseFound)
                {
                    continue;
                }

                if (fingerScore > bestFingerScore
                    || poseScore > bestPoseScore)
                {
                    bestFingerScore = fingerScore;
                    bestPoseScore = poseScore;
                    HandPose handPose = usesHandPose ? _cachedBestHandPose : null;
                    snapAddress.Set(interactable, handPose, _cachedBestSnapPoint, usePinchPoint);
                }

            }

            if (bestFingerScore < 0)
            {
                snapAddress.Clear();
            }
        }
Example #2
0
        /// <summary>
        /// Each call while the interactor is hovering, it checks whether there is an interaction
        /// being hovered and sets the target snapping address to it. In the HandToObject snapping
        /// behaviors this is relevant as the hand can approach the object progressively even before
        /// a true grab starts.
        /// </summary>
        protected override void DoHoverUpdate()
        {
            base.DoHoverUpdate();
            if (_currentSnap.IsValidAddress)
            {
                SnapStrength = HandGrab.ComputeHandGrabScore(this, Interactable,
                    out GrabTypeFlags hoverGrabTypes);
                SnapData = _currentSnap;
            }
            else
            {
                SnapStrength = 0f;
                SnapData = null;
            }

            if (Interactable != null)
            {
                ShouldSelect = HandGrab.ComputeShouldSelect(this, Interactable,
                    out GrabTypeFlags selectingGrabTypes);
            }
        }