void UpdateHand(HandModel hand) { bool wasPinching = false; bool wasGrasping = false; float tempValue; int tempIndex; for (int i = 0; i < hand.fingers.Length; i++) { // Strength tempIndex = hand.fingers[i].bones.Length - 2; hand.fingers[i].strengthLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[i].bones[tempIndex], conf.maxLocalRotZ, conf.minLocalRotZ); // Flex hand.fingers[i].flexLerp = AvatarHelpers.GetFingerFlexion(hand.fingers[i], conf.minFlexRelDistance, hand.proxyHand.scale); // Base rotation (Closed/Opened) tempIndex = hand.fingers[i].bones.Length - 3; hand.fingers[i].baseRotationLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[i].bones[tempIndex], conf.maxLocalRotZ, conf.minLocalRotZ); hand.fingers[i].isClosed = hand.fingers[i].baseRotationLerp > conf.minLerpToClose; // Palm line hand.fingers[i].palmLineLerp = AvatarHelpers.GetPalmLineLerp(hand.fingers[i], conf.maxPalmRelDistance, conf.minPalmRelDistance, hand.proxyHand.scale); // Pinch tempValue = hand.fingers[i].pinchLerp; if (hand.fingers[i].flexLerp < conf.minFlexLerpToDisablePinch) { hand.fingers[i].pinchLerp = AvatarHelpers.GetFingerPinch(hand.fingers[i], conf.maxPinchRelDistance, conf.minPinchRelDistance, hand.proxyHand.scale); } else { hand.fingers[i].pinchLerp = 0.0f; } hand.fingers[i].pinchSpeed = (hand.fingers[i].pinchLerp - tempValue) / Time.deltaTime; if (hand.fingers[i] == hand.index) { wasPinching = hand.fingers[i].isPinching; } hand.fingers[i].isPinching = hand.fingers[i].pinchLerp > conf.minLerpToPinch; } // Fist hand.fistLerp = AvatarHelpers.GetHandFist(hand); hand.isFist = hand.fistLerp > conf.minLerpToFist; // Grasp tempValue = hand.graspLerp; hand.graspLerp = AvatarHelpers.GetHandGrasp(hand); hand.graspSpeed = (hand.graspLerp - tempValue) / Time.deltaTime; wasGrasping = hand.isGrasping; hand.isGrasping = hand.graspLerp > conf.minLerpToGrasp; // Ray if (hand.ray) { hand.ray.forward = AvatarHelpers.GetHandRayDirection(hand); hand.ray.gameObject.SetActive(Vector3.Dot(hand.palmNormal.forward, hand.ray.forward) > 0.0f); } if (hand is MasterHandModel) { EmitEvents(hand as MasterHandModel, hand.proxyHand.handler, wasPinching, wasGrasping); } }
void UpdateHand(HandModel hand, HandViewModel viewModel, CoreConfiguration conf) { bool wasGrasping = hand.isGrasping; float tempValue; int tempIndex; for (int f = 0; f < hand.fingers.Length; f++) { if (hand.fingers[f].bones.Length == 0) { continue; } bool wasPinching = hand.fingers[f].isPinching; if (model.strength) { // Strength if (hand.fingers[f].bones.Length >= 3) { tempIndex = hand.fingers[f].bones.Length - 2; } else { tempIndex = hand.fingers[f].bones.Length - 1; } hand.fingers[f].strengthLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[f].bones[tempIndex].transformRef, conf.maxLocalRotZ, conf.minLocalRotZ); } if (model.flex) { // Flex hand.fingers[f].flexLerp = AvatarHelpers.GetFingerFlexion(hand.fingers[f], conf.minFlexRelDistance, hand.proxyHand.scale); } if (model.grasp) { // Base rotation (Closed/Opened) hand.fingers[f].baseRotationLerp = AvatarHelpers.GetBoneRotLerp(hand.fingers[f].fingerBase, conf.maxLocalRotZ, conf.minLocalRotZ); hand.fingers[f].isClosed = hand.fingers[f].baseRotationLerp > conf.minLerpToClose; } if (model.fist) { // Palm line hand.fingers[f].palmLineLerp = AvatarHelpers.GetPalmLineLerp(hand.fingers[f], conf.maxPalmRelDistance, conf.minPalmRelDistance, hand.proxyHand.scale); } if (model.pinch) { // Pinch tempValue = hand.fingers[f].pinchLerp; if (hand.fingers[f].flexLerp < conf.minFlexLerpToDisablePinch) { hand.fingers[f].pinchLerp = AvatarHelpers.GetFingerPinch(hand.fingers[f], conf.maxPinchRelDistance, conf.minPinchRelDistance, hand.proxyHand.scale); } else { hand.fingers[f].pinchLerp = 0.0f; } // Pinch speed hand.fingers[f].pinchSpeed = (hand.fingers[f].pinchLerp - tempValue) / Time.deltaTime; // Is Pinching hand.fingers[f].isPinching = hand.fingers[f].pinchLerp > conf.minLerpToPinch; // Time counter if (hand.fingers[f].isPinching) { hand.fingers[f].timePinching += Time.deltaTime; } else { hand.fingers[f].timePinching = 0.0f; } // Gesture intention if (hand.fingers[f].isPinching) { hand.fingers[f].pinchIntentionTime = Mathf.Clamp(hand.fingers[f].timePinching, 0.0f, model.configuration.minTimeToIntention); } else { hand.fingers[f].pinchIntentionTime = Mathf.Clamp(hand.fingers[f].pinchIntentionTime - Time.deltaTime, 0.0f, model.configuration.minTimeToIntention); } hand.fingers[f].pinchIntentionLerp = Mathf.InverseLerp(0.0f, model.configuration.minTimeToIntention, hand.fingers[f].pinchIntentionTime); } // Events EmitFingerEvents(hand.fingers[f], viewModel.fingers[f], wasPinching); } if (model.fist) { // Fist hand.fistLerp = AvatarHelpers.GetHandFist(hand); hand.isFist = hand.fistLerp > model.minLerpToFist; } if (model.grasp) { // Grasp tempValue = hand.graspLerp; hand.graspLerp = AvatarHelpers.GetHandGrasp(hand); hand.graspSpeed = (hand.graspLerp - tempValue) / Time.deltaTime; hand.isGrasping = hand.graspLerp > model.minLerpToGrasp; // Time grasping if (hand.isGrasping) { hand.timeGrasping += Time.deltaTime; } else { hand.timeGrasping = 0.0f; } // Gesture intention if (hand.isGrasping) { hand.graspIntentionTime = Mathf.Clamp(hand.timeGrasping, 0.0f, model.configuration.minTimeToIntention); } else { hand.graspIntentionTime = Mathf.Clamp(hand.graspIntentionTime - Time.deltaTime, 0.0f, model.configuration.minTimeToIntention); } hand.graspIntentionLerp = Mathf.InverseLerp(0.0f, model.configuration.minTimeToIntention, hand.graspIntentionTime); } if (model.rays) { // Ray if (hand.ray && hand.proxyHand && hand.proxyHand.shoulderTip) { hand.ray.forward = AvatarHelpers.GetHandRayDirection(hand, hand.proxyHand.shoulderTip); hand.ray.gameObject.SetActive(Vector3.Dot(hand.palmNormal.forward, hand.ray.forward) > 0.0f); } } // Events EmitHandEvents(hand, viewModel, wasGrasping); }