/// <summary> /// Updates the states of all the skeleton actions for a specific input source (left hand / right hand / any) /// </summary> /// <param name="skipStateAndEventUpdates">Controls whether or not events are fired from this update call</param> protected static void UpdateSkeletonActions(SteamVR_Input_Sources inputSource, bool skipStateAndEventUpdates = false) { if (initialized == false) { return; } for (int actionIndex = 0; actionIndex < actionsSkeleton.Length; actionIndex++) { SteamVR_Action_Skeleton action = actionsSkeleton[actionIndex] as SteamVR_Action_Skeleton; if (action != null) { if (action.actionSet.IsActive()) { action.UpdateValue(inputSource, skipStateAndEventUpdates); } } } }
protected IEnumerator DoRangeOfMotionBlend(EVRSkeletalMotionRange oldRangeOfMotion, EVRSkeletalMotionRange newRangeOfMotion, float overTime) { float startTime = Time.time; float endTime = startTime + overTime; Vector3[] oldBonePositions; Quaternion[] oldBoneRotations; Vector3[] newBonePositions; Quaternion[] newBoneRotations; while (Time.time < endTime) { yield return(null); float lerp = (Time.time - startTime) / overTime; if (skeletonBlend > 0) { skeletonAction.SetRangeOfMotion(inputSource, oldRangeOfMotion); skeletonAction.UpdateValue(inputSource, true); oldBonePositions = (Vector3[])GetBonePositions(inputSource).Clone(); oldBoneRotations = (Quaternion[])GetBoneRotations(inputSource).Clone(); skeletonAction.SetRangeOfMotion(inputSource, newRangeOfMotion); skeletonAction.UpdateValue(inputSource, true); newBonePositions = GetBonePositions(inputSource); newBoneRotations = GetBoneRotations(inputSource); for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++) { if (bones[boneIndex] == null) { continue; } if (SteamVR_Utils.IsValid(newBoneRotations[boneIndex]) == false || SteamVR_Utils.IsValid(oldBoneRotations[boneIndex]) == false) { continue; } Vector3 blendedRangeOfMotionPosition = Vector3.Lerp(oldBonePositions[boneIndex], newBonePositions[boneIndex], lerp); Quaternion blendedRangeOfMotionRotation = Quaternion.Lerp(oldBoneRotations[boneIndex], newBoneRotations[boneIndex], lerp); if (skeletonBlend < 1) { SetBonePosition(boneIndex, Vector3.Lerp(bones[boneIndex].localPosition, blendedRangeOfMotionPosition, skeletonBlend)); SetBoneRotation(boneIndex, Quaternion.Lerp(bones[boneIndex].localRotation, blendedRangeOfMotionRotation, skeletonBlend)); } else { SetBonePosition(boneIndex, blendedRangeOfMotionPosition); SetBoneRotation(boneIndex, blendedRangeOfMotionRotation); } } } } rangeOfMotionBlendRoutine = null; }