public Transform GetHandTransform(HandType hand, HandJoint joint) { if (hand >= HandType.Max || joint >= HandJoint.Max) { return(null); } var HandObject = hand == HandType.Left ? HandLeft : HandRight; if (HandObject != null) { var AvatarComponent = HandObject.GetComponent <OvrAvatarComponent>(); if (AvatarComponent != null && AvatarComponent.RenderParts.Count > 0) { var SkinnedMesh = AvatarComponent.RenderParts[0]; return(SkinnedMesh.transform.Find(HandJoints[(int)hand, (int)joint])); } } return(null); }
private static void ColorJointObject(GameObject jointObject, HandJoint finger, int?index) { Color jointColor = Color.magenta; string fingerName = finger.ToString(); const string Thumb = "Thumb"; const string Index = "Index"; const string Middle = "Middle"; const string Ring = "Ring"; const string Little = "Little"; if (fingerName.StartsWith(Thumb)) { jointColor = Color.red; } else if (fingerName.StartsWith(Index)) { jointColor = new Color(1.0f, 0.647f, 0.0f); // Orange } else if (fingerName.StartsWith(Middle)) { jointColor = Color.yellow; } else if (fingerName.StartsWith(Ring)) { jointColor = Color.green; } else if (fingerName.StartsWith(Little)) { jointColor = Color.blue; } // Lighten the colors as we go up the finger. int i = index ?? 0; float saturation = 1.0f - (i * 0.15f); Color.RGBToHSV(jointColor, out float h, out float _, out float v); jointObject.GetComponent <Renderer>().material.color = Color.HSVToRGB(h, saturation, v); }
/// :End: public static void DrawHandSize() { for (int h = 0; h < (int)Handed.Max; h++) { Hand hand = Input.Hand((Handed)h); if (!hand.IsTracked) { continue; } HandJoint at = hand[FingerId.Middle, JointId.Tip]; Vec3 pos = at.position + at.Pose.Forward * at.radius; Quat rot = at.orientation * Quat.FromAngles(-90, 0, 0); if (!HandFacingHead((Handed)h)) { rot = rot * Quat.FromAngles(0, 180, 0); } Text.Add( (hand.size * 100).ToString(".0") + "cm", Matrix.TRS(pos, rot, 0.3f), TextAlign.XCenter | TextAlign.YBottom); } }
public Transform GetJoint(HandJoint joint) { return(jointMap[joint]); }
private bool TryGetJoint(HandJoint joint, out IvJointPos pose) { return(jointPoses.TryGetValue(joint, out pose)); }
public static void GetJointFromGameobjectName(string name, out HandType hand, out HandJoint joint) { if (name.Contains("_r_")) { hand = HandType.Right; } else if (name.Contains("_l_")) { hand = HandType.Left; } else { hand = HandType.Max; } if (name.Contains("thumb")) { joint = HandJoint.ThumbTip; } else if (name.Contains("index")) { joint = HandJoint.IndexTip; } else if (name.Contains("middle")) { joint = HandJoint.MiddleTip; } else if (name.Contains("ring")) { joint = HandJoint.RingTip; } else if (name.Contains("pinky")) { joint = HandJoint.PinkyTip; } else { joint = HandJoint.Max; } }
// Only works when the input joint is a fingertip // returns FingerState.Max otherwise private static FingerShape _GetFingerShapeFromPosition(HandType hand, HandJoint joint, Vector3[,] userFingertipPosition) { var thumbVector = HAND_FRAME_VECTORS[(int)hand, (int)HandFrame.Thumb]; var fingerVector = HAND_FRAME_VECTORS[(int)hand, (int)HandFrame.Fingers]; var palmVector = HAND_FRAME_VECTORS[(int)hand, (int)HandFrame.Palm]; var fingerIdx = JointFingerMap(joint); if (fingerIdx >= 0) { joint = fingertips[fingerIdx]; } else { joint = HandJoint.Max; } if (joint == HandJoint.ThumbTip) { var pos = userFingertipPosition[(int)hand, 0]; if (Vector3.Dot(pos, thumbVector) > 0.1) { return(FingerShape.Extended); } else if (Vector3.Dot(pos, thumbVector) > 0.02) { return(FingerShape.Midway); } else { return(FingerShape.Closed); } } else if (joint == HandJoint.IndexTip) { var pos = userFingertipPosition[(int)hand, fingerIdx]; if (Vector3.Dot(pos, fingerVector) > 0.13 && Vector3.Dot(pos, palmVector) < 0.01) { return(FingerShape.Extended); } else if (Vector3.Dot(pos, fingerVector) > 0.112) { return(FingerShape.Bent); } else if (Vector3.Dot(pos, palmVector) > 0.05) { return(FingerShape.Midway); } else { return(FingerShape.Closed); } } else if (joint != HandJoint.Max) { var pos = userFingertipPosition[(int)hand, fingerIdx]; if (Vector3.Dot(pos, fingerVector) > 0.13 && Vector3.Dot(pos, palmVector) < 0.01) { return(FingerShape.Extended); } else if (Vector3.Dot(pos, fingerVector) > 0.1 && Vector3.Dot(pos, palmVector) < 0.05) { return(FingerShape.Bent); } else if (Vector3.Dot(pos, palmVector) > 0.05) { return(FingerShape.Midway); } else { return(FingerShape.Closed); } } else { return(FingerShape.Max); } }
// Only works when the input joint is a fingertip // returns FingerState.Max otherwise public static FingerShape GetFingerShape(HandType hand, HandJoint joint) { return(_GetFingerShapeFromPosition(hand, joint, cachedPoseData.LatestFrame().FingerPosition)); }
private int ConvertToArrayIndex(HandJoint handJoint) { TrackedHandJoint trackedHandJoint; switch (handJoint) { case HandJoint.Palm: trackedHandJoint = TrackedHandJoint.Palm; break; case HandJoint.Wrist: trackedHandJoint = TrackedHandJoint.Wrist; break; case HandJoint.ThumbMetacarpal: trackedHandJoint = TrackedHandJoint.ThumbMetacarpalJoint; break; case HandJoint.ThumbProximal: trackedHandJoint = TrackedHandJoint.ThumbProximalJoint; break; case HandJoint.ThumbDistal: trackedHandJoint = TrackedHandJoint.ThumbDistalJoint; break; case HandJoint.ThumbTip: trackedHandJoint = TrackedHandJoint.ThumbTip; break; case HandJoint.IndexMetacarpal: trackedHandJoint = TrackedHandJoint.IndexMetacarpal; break; case HandJoint.IndexProximal: trackedHandJoint = TrackedHandJoint.IndexKnuckle; break; case HandJoint.IndexIntermediate: trackedHandJoint = TrackedHandJoint.IndexMiddleJoint; break; case HandJoint.IndexDistal: trackedHandJoint = TrackedHandJoint.IndexDistalJoint; break; case HandJoint.IndexTip: trackedHandJoint = TrackedHandJoint.IndexTip; break; case HandJoint.MiddleMetacarpal: trackedHandJoint = TrackedHandJoint.MiddleMetacarpal; break; case HandJoint.MiddleProximal: trackedHandJoint = TrackedHandJoint.MiddleKnuckle; break; case HandJoint.MiddleIntermediate: trackedHandJoint = TrackedHandJoint.MiddleMiddleJoint; break; case HandJoint.MiddleDistal: trackedHandJoint = TrackedHandJoint.MiddleDistalJoint; break; case HandJoint.MiddleTip: trackedHandJoint = TrackedHandJoint.MiddleTip; break; case HandJoint.RingMetacarpal: trackedHandJoint = TrackedHandJoint.RingMetacarpal; break; case HandJoint.RingProximal: trackedHandJoint = TrackedHandJoint.RingKnuckle; break; case HandJoint.RingIntermediate: trackedHandJoint = TrackedHandJoint.RingMiddleJoint; break; case HandJoint.RingDistal: trackedHandJoint = TrackedHandJoint.RingDistalJoint; break; case HandJoint.RingTip: trackedHandJoint = TrackedHandJoint.RingTip; break; case HandJoint.LittleMetacarpal: trackedHandJoint = TrackedHandJoint.PinkyMetacarpal; break; case HandJoint.LittleProximal: trackedHandJoint = TrackedHandJoint.PinkyKnuckle; break; case HandJoint.LittleIntermediate: trackedHandJoint = TrackedHandJoint.PinkyMiddleJoint; break; case HandJoint.LittleDistal: trackedHandJoint = TrackedHandJoint.PinkyDistalJoint; break; case HandJoint.LittleTip: trackedHandJoint = TrackedHandJoint.PinkyTip; break; default: trackedHandJoint = TrackedHandJoint.None; break; } return((int)trackedHandJoint); }