コード例 #1
0
        public void RegisterConfig(JointDeltaConfig config)
        {
            bool containsKeyAlready = _requestors.ContainsKey(config.InstanceID);

            Assert.IsFalse(containsKeyAlready,
                           "Trying to register multiple configs with the same id into " +
                           "JointDeltaProvider.");

            _requestors.Add(config.InstanceID, new List <HandJointId>(config.JointIDs));

            // Check if any new joints added, if so then add to cache
            foreach (var joint in config.JointIDs)
            {
                if (!_poseDataCache.ContainsKey(joint))
                {
                    _poseDataCache.Add(joint, new PoseData[2]
                    {
                        new PoseData(), new PoseData()
                    });

                    // New joint tracked, so write current data
                    PoseData toWrite = _poseDataCache[joint][CurDataIndex];
                    toWrite.IsValid = Hand.GetJointPose(joint, out toWrite.Pose);
                }
            }
        }
コード例 #2
0
        private void UpdateVisual()
        {
            if (!Hand.IsTrackedDataValid ||
                _rayInteractor.State == InteractorState.Disabled)
            {
                if (_skinnedMeshRenderer.enabled)
                {
                    _skinnedMeshRenderer.enabled = false;
                }
                return;
            }

            if (!_skinnedMeshRenderer.enabled)
            {
                _skinnedMeshRenderer.enabled = true;
            }

            if (!Hand.GetJointPose(HandJointId.HandIndex3, out var poseIndex3))
            {
                return;
            }
            if (!Hand.GetJointPose(HandJointId.HandThumb3, out var poseThumb3))
            {
                return;
            }

            var     isPinching    = _rayInteractor.State == InteractorState.Select;
            Vector3 midIndexThumb = Vector3.Lerp(poseThumb3.position, poseIndex3.position, 0.5f);

            var thisTransform = transform;
            var deltaTarget   = (_rayInteractor.End - thisTransform.position).normalized;

            thisTransform.position   = midIndexThumb;
            thisTransform.rotation   = Quaternion.LookRotation(deltaTarget, Vector3.up);
            thisTransform.localScale = Vector3.one * Hand.Scale;

            var mappedPinchStrength = _remapCurve.Evaluate(Hand.GetFingerPinchStrength(HandFinger.Index));

            _skinnedMeshRenderer.material.color = isPinching ? Color.white : new Color(1f, 1f, 1f, Mathf.Lerp(_alphaRange.x, _alphaRange.y, mappedPinchStrength));
            _skinnedMeshRenderer.SetBlendShapeWeight(0, mappedPinchStrength * 100f);
            _skinnedMeshRenderer.SetBlendShapeWeight(1, mappedPinchStrength * 100f);
        }
コード例 #3
0
 protected virtual void Update()
 {
     if (Hand.GetJointPose(_jointToTest, out Pose jointPose))
     {
         Active = JointPassesTests(jointPose);
     }
     else
     {
         Active = false;
     }
 }
コード例 #4
0
        private bool JointDistanceWithinThreshold()
        {
            if (HandA.GetJointPose(_jointIdA, out Pose poseA) &&
                HandB.GetJointPose(_jointIdB, out Pose poseB))
            {
                float threshold = _internalState ?
                                  _distance + _thresholdWidth * 0.5f :
                                  _distance - _thresholdWidth * 0.5f;

                return(Vector3.Distance(poseA.position, poseB.position) <= threshold);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        private bool PinchHasGoodVisibility(IHand hand)
        {
            if (!hand.GetJointPose(HandJointId.HandWristRoot, out Pose wristPose) ||
                !hand.GetCenterEyePose(out Pose centerEyePose))
            {
                return(false);
            }

            Vector3 handVector   = -1.0f * wristPose.forward;
            Vector3 targetVector = -1.0f * centerEyePose.forward;

            if (hand.Handedness == Handedness.Right)
            {
                handVector = -handVector;
            }

            float angle = Vector3.Angle(handVector, targetVector);

            return(angle <= PINCH_HQ_VIEW_ANGLE_THRESHOLD);
        }
コード例 #6
0
        private void UpdateDebugSkeletonLineRendererJoints()
        {
            if (!_initializedPositions)
            {
                _lineRenderer.positionCount = _jointsCovered.Count;
                _initializedPositions       = true;
            }

            if (Mathf.Abs(_lineRenderer.startWidth - _lineWidth) > Mathf.Epsilon)
            {
                _lineRenderer.startWidth = _lineWidth;
                _lineRenderer.endWidth   = _lineWidth;
            }

            int numJoints = _jointsCovered.Count;

            for (int i = 0; i < numJoints; i++)
            {
                if (_hand.GetJointPose(_jointsCovered[i], out Pose jointPose))
                {
                    _lineRenderer.SetPosition(i, jointPose.position);
                }
            }
        }