// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { if (isRecording) { StopRecording(); Debug.Log("stopped recording: " + myName); } else { StartRecording(); Debug.Log("starting a recording with: " + myName); } } if (isRecording) { TimedPose t = new TimedPose(); t.elapsedTime = timeSinceStart; t.headPosition = head.localPosition; t.headRotation = head.localRotation; t.leftHandPosition = leftHand.localPosition; t.leftHandRotation = leftHand.localRotation; t.rightHandPosition = rightHand.localPosition; t.rightHandRotation = rightHand.localRotation; posesCollected.Add(t); timeSinceStart += Time.deltaTime; } }
/*AUTO SCRIPT*/ /*AUTO SCRIPT*/ /*AUTO SCRIPT*/ /*AUTO SCRIPT*/ public void Invoke(TimedPose val) /*AUTO SCRIPT*/ { /*AUTO SCRIPT*/ if (debug) { /*AUTO SCRIPT*/ Debug.Log($"{name} event invoked: {val}"); } /*AUTO SCRIPT*/ ahoyEvent.Invoke(val); /*AUTO SCRIPT*/ //important to do this incase a listener removes its self from the list /*AUTO SCRIPT*/ unityEventListeners.ToArray().ForEach(l => l.Invoke(val)); /*AUTO SCRIPT*/ assetEventListeners.ToArray().ForEach(l => l.Invoke(val)); /*AUTO SCRIPT*/ }
string ConvertToString(TimedPose pose) { string line = pose.elapsedTime + ", " + pose.headPosition.x + ", " + pose.headPosition.y + ", " + pose.headPosition.z + ", " + pose.headRotation.x + ", " + pose.headRotation.y + ", " + pose.headRotation.z + ", " + pose.headRotation.w + ", " + pose.leftHandPosition.x + ", " + pose.leftHandPosition.y + ", " + pose.leftHandPosition.z + ", " + pose.leftHandRotation.x + ", " + pose.leftHandRotation.y + ", " + pose.leftHandRotation.z + ", " + pose.leftHandRotation.w + ", " + pose.rightHandPosition.x + ", " + pose.rightHandPosition.y + ", " + pose.rightHandPosition.z + ", " + pose.rightHandRotation.x + ", " + pose.rightHandRotation.y + ", " + pose.rightHandRotation.z + ", " + pose.rightHandRotation.w + ";"; return(line); }
// Start is called before the first frame update public void ChangeName(string nm) { filename = nm; nameText.text = filename; records = GameObject.Find("Player").GetComponent <RecordPlayerMovement>(); Debug.Log("player found: " + records.name); //try to load a file //Re-import the file to update the reference in the editor StreamReader reader = new StreamReader("Assets/Resources/" + filename + ".txt"); string asset = reader.ReadToEnd(); //Read the text from directly from the test.txt file //if no file, use the player memory to playback poses if (asset != null && !string.IsNullOrEmpty(asset)) { poses = new List <TimedPose>(); string[] lines = asset.Split(';'); foreach (string line in lines) { try { string[] vals = line.Split(','); TimedPose t = new TimedPose(); t.elapsedTime = float.Parse(vals[0]); t.headPosition = new Vector3(float.Parse(vals[1]), float.Parse(vals[2]), float.Parse(vals[3])); t.headRotation = new Quaternion(float.Parse(vals[4]), float.Parse(vals[5]), float.Parse(vals[6]), float.Parse(vals[7])); t.leftHandPosition = new Vector3(float.Parse(vals[8]), float.Parse(vals[9]), float.Parse(vals[10])); t.leftHandRotation = new Quaternion(float.Parse(vals[11]), float.Parse(vals[12]), float.Parse(vals[13]), float.Parse(vals[14])); t.rightHandPosition = new Vector3(float.Parse(vals[15]), float.Parse(vals[16]), float.Parse(vals[17])); t.rightHandRotation = new Quaternion(float.Parse(vals[18]), float.Parse(vals[19]), float.Parse(vals[20]), float.Parse(vals[21])); poses.Add(t); } catch (System.FormatException e) { Debug.Log("incorrect line format detected."); } } } else { poses = records.Poses; } }
void OnArucoPose(MarkerPose pose) { if (pose.Id == MarkerId) { // pose is marker's pose -> inverted we get camera pose var markerMatrix = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one); var cameraMatrix = markerMatrix.inverse; var cameraLocalPos = cameraMatrix.GetPosition(); var cameraWorldPos = transform.TransformPoint(cameraLocalPos); var camPose = new TimedPose { DetectionTime = DateTime.Now, CameraPose = cameraWorldPos }; _savedPoses.Add(camPose); } }
void OnArucoPose(MarkerPose pose) { if (pose.Id == MarkerId) { // pose is marker's pose -> inverted we get camera pose var markerMatrix = Matrix4x4.TRS(pose.Position, pose.Rotation, Vector3.one); var cameraMatrix = markerMatrix.inverse; var cameraLocalPos = cameraMatrix.GetPosition(); var cameraWorldPos = transform.TransformPoint(cameraLocalPos); var camPose = new TimedPose { DetectionTime = DateTime.Now, CameraPose = cameraWorldPos }; _savedPoses.Add(camPose); } }
// Update is called once per frame void Update() { nameText.transform.LookAt(Camera.main.transform.position); if (isPlayback) { if (poses != null && timeSinceStart > poses[playbackIndex].elapsedTime) { playbackIndex += 1; } if (poses != null) { if (playbackIndex < poses.Count) { TimedPose t = poses[playbackIndex]; head.localPosition = t.headPosition; head.localRotation = t.headRotation; leftHand.localPosition = t.leftHandPosition; leftHand.localRotation = t.leftHandRotation; rightHand.localPosition = t.rightHandPosition; rightHand.localRotation = t.rightHandRotation; timeSinceStart += Time.deltaTime * timeScale; } else { OnPlaybackEnded(new EventArgs()); StopPlayback(); } } else { StopPlayback(); } } }
/*AUTO SCRIPT*/ public void Log(TimedPose val) { /*AUTO SCRIPT*/ Debug.Log($"{prefix}: {val}"); /*AUTO SCRIPT*/ }
/*AUTO SCRIPT*/ /*AUTO SCRIPT*/ public void Push(TimedPose val) /*AUTO SCRIPT*/ { /*AUTO SCRIPT*/ array.Push(val); /*AUTO SCRIPT*/ Invoke(); /*AUTO SCRIPT*/ }