示例#1
0
        private void GrabAttemp(Grabbable grabbable, float amount)
        {
            snapBack = false;
            if (grabbable == null)
            {
                currentGhost = null;
                this.puppet.SetDefaultPose();
                return;
            }
            SnappableObject snappable = grabbable.Snappable;

            if (snappable != null)
            {
                HandSnapPose userPose = this.puppet.CurrentPoseTracked(snappable.transform);

                HandGhost ghost = snappable.FindNearsetGhost(userPose, out float score, out var bestPlace);
                if (ghost != null)
                {
                    currentGhost = ghost;
                    poseInVolume = currentGhost.AdjustPlace(bestPlace);
                    offsetAmount = grabbingAmount = amount;
                }
                else
                {
                    currentGhost = null;
                    offsetAmount = grabbingAmount = 0f;
                }
            }
        }
        public HandGhost AddPose(HandPuppet puppet)
        {
            HandSnapPose pose  = puppet.CurrentPoseVisual(this.transform);
            HandGhost    ghost = Instantiate(handProvider.GetHand(pose.handeness), this.transform);

            ghost.SetPose(pose, this.transform);
            this.ghosts.Add(ghost);
            return(ghost);
        }
示例#3
0
        public HandSnapPose InvertedPose(Transform relativeTo) //relativeTo probably not needed
        {
            HandSnapPose invertedPose = pose;
            Quaternion   globalRot    = relativeTo.rotation * invertedPose.relativeGripRot;

            Quaternion invertedRot = Quaternion.AngleAxis(180f, volume.StartAngleDir) * globalRot;

            invertedPose.relativeGripRot = Quaternion.Inverse(relativeTo.rotation) * invertedRot;

            return(invertedPose);
        }
示例#4
0
 public void SetPose(HandSnapPose userPose, Transform relativeTo)
 {
     Puppet.TransitionToPose(userPose, relativeTo);
     RelativeTo      = relativeTo;
     _snapPoseVolume = new VolumetricPose()
     {
         pose        = userPose,
         volume      = new CylinderSurface(Puppet.Grip).MakeSinglePoint(),
         maxDistance = 0.1f
     };
 }
        public HandGhost FindNearsetGhost(HandSnapPose userPose, out float score, out (Vector3, Quaternion) bestPlace)
        {
            float     maxScore     = 0f;
            HandGhost nearestGhost = null;

            bestPlace = (Vector3.zero, Quaternion.identity);
            foreach (var ghost in this.ghosts)
            {
                float poseScore = ghost.CalculateBestPlace(userPose, out var place);
                if (poseScore > maxScore)
                {
                    nearestGhost = ghost;
                    maxScore     = poseScore;
                    bestPlace    = place;
                }
            }
            score = maxScore;
            return(nearestGhost);
        }
示例#6
0
        private void GrabStarted(Grabbable grabbable)
        {
            SnappableObject snappable = grabbable.Snappable;

            if (snappable != null)
            {
                HandSnapPose userPose = this.puppet.CurrentPoseTracked(snappable.transform);
                HandGhost    ghost    = snappable.FindNearsetGhost(userPose, out float score, out var bestPlace);

                if (ghost != null)
                {
                    currentGhost   = ghost;
                    poseInVolume   = currentGhost.AdjustPlace(bestPlace);
                    grabbingAmount = 1f;
                    offsetAmount   = 1f;
                    grabStartTime  = Time.timeSinceLevelLoad;
                    snapBack       = grabbable.CanMove && snappable.HandSnapBacks;
                    this.puppet.TransitionToPose(poseInVolume, currentGhost.RelativeTo, grabbingAmount, 1f);
                }
            }
        }
        private void HighlightNearestPose()
        {
            var grabbable = grabber.FindClosestGrabbable().Item1;

            if (grabbable != null && grabbable.Snappable != null)
            {
                HandSnapPose userPose = this.puppetHand.CurrentPoseTracked(grabbable.Snappable.transform);
                HandGhost    ghost    = grabbable.Snappable.FindNearsetGhost(userPose, out float score, out var bestPose);
                if (ghost != previousGhost)
                {
                    previousGhost?.Highlight(false);
                    previousGhost = ghost;
                }
                ghost?.Highlight(score);
            }
            else if (previousGhost != null)
            {
                previousGhost.Highlight(false);
                previousGhost = null;
            }
        }
示例#8
0
        public float CalculateBestPlace(HandSnapPose userPose, out (Vector3, Quaternion) bestPlace)
        {
            float        bestScore = 0f;
            HandSnapPose snapPose  = _snapPoseVolume.pose;

            if (snapPose.handeness != userPose.handeness &&
                !_snapPoseVolume.ambydextrous)
            {
                bestPlace = (Vector3.zero, Quaternion.identity);
                return(bestScore);
            }

            Vector3    globalPosDesired = RelativeTo.TransformPoint(userPose.relativeGripPos);
            Quaternion globalRotDesired = RelativeTo.rotation * userPose.relativeGripRot;

            (Vector3, Quaternion)desiredPlace = (globalPosDesired, globalRotDesired);

            var similarPlace = SimilarPlaceAtVolume(userPose, snapPose);
            var nearestPlace = NearestPlaceAtVolume(userPose, snapPose);

            bestPlace = GetBestPlace(similarPlace, nearestPlace, desiredPlace, out bestScore);

            if (_snapPoseVolume.handCanInvert)
            {
                HandSnapPose invertedPose = _snapPoseVolume.InvertedPose(RelativeTo);

                var similarInvertedPlace = SimilarPlaceAtVolume(userPose, invertedPose);
                var nearestInvertedPlace = NearestPlaceAtVolume(userPose, invertedPose);
                var bestInvertedPlace    = GetBestPlace(similarInvertedPlace, nearestInvertedPlace, desiredPlace, out float bestInvertedScore);

                if (bestInvertedScore > bestScore)
                {
                    bestPlace = bestInvertedPlace;
                    return(bestInvertedScore);
                }
            }

            return(bestScore);
        }