Exemplo n.º 1
0
 public Vector3 GetKeyframePosition(int key)
 {
     return(new Vector3(
                x.GetKeyframeByKey(key).value,
                y.GetKeyframeByKey(key).value,
                z.GetKeyframeByKey(key).value
                ));
 }
Exemplo n.º 2
0
 public Quaternion GetRotationAtKeyframe(int key)
 {
     return(new Quaternion(
                rotX.GetKeyframeByKey(key).value,
                rotY.GetKeyframeByKey(key).value,
                rotZ.GetKeyframeByKey(key).value,
                rotW.GetKeyframeByKey(key).value
                ));
 }
Exemplo n.º 3
0
        public int SetKeyframeByKey(int key, Vector3 localPosition, Quaternion locationRotation)
        {
            var curveType = x.GetKeyframeByKey(key).curveType;

            x.SetKeyframeByKey(key, localPosition.x, curveType);
            y.SetKeyframeByKey(key, localPosition.y, curveType);
            z.SetKeyframeByKey(key, localPosition.z, curveType);
            rotX.SetKeyframeByKey(key, locationRotation.x, curveType);
            rotY.SetKeyframeByKey(key, locationRotation.y, curveType);
            rotZ.SetKeyframeByKey(key, locationRotation.z, curveType);
            rotW.SetKeyframeByKey(key, locationRotation.w, curveType);
            dirty = true;
            return(key);
        }
Exemplo n.º 4
0
        private static void SetValue(BezierAnimationCurve curve, int key, float value)
        {
            var keyframe = curve.GetKeyframeByKey(key);

            keyframe.value = value;
            curve.SetKeyframeByKey(key, keyframe);
        }
Exemplo n.º 5
0
        public IEnumerable AddAndRemoveFrames(TestContext context)
        {
            var curve = new BezierAnimationCurve();

            {
                var key = curve.SetKeyframe(0, 123, CurveTypeValues.Linear);
                if (!context.Assert(key, 0, "First key is zero"))
                {
                    yield break;
                }
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f }, "Expected one frame"))
                {
                    yield break;
                }
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0)).value, 123, "Set and get at time 0");
            }

            {
                var key = curve.SetKeyframe(0.499999f, 456, CurveTypeValues.Linear);
                if (!context.Assert(key, 1, "Second key is one"))
                {
                    yield break;
                }
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f, 0.5f }, "Expected two frames"))
                {
                    yield break;
                }
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.000001f)).value, 123, "Set and get at time 0.000001");
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.499999f)).value, 456, "Set and get at time 0.499999");
            }

            {
                var key = curve.SetKeyframe(0.250f, 789, CurveTypeValues.Linear);
                if (!context.Assert(key, 1, "Third key is one"))
                {
                    yield break;
                }
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f, 0.250f, 0.5f }, "Expected three frames"))
                {
                    yield break;
                }
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.000001f)).value, 123, "Set and get at time 0.000001");
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.250f)).value, 789, "Set and get at time 0.250f");
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.499999f)).value, 456, "Set and get at time 0.499999");
            }

            {
                curve.RemoveKey(1);
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f, 0.5f }, "Expected two frames after remove"))
                {
                    yield break;
                }
            }

            yield break;
        }
        private static JSONNode SerializeCurve(BezierAnimationCurve curve)
        {
            var curveJSON = new JSONArray();

            for (var key = 0; key < curve.length; key++)
            {
                var keyframe   = curve.GetKeyframeByKey(key);
                var curveEntry = new JSONClass
                {
                    ["t"] = keyframe.time.ToString(CultureInfo.InvariantCulture),
                    ["v"] = keyframe.value.ToString(CultureInfo.InvariantCulture),
                    ["c"] = keyframe.curveType.ToString(CultureInfo.InvariantCulture),
                    ["i"] = keyframe.controlPointIn.ToString(CultureInfo.InvariantCulture),
                    ["o"] = keyframe.controlPointOut.ToString(CultureInfo.InvariantCulture)
                };
                curveJSON.Add(curveEntry);
            }

            return(curveJSON);
        }
Exemplo n.º 7
0
        // const float kDefaultWeight = 1.0f / 3.0f;
        // const float kCurveTimeEpsilon = 0.00001f;

        private static Quaternion GetValue(BezierAnimationCurve x, BezierAnimationCurve y, BezierAnimationCurve z, BezierAnimationCurve w, int key)
        {
            return(new Quaternion(x.GetKeyframeByKey(key).value, y.GetKeyframeByKey(key).value, z.GetKeyframeByKey(key).value, w.GetKeyframeByKey(key).value));
        }