示例#1
0
        public void UpdateBehaviour(IInteractionBehaviour behaviour, Hand _hand)
        {
            using (new ProfilerSample("Update Individual Classifier", behaviour.gameObject)) {
                GrabClassifierHeuristics.GrabClassifier classifier;
                Dictionary <IInteractionBehaviour, GrabClassifierHeuristics.GrabClassifier> classifiers = (_hand.IsLeft ? leftGrabClassifiers : rightGrabClassifiers);
                if (!classifiers.TryGetValue(behaviour, out classifier))
                {
                    classifier = new GrabClassifierHeuristics.GrabClassifier(behaviour.gameObject);
                    classifiers.Add(behaviour, classifier);
                }

                //Do the actual grab classification logic
                fillClassifier(_hand, ref classifier);
                GrabClassifierHeuristics.UpdateClassifier(classifier, collidingCandidates, numberOfColliders, scaledGrabParams);

                if (classifier.isGrabbing != classifier.prevGrabbing)
                {
                    if (classifier.isGrabbing)
                    {
                        if (!_manager.TwoHandedGrasping)
                        {
                            _manager.ReleaseObject(behaviour);
                        }
                        _manager.GraspWithHand(_hand, behaviour);
                    }
                    else if (behaviour.IsBeingGraspedByHand(_hand.Id))
                    {
                        _manager.ReleaseHand(_hand.Id);
                        classifier.coolDownProgress = 0f;
                    }
                }
                classifier.prevGrabbing = classifier.isGrabbing;
            }
        }
示例#2
0
 protected void fillClassifier(Hand _hand, ref GrabClassifierHeuristics.GrabClassifier classifier)
 {
     classifier.handChirality  = _hand.IsLeft;
     classifier.handDirection  = _hand.Direction.ToVector3();
     classifier.handXBasis     = _hand.Basis.xBasis.ToVector3();
     classifier.handGrabCenter = (_hand.PalmPosition + (_hand.Direction * 0.05f * _manager.SimulationScale) + (_hand.PalmNormal * 0.01f * _manager.SimulationScale)).ToVector3();
     for (int i = 0; i < _hand.Fingers.Count; i++)
     {
         classifier.probes[i].direction = _hand.Fingers[i].Direction.ToVector3();
     }
 }
        protected void FillClassifier(IInteractionBehaviour behaviour, Hand hand, ref GrabClassifierHeuristics.GrabClassifier classifier)
        {
            classifier.handChirality = hand.IsLeft;
            classifier.handDirection = hand.Direction.ToVector3();
            classifier.handXBasis    = hand.Basis.xBasis.ToVector3();
            float simScale = interactionHand.manager.SimulationScale;

            classifier.handGrabCenter = (hand.PalmPosition
                                         + (hand.Direction * 0.05f * simScale)
                                         + (hand.PalmNormal * 0.01f * simScale)).ToVector3();
            for (int i = 0; i < hand.Fingers.Count; i++)
            {
                classifier.probes[i].direction = hand.Fingers[i].Direction.ToVector3();
            }
            classifier.isGrabbed = behaviour.isGrasped;
        }
示例#4
0
        /// <summary>
        /// Returns true if the behaviour reflects the state-change (grasped or released) as specified by
        /// the graspMode.
        /// </summary>
        private bool updateBehaviour(IInteractionBehaviour behaviour, Hand hand, GraspUpdateMode graspMode, bool ignoreTemporal = false)
        {
            using (new ProfilerSample("Update Individual Grab Classifier", behaviour.gameObject))
            {
                // Ensure a classifier exists for this Interaction Behaviour.
                GrabClassifierHeuristics.GrabClassifier classifier;
                if (!_classifiers.TryGetValue(behaviour, out classifier))
                {
                    classifier = new GrabClassifierHeuristics.GrabClassifier(behaviour.gameObject);
                    _classifiers.Add(behaviour, classifier);
                }

                // Do the actual grab classification logic.
                FillClassifier(behaviour, hand, ref classifier);
                GrabClassifierHeuristics.UpdateClassifier(classifier, _scaledGrabParams,
                                                          ref _collidingCandidates,
                                                          ref _numberOfColliders,
                                                          ignoreTemporal);

                // Determine whether there was a state change.
                bool didStateChange = false;
                if (!classifier.prevThisControllerGrabbing && classifier.isThisControllerGrabbing &&
                    graspMode == GraspUpdateMode.BeginGrasp)
                {
                    didStateChange = true;

                    classifier.prevThisControllerGrabbing = classifier.isThisControllerGrabbing;
                }
                else if (classifier.prevThisControllerGrabbing && !classifier.isThisControllerGrabbing &&
                         interactionHand.graspedObject == behaviour && graspMode == GraspUpdateMode.ReleaseGrasp)
                {
                    didStateChange = true;

                    classifier.coolDownProgress           = 0f;
                    classifier.prevThisControllerGrabbing = classifier.isThisControllerGrabbing;
                }

                return(didStateChange);
            }
        }