protected virtual void CheckSkeletonAction() { if (skeletonAction == null) { skeletonAction = SteamVR_Input.GetAction <SteamVR_Action_Skeleton0>("Skeleton" + inputSource.ToString()); } }
public void UpdateAdditiveAnimation(SteamVR_Action_Skeleton0 skeletonAction, SteamVR_Input_Sources inputSource) { SteamVR_Skeleton_PoseSnapshot0 snapshot = GetHandSnapshot(inputSource); SteamVR_Skeleton_Pose_Hand0 poseHand = pose.GetHand(inputSource); for (int boneIndex = 0; boneIndex < snapshotL.bonePositions.Length; boneIndex++) { int fingerIndex = SteamVR_Skeleton_JointIndexes0.GetFingerForBone(boneIndex); SteamVR_Skeleton_FingerExtensionTypes extensionType = poseHand.GetMovementTypeForBone(boneIndex); if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Free) { snapshot.bonePositions[boneIndex] = skeletonAction.bonePositions[boneIndex]; snapshot.boneRotations[boneIndex] = skeletonAction.boneRotations[boneIndex]; } if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Extend) { // lerp to open pose by fingercurl snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], skeletonAction.bonePositions[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]); snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], skeletonAction.boneRotations[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]); } if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Contract) { // lerp to closed pose by fingercurl snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], skeletonAction.bonePositions[boneIndex], skeletonAction.fingerCurls[fingerIndex]); snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], skeletonAction.boneRotations[boneIndex], skeletonAction.fingerCurls[fingerIndex]); } } }
/// <summary> /// Updates all pose animation and blending. Can be called from different places without performance concerns, as it will only let itself run once per frame. /// </summary> public void UpdatePose(SteamVR_Action_Skeleton0 skeletonAction, SteamVR_Input_Sources inputSource) { // only allow this function to run once per frame if (poseUpdatedThisFrame) { return; } poseUpdatedThisFrame = true; // always do additive animation on main pose blendPoses[0].UpdateAdditiveAnimation(skeletonAction, inputSource); //copy from main pose as a base SteamVR_Skeleton_PoseSnapshot0 snap = GetHandSnapshot(inputSource); snap.CopyFrom(blendPoses[0].GetHandSnapshot(inputSource)); ApplyBlenderBehaviours(skeletonAction, inputSource, snap); if (inputSource == SteamVR_Input_Sources.RightHand) { blendedSnapshotR = snap; } if (inputSource == SteamVR_Input_Sources.LeftHand) { blendedSnapshotL = snap; } }
private void OnTrackingChanged(SteamVR_Action_Skeleton0 fromAction, ETrackingResult trackingState) { if (onTrackingChanged != null) { onTrackingChanged.Invoke(this, inputSource, trackingState); } if (onTrackingChangedEvent != null) { onTrackingChangedEvent.Invoke(this, inputSource, trackingState); } }
private void OnDeviceConnectedChanged(SteamVR_Action_Skeleton0 fromAction, bool deviceConnected) { if (onConnectedChanged != null) { onConnectedChanged.Invoke(this, inputSource, deviceConnected); } if (onConnectedChangedEvent != null) { onConnectedChangedEvent.Invoke(this, inputSource, deviceConnected); } }
protected void ApplyBlenderBehaviours(SteamVR_Action_Skeleton0 skeletonAction, SteamVR_Input_Sources inputSource, SteamVR_Skeleton_PoseSnapshot0 snapshot) { // apply blending for each behaviour for (int behaviourIndex = 0; behaviourIndex < blendingBehaviours.Count; behaviourIndex++) { blendingBehaviours[behaviourIndex].Update(Time.deltaTime, inputSource); // if disabled or very low influence, skip for perf if (blendingBehaviours[behaviourIndex].enabled && blendingBehaviours[behaviourIndex].influence * blendingBehaviours[behaviourIndex].value > 0.01f) { if (blendingBehaviours[behaviourIndex].pose != 0) { // update additive animation only as needed blendPoses[blendingBehaviours[behaviourIndex].pose].UpdateAdditiveAnimation(skeletonAction, inputSource); } blendingBehaviours[behaviourIndex].ApplyBlending(snapshot, blendPoses, inputSource); } } }
/// <summary> /// Retrieve the final animated pose, to be applied to a hand skeleton /// </summary> /// <param name="forAction">The skeleton action you want to blend between</param> /// <param name="handType">If this is for the left or right hand</param> public SteamVR_Skeleton_PoseSnapshot0 GetBlendedPose(SteamVR_Action_Skeleton0 skeletonAction, SteamVR_Input_Sources handType) { UpdatePose(skeletonAction, handType); return(GetHandSnapshot(handType)); }