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); } } }
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); }
protected virtual void Update() { if (Hand.GetJointPose(_jointToTest, out Pose jointPose)) { Active = JointPassesTests(jointPose); } else { Active = false; } }
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); } }
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); }
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); } } }