Esempio n. 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;
            }
        }
Esempio n. 2
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);
            }
        }