/// <summary> /// Collects the position of the HMD with a timestamp, to be looked up later to correct for latency. /// </summary> public void CollectPose() { if (manager == null) { return; } KeyPose k = new KeyPose(); #if UNITY_2019_1_OR_NEWER InputTracking.GetNodeStates(nodeStates); XRNodeState nodeState = nodeStates.Find(node => node.nodeType == XRNode.Head); nodeState.TryGetRotation(out k.Orientation); nodeState.TryGetPosition(out k.Translation); #else k.Orientation = InputTracking.GetLocalRotation(XRNode.Head); k.Translation = InputTracking.GetLocalPosition(XRNode.Head); #endif if (manager.zedCamera.IsCameraReady) { k.Timestamp = manager.zedCamera.GetCurrentTimeStamp(); if (k.Timestamp >= 0) { dllz_latency_corrector_add_key_pose(ref k.Translation, ref k.Orientation, k.Timestamp); //Poses are handled by the wrapper. } } }
public static KeyPose lerp(KeyPose start, KeyPose end, float amount) { KeyPose result = new KeyPose(start.boneOffsets.Length); for (int i = 0; i < start.boneOffsets.Length; i++) { result.boneOffsets[i] = new BoneOffset(Vector3.Lerp(start.boneOffsets[i].localPosition, end.boneOffsets[i].localPosition, amount), Quaternion.Lerp(start.boneOffsets[i].localRotation, end.boneOffsets[i].localRotation, amount)); } return(result); }
/// <summary> /// Collect positions used in the latency corrector /// </summary> public void CollectPose() { KeyPose k = new KeyPose(); k.Orientation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.Head); k.Translation = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.Head); if (sl.ZEDCamera.GetInstance().IsCameraReady) { k.Timestamp = sl.ZEDCamera.GetInstance().GetCurrentTimeStamp(); if (k.Timestamp >= 0) { dllz_latency_corrector_add_key_pose(ref k.Translation, ref k.Orientation, k.Timestamp); } } }
/// <summary> /// Collects the position of the HMD with a timestamp, to be looked up later to correct for latency. /// </summary> public void CollectPose() { if (manager == null) { return; } KeyPose k = new KeyPose(); k.Orientation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.Head); k.Translation = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.Head); if (manager.zedCamera.IsCameraReady) { k.Timestamp = manager.zedCamera.GetCurrentTimeStamp(); if (k.Timestamp >= 0) { dllz_latency_corrector_add_key_pose(ref k.Translation, ref k.Orientation, k.Timestamp); //Poses are handled by the wrapper. } } }
void Start() { Regex removeCharsFromFilename = new Regex("[^a-zA-Z0-9 -]"); path = Application.dataPath + "/Poses/" + removeCharsFromFilename.Replace(poseClip.name, "") + ".json"; path_f = Application.dataPath + "/Poses/" + removeCharsFromFilename.Replace(poseClip.name, "") + "_f.json"; boneTransforms = gameObject.GetComponentsInChildren <Transform>(); // boneTransforms_f = (Transform[]) boneTransforms.Clone(); parent = gameObject.GetComponentInParent <Animation>(); parent.clip = poseClip; poseClip.SampleAnimation(parent.gameObject, 1f); pose = new KeyPose(boneTransforms, false); pose_f = new KeyPose(boneTransforms, true); storeBoneTransforms(); }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player"); player_controller = player.GetComponent <controller>(); boneTransforms = gameObject.GetComponentsInChildren <Transform>(); string path = Application.dataPath + "/Poses/"; testPose4_w = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmatureWalkPass.json")); testPose3_w = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmatureWalkReach.json")); testPose2_w = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmatureWalkPass_f.json")); testPose_w = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmatureWalkReach_f.json")); testPose4 = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmaturePass.json")); testPose3 = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmatureReach.json")); testPose2 = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmaturePass_f.json")); testPose = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmatureReach_f.json")); stand = JsonUtility.FromJson <KeyPose>(File.ReadAllText(path + "ArmatureStand.json")); current = testPose4; goingTo = testPose; current_w = testPose4_w; goingTo_w = testPose_w; // left = new Transform[10]; // right = new Transform[10]; // foreach(Transform boneTransform in boneTransforms){ // if(boneTransform.gameObject.name.Contains(".L")){ // left[left_count] = boneTransform; // left_count++; // } // if(boneTransform.gameObject.name.Contains(".R")){ // right[right_count] = boneTransform; // right_count++; // } // } }
void LateUpdate() { distTravelled += player_controller.lerped.magnitude; // Debug.Log(distTravelled); if (distTravelled >= .25f) { pose++; if (pose == 5) { pose = 1; } distTravelled = 0; switch (pose) { case 1: //liner endslow = true; current = testPose4; goingTo = testPose; current_w = testPose4_w; goingTo_w = testPose_w; break; case 2: //lin endslow = false; current = testPose; goingTo = testPose2; current_w = testPose_w; goingTo_w = testPose2_w; break; case 3: //end slow endslow = true; current = testPose2; goingTo = testPose3; current_w = testPose2_w; goingTo_w = testPose3_w; break; case 4: //start slow endslow = false; current = testPose3; goingTo = testPose4; current_w = testPose3_w; goingTo_w = testPose4_w; break; } //Debug.Log(pose + " " + endslow); } if (endslow) { lerpedPose_run = KeyPose.lerp(current, goingTo, singleBicubic.Evaluate(distTravelled / .25f)); lerpedPose_w = KeyPose.lerp(current_w, goingTo_w, singleBicubic.Evaluate(distTravelled / .25f)); } else { lerpedPose_run = KeyPose.lerp(current, goingTo, bicubic.Evaluate(distTravelled / .25f)); lerpedPose_w = KeyPose.lerp(current_w, goingTo_w, bicubic.Evaluate(distTravelled / .25f)); } standLerp = KeyPose.lerp(stand, lerpedPose_w, bicubic.Evaluate((player_controller.lerped.magnitude / Time.deltaTime) / 1f)); finalLerped = KeyPose.lerp(standLerp, lerpedPose_run, bicubic.Evaluate((player_controller.lerped.magnitude / Time.deltaTime) / 2.2f)); //Debug.Log(player_controller.lerped.magnitude/Time.deltaTime); for (int i = 0; i < boneTransforms.Length; i++) { boneTransforms[i].localPosition = finalLerped.boneOffsets[i].localPosition; boneTransforms[i].localRotation = finalLerped.boneOffsets[i].localRotation; } }