/// <summary> /// Interpolates between two HandPoses, if they have the same handeness and bones. /// </summary> /// <param name="from">Base HandPose to interpolate from.</param> /// <param name="to">Target HandPose to interpolate to.</param> /// <param name="t">Interpolation factor, 0 for the base, 1 for the target.</param> /// <returns>A new HandPose positioned/rotated between the base and target, null if the hands cannot be interpolated.</returns> public static HandPose?Lerp(HandPose from, HandPose to, float t) { if (from.handeness != to.handeness) { Debug.LogError("Hand poses must have same handenness for lerping"); return(null); } if (from.Bones.Count != to.Bones.Count) { Debug.LogError("Hand poses must have same Bones for lerping"); return(null); } HandPose result = new HandPose(); result.relativeGrip = PoseUtils.Lerp(from.relativeGrip, to.relativeGrip, t); result.handeness = from.handeness; result.Bones.Clear(); for (int i = 0; i < from.Bones.Count; i++) { BonePose?bone = BonePose.Lerp(from.Bones[i], to.Bones[i], t); if (bone.HasValue) { result.Bones.Add(bone.Value); } else { Debug.LogError("Hand poses must have same Bones for lerping"); return(null); } } return(result); }
/// <summary> /// Gets the interpolated value between two rotations of the same bone (same indentifier). /// </summary> /// <param name="from">Base rotation to interpolate from.</param> /// <param name="to">Target rotation to interpolate to.</param> /// <param name="t">Interpolation factor, 0 for base, 1 for target rotation</param> /// <returns>A new BonePose between base and target, null if bone is invalid.</returns> public static BonePose?Lerp(BonePose from, BonePose to, float t) { if (from.boneID != to.boneID) { Debug.LogError("Bones must have same id for interpolation"); return(null); } return(new BonePose() { boneID = from.boneID, rotation = Quaternion.Lerp(from.rotation, to.rotation, t), position = Vector3.Lerp(from.position, to.position, t) }); }
private void SetLivePose(SkeletonDataProvider skeletonData) { BonePose[] fingers = skeletonData.Fingers; BonePose hand = skeletonData.Hand; for (int i = 0; i < fingers.Length; ++i) { BoneId boneId = fingers[i].boneID; if (BonesCache.ContainsKey(boneId)) { Transform boneTransform = BonesCache[boneId].transform; Quaternion desiredRot = BonesCache[boneId].RotationOffset * fingers[i].rotation; boneTransform.localRotation = desiredRot; } } Pose rootPose = new Pose(hand.position, hand.rotation); SetRootPose(rootPose, false); }