Tanoda
Recording.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using System.Collections.Generic;
11
12namespace Leap.Unity.Playback {
13
14 public class Recording : ScriptableObject {
15 public List<Frame> frames = new List<Frame>();
16 public List<float> frameTimes = new List<float>();
17
18 public virtual void TrimStartOfEmptyFrames(int framesToRemain) {
19 int firstFrameWithHand = -1;
20
21 for (int i = 0; i < frames.Count; i++) {
22 if (frames[i].Hands.Count != 0) {
23 firstFrameWithHand = i;
24 break;
25 }
26 }
27
28 int trimStart;
29 if (firstFrameWithHand == -1) {
30 trimStart = framesToRemain;
31 } else {
32 trimStart = Mathf.Max(0, firstFrameWithHand - framesToRemain);
33 }
34
35 TrimStart(trimStart);
36 }
37
38 public virtual void TrimEndOfEmptyFrames(int framesToRemain) {
39 int lastFrameWithHand = -1;
40
41 for (int i = frames.Count - 1; i >= 0; i--) {
42 if (frames[i].Hands.Count != 0) {
43 lastFrameWithHand = i;
44 break;
45 }
46 }
47
48 int trimEnd;
49 if (lastFrameWithHand == -1) {
50 trimEnd = framesToRemain;
51 } else {
52 trimEnd = Mathf.Max(0, (frames.Count - 1 - lastFrameWithHand) - framesToRemain);
53 }
54
55 TrimEnd(trimEnd);
56 }
57
58 public virtual void TrimStart(int trimCount) {
59 for (int i = 0; i < trimCount; i++) {
60 frames.RemoveAt(0);
61 frameTimes.RemoveAt(0);
62 }
63
64 float startTime = frameTimes[0];
65 for (int i = 0; i < frameTimes.Count; i++) {
66 frameTimes[i] -= startTime;
67 }
68 }
69
70 public virtual void TrimEnd(int trimCount) {
71 for (int i = 0; i < trimCount; i++) {
72 frames.RemoveAt(frames.Count - 1);
73 frameTimes.RemoveAt(frames.Count - 1);
74 }
75 }
76 }
77}
virtual void TrimEndOfEmptyFrames(int framesToRemain)
Definition: Recording.cs:38
virtual void TrimStart(int trimCount)
Definition: Recording.cs:58
virtual void TrimEnd(int trimCount)
Definition: Recording.cs:70
virtual void TrimStartOfEmptyFrames(int framesToRemain)
Definition: Recording.cs:18