public void RestoreFrom(ICurveAnimationTarget backup)
        {
            var target = backup as FreeControllerAnimationTarget;

            if (target == null)
            {
                return;
            }
            var maxTime = x.GetLastFrame().time;

            x.keys.Clear();
            x.keys.AddRange(target.x.keys.Where(k => k.time < maxTime + 0.0001f));
            y.keys.Clear();
            y.keys.AddRange(target.y.keys.Where(k => k.time < maxTime + 0.0001f));
            z.keys.Clear();
            z.keys.AddRange(target.z.keys.Where(k => k.time < maxTime + 0.0001f));
            rotX.keys.Clear();
            rotX.keys.AddRange(target.rotX.keys.Where(k => k.time < maxTime + 0.0001f));
            rotY.keys.Clear();
            rotY.keys.AddRange(target.rotY.keys.Where(k => k.time < maxTime + 0.0001f));
            rotZ.keys.Clear();
            rotZ.keys.AddRange(target.rotZ.keys.Where(k => k.time < maxTime + 0.0001f));
            rotW.keys.Clear();
            rotW.keys.AddRange(target.rotW.keys.Where(k => k.time < maxTime + 0.0001f));
            AddEdgeFramesIfMissing(maxTime);
            dirty = true;
        }
Esempio n. 2
0
        private void BindCurves(ICurveAnimationTarget target)
        {
            var lead = target.GetLeadCurve();

            _animationLength = lead.keys[lead.keys.Length - 1].time;
            _targets.Add(target);
            target.onAnimationKeyframesRebuilt.AddListener(OnAnimationKeyframesRebuilt);
            if (target is FreeControllerAnimationTarget)
            {
                var t = (FreeControllerAnimationTarget)target;
                if (_lines.Count > _maxCurves - 3)
                {
                    return;
                }
                BindCurve(t.x, _style.CurveLineColorX, $"{target.GetShortName()} x");
                BindCurve(t.y, _style.CurveLineColorY, $"{target.GetShortName()} y");
                BindCurve(t.z, _style.CurveLineColorZ, $"{target.GetShortName()} z");
                // To display rotation as euleur angles, we have to build custom curves. But it's not that useful.
                // var rotVX = new Keyframe[t.rotX.length];
                // var rotVY = new Keyframe[t.rotY.length];
                // var rotVZ = new Keyframe[t.rotZ.length];
                // for (var time = 0; time < t.rotW.length; time++)
                // {
                //     Keyframe keyX = t.rotX[time];
                //     Keyframe keyY = t.rotY[time];
                //     Keyframe keyZ = t.rotZ[time];
                //     Keyframe keyW = t.rotW[time];
                //     var rot = new Quaternion(
                //         keyX.value,
                //         keyY.value,
                //         keyZ.value,
                //         keyW.value
                //     );
                //     var eulerAngles = rot.eulerAngles;
                //     rotVX[time] = new Keyframe(keyW.time, eulerAngles.x);
                //     rotVY[time] = new Keyframe(keyW.time, eulerAngles.y);
                //     rotVZ[time] = new Keyframe(keyW.time, eulerAngles.z);
                // }
                // AnimationCurve rotVXCurve = new AnimationCurve(rotVX);
                // AnimationCurve rotVYCurve = new AnimationCurve(rotVY);
                // AnimationCurve rotVZCurve = new AnimationCurve(rotVZ);
                // BindCurve(rotVXCurve, new Color(1.0f, 0.8f, 0.8f), $"{target.GetShortName()} rot x");
                // BindCurve(rotVYCurve, new Color(0.8f, 1.0f, 0.8f), $"{target.GetShortName()} rot y");
                // BindCurve(rotVZCurve, new Color(0.8f, 0.8f, 1.0f), $"{target.GetShortName()} rot z");
            }
            else if (target is FloatParamAnimationTarget)
            {
                if (_lines.Count > _maxCurves - 1)
                {
                    return;
                }
                var t = (FloatParamAnimationTarget)target;
                BindCurve(t.value, _style.CurveLineColorFloat, target.GetShortName());
            }
            else
            {
                return;
            }
        }
        private static void AddMissingKeyframeSettings(ICurveAnimationTarget target)
        {
            AnimationCurve leadCurve = target.GetLeadCurve();

            for (var key = 0; key < leadCurve.length; key++)
            {
                var time = leadCurve[key].time;
                target.EnsureKeyframeSettings(time, CurveTypeValues.LeaveAsIs);
            }
        }
Esempio n. 4
0
        private static void RebuildClipLoop(AtomAnimationClip clip, ICurveAnimationTarget target)
        {
            KeyframeSettings settings;

            if (clip.loop && target.settings.TryGetValue(0, out settings) && settings.curveType == CurveTypeValues.Smooth)
            {
                foreach (var curve in target.GetCurves())
                {
                    curve.SmoothLoop();
                }
            }
        }
Esempio n. 5
0
        public void RestoreFrom(ICurveAnimationTarget backup)
        {
            var target = backup as FloatParamAnimationTarget;

            if (target == null)
            {
                return;
            }
            var maxTime = value.GetLastFrame().time;

            value.keys.Clear();
            value.keys.AddRange(target.value.keys.Where(k => k.time < maxTime + 0.0001f));
            value.AddEdgeFramesIfMissing(maxTime, CurveTypeValues.SmoothLocal);
            dirty = true;
        }
Esempio n. 6
0
        private void BindCurves(ICurveAnimationTarget target)
        {
            var lead = target.GetLeadCurve();

            _animationLength = lead.length >= 2 ? lead.GetKeyframeByKey(lead.length - 1).time : 0f;
            _targets.Add(target);
            target.onAnimationKeyframesRebuilt.AddListener(OnAnimationKeyframesRebuilt);
            if (target is FreeControllerAnimationTarget)
            {
                var t = (FreeControllerAnimationTarget)target;
                if (_lines.Count > _maxCurves - 3)
                {
                    return;
                }
                BindCurve(t.x, _style.CurveLineColorX, $"{target.GetShortName()} x");
                BindCurve(t.y, _style.CurveLineColorY, $"{target.GetShortName()} y");
                BindCurve(t.z, _style.CurveLineColorZ, $"{target.GetShortName()} z");
                // To display rotation as euleur angles, we have to build custom curves. But it's not that useful.

                /*
                 * var rotVX = new BezierKeyframe[t.rotX.length];
                 * var rotVY = new BezierKeyframe[t.rotY.length];
                 * var rotVZ = new BezierKeyframe[t.rotZ.length];
                 * for (var time = 0; time < t.rotW.length; time++)
                 * {
                 *  var keyX = t.rotX.keys[time];
                 *  var keyY = t.rotY.keys[time];
                 *  var keyZ = t.rotZ.keys[time];
                 *  var keyW = t.rotW.keys[time];
                 *  var rot = new Quaternion(
                 *      keyX.value,
                 *      keyY.value,
                 *      keyZ.value,
                 *      keyW.value
                 *  );
                 *  var eulerAngles = rot.eulerAngles;
                 *  rotVX[time] = new BezierKeyframe(keyW.time, eulerAngles.x, keyW.curveType);
                 *  rotVY[time] = new BezierKeyframe(keyW.time, eulerAngles.y, keyW.curveType);
                 *  rotVZ[time] = new BezierKeyframe(keyW.time, eulerAngles.z, keyW.curveType);
                 * }
                 * var rotVXCurve = new BezierAnimationCurve(rotVX);
                 * var rotVYCurve = new BezierAnimationCurve(rotVY);
                 * var rotVZCurve = new BezierAnimationCurve(rotVZ);
                 * BindCurve(rotVXCurve, new Color(1.0f, 0.8f, 0.8f), $"{target.GetShortName()} rot x");
                 * BindCurve(rotVYCurve, new Color(0.8f, 1.0f, 0.8f), $"{target.GetShortName()} rot y");
                 * BindCurve(rotVZCurve, new Color(0.8f, 0.8f, 1.0f), $"{target.GetShortName()} rot z");
                 */
            }
            else if (target is FloatParamAnimationTarget)
            {
                if (_lines.Count > _maxCurves - 1)
                {
                    return;
                }
                var t = (FloatParamAnimationTarget)target;
                BindCurve(t.value, _style.CurveLineColorFloat, target.GetShortName());
            }
            else
            {
            }
        }