Пример #1
0
        /// <summary>
        /// During the update event, move the current interactor (containing also the
        /// trigger for detecting nearby interactableS) to the tracked position of the grip.
        ///
        /// That is the tracked wrist plus a pregenerated position and rotation offset.
        /// </summary>
        protected override void DoEveryUpdate()
        {
            base.DoEveryUpdate();

            _gripPoint.GetWorldPose(ref _trackedGripPose);
            _gripPoint.GetOffset(ref _wristToSnapOffset);

            _trackedPinchPose = _pinchPoint.GetPose();

            if (!SnapAddress.IsNullOrInvalid(_currentSnap)
                && _currentSnap.SnappedToPinch)
            {
                if (State == InteractorState.Select)
                {
                    _wristToSnapOffset.Premultiply(_snapOffset);
                }
                else
                {
                    Pose gripToPinchOffset = PoseUtils.RelativeOffset(_trackedPinchPose, _trackedGripPose);
                    _wristToSnapOffset.Premultiply(gripToPinchOffset);
                }
            }

            this.transform.SetPose(_trackedGripPose);
        }
Пример #2
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();
            }
        }
Пример #3
0
        /// <summary>
        /// When a new interactable is selected, start the grab at the ideal point. When snapping is
        /// involved that can be a point in the interactable offset from the hand
        /// which will be stored to progressively reduced it in the next updates,
        /// effectively attracting the object towards the hand.
        /// When no snapping is involved the point will be the grip point of the hand directly.
        /// Note: ideally this code would be in InteractableSelected but it needs
        /// to be called before the object is marked as active.
        /// </summary>
        /// <param name="snap">The selected Snap Data </param>
        protected override void InteractableSelected(HandGrabInteractable interactable)
        {
            if (SnapAddress.IsNullOrInvalid(_currentSnap))
            {
                base.InteractableSelected(interactable);
                return;
            }

            if (_currentSnap.SnappedToPinch)
            {
                _snapOffset = PoseUtils.RelativeOffset(_trackedPinchPose, _trackedGripPose);
            }
            else
            {
                _snapOffset = Pose.identity;
            }

            Pose handGrabStartPose = PoseUtils.Multiply(_trackedGripPose, _snapOffset);
            Pose interactableGrabStartPose = _currentSnap.WorldSnapPose;
            _movement = interactable.GenerateMovement(interactableGrabStartPose, handGrabStartPose);
            base.InteractableSelected(interactable);
        }
Пример #4
0
 public void Set(SnapAddress <TSnappable> other)
 {
     Set(other.Interactable, other.HandPose, other._snapPoint, other.SnappedToPinch);
 }