Tanoda
Vector3Curves.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 System.Collections;
10using System.Collections.Generic;
11using UnityEngine;
12
13namespace Leap.Unity.Recording {
14
16 [System.Serializable]
17 public struct Vector3Curves {
18
19 [SerializeField]
20 private AnimationCurve _xCurve;
21 public AnimationCurve xCurve {
22 get { if (_xCurve == null) { _xCurve = new AnimationCurve(); } return _xCurve; }
23 set { _xCurve = value; }
24 }
25
26 [SerializeField]
27 private AnimationCurve _yCurve;
28 public AnimationCurve yCurve {
29 get { if (_yCurve == null) { _yCurve = new AnimationCurve(); } return _yCurve; }
30 set { _yCurve = value; }
31 }
32
33 [SerializeField]
34 private AnimationCurve _zCurve;
35 public AnimationCurve zCurve {
36 get { if (_zCurve == null) { _zCurve = new AnimationCurve(); } return _zCurve; }
37 set { _zCurve = value; }
38 }
39
40 public void AddKeyframes(float time, Vector3 value) {
41 xCurve.AddKey(time, value.x);
42 yCurve.AddKey(time, value.y);
43 zCurve.AddKey(time, value.z);
44 }
45
46 public Vector3 Evaluate(float time) {
47 return new Vector3(xCurve.Evaluate(time),
48 yCurve.Evaluate(time),
49 zCurve.Evaluate(time));
50 }
51
52#if UNITY_EDITOR
56 public void Compress(float maxDistanceError = 0.005f) {
57 AnimationCurve outXCurve, outYCurve, outZCurve;
58 AnimationCurveUtil.CompressPositions(xCurve, yCurve, zCurve,
59 out outXCurve, out outYCurve, out outZCurve,
60 maxDistanceError: maxDistanceError);
61 xCurve = outXCurve;
62 yCurve = outYCurve;
63 zCurve = outZCurve;
64 }
65#endif
66 }
67
68}
AnimationCurve data for an animated Vector3.
void AddKeyframes(float time, Vector3 value)