public override void Serialize(JsonWriter writer)
        {
            KeyFrameReduction();

            var max = Keyframes.Select(a => a.Value).Append(float.MinValue).Max();
            var min = Keyframes.Select(a => a.Value).Append(float.MaxValue).Min();

            if (Math.Abs(max - min) < float.Epsilon)
            {
                max += 1;
            }
            var range = max - min;

            writer.WriteStartObject();
            {
                writer.WritePropertyName("Name");
                writer.WriteValue(Name);

                writer.WritePropertyName("Min");
                writer.WriteValue(min);

                writer.WritePropertyName("Max");
                writer.WriteValue(max);

                writer.WritePropertyName("Type");
                writer.WriteValue(nameof(Single) + "_r16");

                writer.WritePropertyName("KeysData");
                writer.WriteValue(ToBase64(Keyframes.Select(a => (uint)a.Time.TotalMilliseconds)));

                writer.WritePropertyName("ValueData");
                writer.WriteValue(ToBase64(Keyframes.Select(a => (ushort)((a.Value - min) / range * ushort.MaxValue))));
            }
            writer.WriteEndObject();
        }
Пример #2
0
        public override void Evaluate(float time)
        {
            var kfs = Keyframes.ToList();
            var kf  = kfs.FindLast(k => k.Time.Value <= time);
            var kf1 = kfs.Find(k => k.Time.Value > time);

            if (kf == null && kf1 == null)
            {
                CurrentValue = 0;
            }
            else if (kf == null)
            {
                CurrentValue = kf1.Value.Value;
            }
            else if (kf1 == null)
            {
                CurrentValue = kf.Value.Value;
            }
            else
            {
                var curve = Curves.FirstOrDefault(c => (c.Start == kf) && (c.End == kf1));
                if (curve != null)
                {
                    CurrentValue = curve.GetValue(time);
                }
            }
        }
Пример #3
0
        public AnimationFrame GetAnimFrame(int index, bool linear)
        {
            AnimationFrame a = Keyframes.GetFullFrame(index, linear);

            a.forKeyframeCHR = true;
            return(a);
        }
Пример #4
0
        public AttributeAnimation(XmlElement elem)
        {
            name_          = elem.GetAttribute("name");
            speed_         = float.Parse(elem.GetAttribute("speed"));
            splineTension_ = float.Parse(elem.GetAttribute("splinetension"));
            string interp   = elem.GetAttribute("interpolation").ToLowerInvariant();
            string wrapmode = elem.GetAttribute("wrapmode").ToLowerInvariant();

            if (interp.Equals("linear"))
            {
                interp_ = InterpolationMethod.Linear;
            }
            else if (interp.Equals("linear"))
            {
                interp_ = InterpolationMethod.Spline;
            }
            if (wrapmode.Equals("clamp"))
            {
                wrap_ = AnimWrapMode.Clamp;
            }
            else if (wrapmode.Equals("loop"))
            {
                wrap_ = AnimWrapMode.Loop;
            }
            else if (wrapmode.Equals("once"))
            {
                wrap_ = AnimWrapMode.Once;
            }

            foreach (XmlElement keyelem in elem.GetElementsByTagName("keyframe"))
            {
                Keyframes.Add(new Keyframe(keyelem));
            }
        }
Пример #5
0
 public SerializableUniform(string uniformName, IEnumerable <KeyValuePair <float, float> > uniformKeyFrames) : this(uniformName)
 {
     foreach (var kf in uniformKeyFrames)
     {
         Keyframes.Add(new Keyframe(kf.Key, kf.Value));
     }
 }
Пример #6
0
 private Keyframe GetLastKeyframe(long tick)
 => tick > StartTick && Keyframes.Any(x => x.Tick < tick)
         ? Keyframes
 .Where(x => x.Tick < tick)
 .OrderBy(x => Math.Abs(x.Tick - tick))
 .FirstOrDefault()
         : Keyframe.GetDefault(StartTick);
 void OnEdit()
 {
     if (Keyframes != null)
     {
         Keyframes.Sort((k1, k2) => k1.Time.CompareTo(k2.Time));
     }
     OnAssetEdit.SafeInvoke();
 }
Пример #8
0
 private void RebuildKeyframeViewModels()
 {
     foreach (var key in timeline.Keys)
     {
         KeyframeViewModel keyVM = new KeyframeViewModel(key.Key);
         Keyframes.Add(keyVM);
     }
 }
Пример #9
0
        /// <summary> Removes a keyframe at a given index. </summary>
        /// <param name="keyframe"> </param>
        public void DeleteKeyframe(int keyframe)
        {
            Argument.Check(Check.Range(keyframe, Keyframes));
#if UNITY_EDITOR
            Undo.RecordObject(this, "Delete Keyframe");
#endif
            Keyframes.RemoveAt(keyframe);
            InternalOnChange();
        }
Пример #10
0
    void ExportKeyFrames(XmlElement parent, Keyframes keyframes)
    {
        XmlElement elt = AddChild(parent, "Keyframes");

        elt.SetAttribute("Count", keyframes.Count.ToString(myNumberFormat));
        foreach (Keyframe keyframe in keyframes)
        {
            ExportKeyframe(elt, keyframe);
        }
    }
Пример #11
0
        public void SetKeyframe(KeyFrameMode mode, int index, float value)
        {
            KeyframeEntry k = Keyframes.SetFrameValue(mode, index, value);

            k.GenerateTangent();
            k._prev.GenerateTangent();
            k._next.GenerateTangent();

            SignalPropertyChange();
        }
Пример #12
0
        void ChangeKeyframeText(SvgWidget widget, object newValue, object delta)
        {
            var cmds = new CompoundCommand();

            foreach (var kf in Keyframes.Where(x => x.Model.Selected.Value))
            {
                cmds.Append(Command.Set(kf.Model.Text, (string)newValue));
            }

            History.Insert(cmds);
        }
Пример #13
0
        //-----------------------------------------------------------------------
        public Animation(SkeletalAnimationItem item)
        {
            Timeline             = new AnimationTimeline();
            Timeline.DataContext = this;
            Item = item;

            InterpolatedSkeleton = RecursivelyConvert(Item.RootBone);

            PropertyChanged += (e, args) =>
            {
                item.RaisePropertyChangedEvent(args.PropertyName);
            };

            Timeline.PropertyChanged += (e, args) =>
            {
                if (args.PropertyName == "IndicatorTime")
                {
                    Prev = null;
                    Next = null;

                    if (Keyframes.Count > 0)
                    {
                        if (Timeline.IndicatorTime <= Keyframes.FirstOrDefault().Time)
                        {
                            Prev = Keyframes.FirstOrDefault();
                        }
                        else if (Timeline.IndicatorTime >= Keyframes.LastOrDefault().Time)
                        {
                            Prev = Keyframes.LastOrDefault();
                        }
                        else
                        {
                            foreach (var keyframe in Keyframes)
                            {
                                Prev = Next;
                                Next = keyframe;

                                if (keyframe.Time >= Timeline.IndicatorTime)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    foreach (var bone in InterpolatedSkeleton.Descendants)
                    {
                        bone.InvalidateTransforms();
                    }

                    RaisePropertyChangedEvent("IndicatorTime");
                }
            };
        }
Пример #14
0
        public void RemoveKeyframe(KeyFrameMode mode, int index)
        {
            KeyframeEntry k = Keyframes.Remove(mode, index);

            if (k != null)
            {
                k._prev.GenerateTangent();
                k._next.GenerateTangent();
                SignalPropertyChange();
            }
        }
Пример #15
0
        public void DeleteKeyframe(HitboxKeyframe keyframe)
        {
            if (!Keyframes.Contains(keyframe))
            {
                return;
            }
#if UNITY_EDITOR
            Undo.RecordObject(this, "Delete Keyframe");
#endif
            Keyframes.Remove(keyframe);
            InternalOnChange();
        }
Пример #16
0
        public void RemoveKeyframe(int arrayIndex, int index)
        {
            KeyframeEntry k = Keyframes.Remove(arrayIndex, index);

            if (k != null && _generateTangents &&
                _alterAdjTangents && _alterAdjTangents_KeyFrame_Del)
            {
                k._prev.GenerateTangent();
                k._next.GenerateTangent();
                SignalPropertyChange();
            }
        }
Пример #17
0
    void ImportKeyframes(XmlElement parent, Keyframes keyframes)
    {
        XmlElement elt = parent["Keyframes"];

        if (null == elt)
        {
            return;
        }
        foreach (XmlElement child in elt)
        {
            ImportKeyframe(child, keyframes);
        }
    }
Пример #18
0
        internal override void Write(ResourceWriter writer)
        {
            writer.WriteInt32(( int )KeyframeType);
            writer.WriteInt32(Keyframes.Count);
            KeyframeTimings.ForEach(writer.WriteSingle);
            Keyframes.ForEach(x => x.Write(writer));

            if (UsesScaleVectors())
            {
                writer.WriteVector3(PositionScale);
                writer.WriteVector3(ScaleScale);
            }
        }
Пример #19
0
        public KeyframeEntry SetKeyframe(KeyFrameMode mode, int index, float value, bool forceNoGenTans)
        {
            KeyframeEntry k = Keyframes.SetFrameValue(mode, index, value);

            if (_generateTangents && !forceNoGenTans)
            {
                k.GenerateTangent();
                k._prev.GenerateTangent();
                k._next.GenerateTangent();
            }

            SignalPropertyChange();
            return(k);
        }
            public virtual void ReadChildData(BinaryReader reader)
            {
                int x = 0;

                for (x = 0; (x < _keyframes.Count); x = (x + 1))
                {
                    Keyframes.Add(new ScreenAnimationKeyframeReferenceBlockBlock());
                    Keyframes[x].Read(reader);
                }
                for (x = 0; (x < _keyframes.Count); x = (x + 1))
                {
                    Keyframes[x].ReadChildData(reader);
                }
            }
Пример #21
0
        public CHRAnimationFrame GetAnimFrame(int index, bool returnOutFrame = false)
        {
            CHRAnimationFrame frame = new CHRAnimationFrame()
            {
                Index = index
            };
            float *dPtr = (float *)&frame;

            for (int x = 0; x < 9; x++)
            {
                frame.SetBool(x, Keyframes.GetKeyframe(x, index) != null);
                *dPtr++ = GetFrameValue(x, index, returnOutFrame);
            }
            return(frame);
        }
Пример #22
0
    void ImportKeyframe(XmlElement parent, Keyframes keyframes)
    {
        Timecode position = ChildTimecode(parent, "Position");
        Keyframe keyframe = null;

        if (0 == position.Nanos)
        {
            keyframe = (Keyframe)keyframes[0];
        }
        else
        {
            keyframe = new Keyframe(position);
            keyframes.Add(keyframe);
        }
        try { keyframe.Type = ChildVideoKeyframeType(parent, "Type"); } catch {}
    }
Пример #23
0
        public KeyframeEntry SetKeyframe(int arrayIndex, int index, float value, bool forceNoGenTans)
        {
            KeyframeEntry k = Keyframes.SetFrameValue(arrayIndex, index, value);

            if (_generateTangents && !forceNoGenTans)
            {
                k.GenerateTangent();

                if (_alterAdjTangents && _alterAdjTangents_KeyFrame_Set)
                {
                    k._prev.GenerateTangent();
                    k._next.GenerateTangent();
                }
            }

            SignalPropertyChange();
            return(k);
        }
        public void UpdateSpawn()
        {
            if (Spawn == null)
            {
                return;
            }
            HitboxKeyframe frame = Keyframes.FindLast(h => h.Time < SeekTime);

            for (var i = 0; i < IDs.Count; i++)
            {
                Hitbox hitbox = GetHitbox(IDs[i]);
                if (hitbox == null)
                {
                    continue;
                }
                hitbox.CurrentType = frame != null ? frame.States[i] : hitbox.DefaultType;
            }
            SceneView.RepaintAll();
        }
Пример #25
0
        public override void Nudge(ref CompoundCommand cmds, NudgeDirection direction, float timeDelta, float valueDelta)
        {
            base.Nudge(ref cmds, direction, timeDelta, valueDelta);

            foreach (var kf in Keyframes.Where(x => x.Model.Selected.Value))
            {
                switch (direction)
                {
                case NudgeDirection.Up:
                    var newValue = (float)VMath.Clamp(kf.Model.Value.Value + valueDelta, Model.Minimum.Value, Model.Maximum.Value);
                    cmds.Append(Command.Set(kf.Model.Value, newValue));
                    break;

                case NudgeDirection.Down:
                    newValue = (float)VMath.Clamp(kf.Model.Value.Value - valueDelta, Model.Minimum.Value, Model.Maximum.Value);
                    cmds.Append(Command.Set(kf.Model.Value, newValue));
                    break;
                }
            }
        }
Пример #26
0
        public KeyframeEntry SetKeyframe(KeyFrameMode mode, int index, float value)
        {
            bool          exists = Keyframes.GetKeyframe(mode, index) != null;
            KeyframeEntry k      = Keyframes.SetFrameValue(mode, index, value);

            if (!exists && !_generateTangents)
            {
                k.GenerateTangent();
            }

            if (_generateTangents)
            {
                k.GenerateTangent();
                k._prev.GenerateTangent();
                k._next.GenerateTangent();
            }

            SignalPropertyChange();
            return(k);
        }
Пример #27
0
        public KeyframeEntry SetKeyframe(int arrayIndex, int index, float value, bool forceNoGenTans = false, bool parsing = false)
        {
            KeyframeEntry k = Keyframes.SetFrameValue(arrayIndex, index, value, parsing);

            if (!forceNoGenTans)
            {
                bool exists = Keyframes.GetKeyframe(arrayIndex, index) != null;
                if (_generateTangents || !exists)
                {
                    k.GenerateTangent();
                }
                if (_generateTangents && _alterAdjTangents && _alterAdjTangents_KeyFrame_Set)
                {
                    k._prev.GenerateTangent();
                    k._next.GenerateTangent();
                }
            }

            SignalPropertyChange();
            return(k);
        }
Пример #28
0
        /// <summary> Adds a new HitboxKeyfram at the a specified time. </summary>
        /// <param name="time"> the time to add the keyframe at </param>
        /// <param name="defaultType"> the default type to use for every hitbox if no keyframes are currently present </param>
        /// <returns> the created keyframe </returns>
        /// <exception cref="ArgumentNullException"> </exception>
        public HitboxKeyframe AddKeyframe(float time = 0f, Hitbox.Type defaultType = Hitbox.Type.Inactive)
        {
            time = Mathf.Clamp01(time);
#if UNITY_EDITOR
            Undo.RecordObject(this, "Add Keyframe");
#endif
            HitboxKeyframe prevKeyframe = PrevKeyframe(time);
            var            keyframe     = new HitboxKeyframe {
                Time = time,
            };
            if (prevKeyframe != null)
            {
                keyframe.States = new List <Hitbox.Type>(prevKeyframe.States);
            }
            else
            {
                keyframe.States = Enumerable.Repeat(defaultType, IDs.Count).ToList();
            }
            Keyframes.Add(keyframe);
            InternalOnChange();
            return(keyframe);
        }
 void TimeGUI()
 {
     using (EditorGUILayout.VerticalScope scope = hGUI.Vertical()) {
         SeekAreaGUI();
         using (EditorGUILayout.VerticalScope displayScope = hGUI.Vertical()) {
             DragListener.EventCheck(displayScope.rect);
             string error = null;
             if (IDs == null)
             {
                 error = "No selected event. Select an event.";
             }
             else if (IDs.Count <= 0)
             {
                 error = "No Hitboxes on {0}. Drag Character hitboxes here.".With(State.name);
             }
             if (!error.IsNullOrEmpty())
             {
                 hGUI.Space();
                 EditorGUILayout.LabelField(error, GUI.skin.label.WithAlignment(TextAnchor.MiddleCenter));
             }
             else
             {
                 for (var i = 0; i < IDs.Count; i++)
                 {
                     DrawHitboxGUI(i);
                 }
             }
             hGUI.Space();
         }
         Rect areaRect = scope.rect;
         DrawVerticalLine(SeekTime, SeekLineColor, areaRect);
         areaRect.height -= elementHeight;
         areaRect.y      += elementHeight;
         foreach (HitboxKeyframe keyframe in Keyframes.IgnoreNulls())
         {
             DrawVerticalLine(keyframe.Time, KeyframeLineColor, areaRect);
         }
     }
 }
        /// <summary>
        /// Initializes the light pattern from the keyframes in the animation file
        /// </summary>
        /// <param name="k"></param>
        void FromVectorAnim(Keyframes k)
        {
            // Allocate lists to hold the LEDs
            var  FrontSeq  = new List <LightFrame>();
            var  MiddleSeq = new List <LightFrame>();
            var  BackSeq   = new List <LightFrame>();
            uint lastTime  = 0;

            // Convert each of the animation files backpack lights into a
            // single internal format
            for (var I = 0; I < k.BackpackLightsKeyFrameLength; I++)
            {
                var l = k.BackpackLightsKeyFrame(I);
                if (null == l)
                {
                    continue;
                }

                // Convert the struct to frames for each of the LEDs
                lastTime = From((Anki.VectorAnim.BackpackLights)l, out var front, out var middle, out var back);

                // Append these to the list
                FrontSeq.Add(front);
                MiddleSeq.Add(middle);
                BackSeq.Add(back);
            }

            if (FrontSeq.Count == 0 && MiddleSeq.Count == 0 && BackSeq.Count == 0)
            {
                return;
            }

            // Now put that into something to hold all of them
            lightKeyFrames = new IReadOnlyList <LightFrame>[3] {
                FrontSeq, MiddleSeq, BackSeq
            };
            duration_ms = lastTime - FrontSeq[0].triggerTime_ms;
        }