/// <summary> /// Initialize hand controller pairs corresponding to each of the hand model pairs /// configured in _handPool.HandPairs list. If any of the hand model in /// _handPool.HandPairs is not configured properly, its corresponding hand controller /// will be null and will not be updated afterwards. /// </summary> private void InitHandControllers() { _handModelCalibProfileManager = CalibrationProfileManager.Instance; _handControllerPairs = new List <LeftRightPair <UnityHandController> >(); _handControllers = new List <UnityHandController>(); int n = _handPool.HandPairs.Count; int vrControllerPairNum = _vrControllerObjReferencePairs.Count; for (int i = 0; i < n; i++) { UnityHandRepresentation leftRep = _handPool.HandPairs[i].Left; UnityHandController left = null; if (leftRep.Initialized) { HandModelCalibrationProfile profile = _handModelCalibProfileManager.FindProfile( leftRep.GraphicsHandModel.Hand); left = new UnityHandController(false, leftRep, this); GameObject vrControllerObj = i < vrControllerPairNum ? _vrControllerObjReferencePairs[i].Left : null; Debug.Log(leftRep.GraphicsHandModel.Hand + "+++++++++++++++"); Debug.Log(profile); Debug.Log("_handModelCalibProfileManager" + _handModelCalibProfileManager); //Debug.Log(vrControllerObj); //Debug.Log(rightRep.BendInwardLocalDirection); left.StartInit(profile, vrControllerObj, leftRep.BendInwardLocalDirection); _handControllers.Add(left); } UnityHandRepresentation rightRep = _handPool.HandPairs[i].Right; UnityHandController right = null; if (rightRep.Initialized) { HandModelCalibrationProfile profile = _handModelCalibProfileManager.FindProfile( rightRep.GraphicsHandModel.Hand); right = new UnityHandController(true, rightRep, this); GameObject vrControllerObj = i < vrControllerPairNum ? _vrControllerObjReferencePairs[i].Right : null; right.StartInit(profile, vrControllerObj, rightRep.BendInwardLocalDirection); _handControllers.Add(right); } LeftRightPair <UnityHandController> pair = new LeftRightPair <UnityHandController>(left, right); _handControllerPairs.Add(pair); } }
private float GetJointSplitAngle(UnityHandController hand, UnityHandRepresentation rep, int finger, int joint) { if (isReady) { var value = hand.GetCurrentFingerRotationInfo().Fingers[finger].Split.Value; var handProfile = profileMgr.FindProfile(rep.GraphicsHandModel.Hand); if (handProfile != null) { var angle = handProfile.Fingers[finger].Joints[joint].SplitAngleExtreme * value; return(angle); } } return(0); }
/* private float GetJointRotationAngle(UnityHandController hand, UnityHandRepresentation rep, int finger, int joint) * { * if (isReady) * { * var value = hand.GetCurrentFingerRotationInfo().Thumb.Rotate.Value; * var handProfile = profileMgr.FindProfile(rep.GraphicsHandModel.Hand); * if (handProfile != null) * { * // var angle = handProfile.Fingers[finger].Joints[joint]. value;\ * return 8; * } * } * return 0; * }*/ private float GetForceIndex(UnityHandController hand, UnityHandRepresentation rep) { if (isReady) { var handProfile = profileMgr.FindProfile(rep.GraphicsHandModel.Hand); //float currentForce = 0; if (handProfile != null) { var value = hand.Index.GetCollisionInfoOnTouch().FingerImpControlInfo.Stiffness; //var value = hand.GetCollisionInfoOnTouch().FingerImpControlInfo.Stiffness; return(value); } } return(0); }
private void FindController() { if (isReady) { return; } controller = DexmoController.Instance; profileMgr = CalibrationProfileManager.Instance; if (controller != null && profileMgr != null) { isReady = true; leftHand = controller.HandControllerPairs[0].Left; rightHand = controller.HandControllerPairs[0].Right; leftRep = controller.HandPool.HandPairs[0].Left; rightRep = controller.HandPool.HandPairs[0].Right; } }
/// <summary> /// When VR controller GameObject is used as the reference to move hand models, it switches /// the left/right VR controller reference for the left/right hand models, so if originally /// left VR conroller moves the left hand model, it is now the right VR controller that moves /// the left hand model. /// </summary> private void SwitchHandPositionAndAttitudeReference() { _isLeftRightReferenceReversed = !_isLeftRightReferenceReversed; int pairNum = _vrControllerObjReferencePairs.Count; int handControllerPairNum = _handControllerPairs.Count; for (int i = 0; i < pairNum && i < handControllerPairNum; i++) { LeftRightPair <UnityHandController> handControllerPair = _handControllerPairs[i]; LeftRightPair <GameObject> vrControllerObjReferencePair = _vrControllerObjReferencePairs[i]; GameObject leftReference = vrControllerObjReferencePair.Left; GameObject rightReference = vrControllerObjReferencePair.Right; UnityHandController leftHandController = handControllerPair.Left; UnityHandController rightHandController = handControllerPair.Right; if (_isLeftRightReferenceReversed) { if (leftHandController != null) { leftHandController.AssignPositionAndAttitudeReference(rightReference); } if (rightHandController != null) { rightHandController.AssignPositionAndAttitudeReference(leftReference); } } else { if (leftHandController != null) { leftHandController.AssignPositionAndAttitudeReference(leftReference); } if (rightHandController != null) { rightHandController.AssignPositionAndAttitudeReference(rightReference); } } } }
private void DisplayHandRotationNormalized(bool isRight) { string handLabel = isRight ? "Right Hand" : "Left Hand"; EditorGUILayout.LabelField(handLabel); EditorGUI.indentLevel++; if (_dexmoController.HandControllerPairs == null || _dexmoController.HandControllerPairs.Count == 0) { EditorGUILayout.LabelField(handLabel + " is not initialized."); } else { UnityHandController handController = isRight ? _dexmoController.HandControllerPairs[0].Right : _dexmoController.HandControllerPairs[0].Left; //if (!handController.Active) //{ // EditorGUILayout.LabelField(handLabel + " is not active."); //} //else { IHandRotationNormalized handRotation = handController.GetCurrentFingerRotationInfo(); int n = handRotation.Fingers.Length; for (int i = 0; i < n; i++) { IFingerRotationNormalized fingerRotation = handRotation.Fingers[i]; FingerType fingerType = (FingerType)i; EditorGUILayout.LabelField(fingerType.ToString()); DisplayFingerRotationNormalized(fingerRotation); } } } EditorGUI.indentLevel--; }
/// <summary> /// Update hand controllers with hand mocap data. /// </summary> void FixedUpdate() { if (_keyboardControlTest) { Hand fakeHandData; KeyboardControl(out fakeHandData); UnityHandController hc = _keyboardControlRight ? _handControllerPairs[0].Right : _handControllerPairs[0].Left; hc.FixedUpdate(fakeHandData); } else { if (LibdexmoClientController == null) { return; } if (!LibdexmoClientController.Connected) { print("LibdexmoClientController not connected."); return; } UpdateHandMotion(); } }