private KeyframeTimeline CreateTimeline(Entity entity) { var properties = entity.Components .Where(keyframeInfoCache.ContainsKey) .SelectMany(x => keyframeInfoCache[x]) .ToArray(); KeyframeTimeline timeline = new KeyframeTimeline(properties); timelines.Add(entity, timeline); return(timeline); }
/// <summary> /// Sets the current timeline instance and binds/unbinds events to it /// </summary> /// <param name="newTimeline"></param> private void SetTimeLine(KeyframeTimeline newTimeline) { if (timeline != null) { timeline.KeyframeAdded -= Timeline_KeyframeAdded; } if (!newTimeline.IsEmpty) { RebuildKeyframeViewModels(); } newTimeline.KeyframeAdded += Timeline_KeyframeAdded; timeline = newTimeline; }
/// <summary> /// Message callback for the currently selected entity, (For example if scoping is /// enabled we need to filter out keyframes local to only this entity) /// </summary> /// <param name="message"></param> private void ActiveEntityChanged(SelectedEntityChanged message) { if (message.Content != null) { activeEntity = message.Content.EntitySource; Aegir.Util.DebugUtil.LogWithLocation($"SelectedEntityChanged Received, ActiveEntity Changed to {activeEntity?.Name}"); AddKeyframeCommand.RaiseCanExecuteChanged(); //Get the current Timeline for this entity KeyframeTimeline timeline = Engine.GetTimeline(activeEntity); SetTimeLine(timeline); //ResetTimeline(TimelineStart,TimelineEnd); } }
private void SeekValueKeyframe(KeyframeTimeline timeline, KeyframePropertyInfo property, int time) { //Get closest keys KeySet interval = timeline.GetClosestKeys(property, time); //int t = 5; Type valueType = property.Property.PropertyType; //If both keys are the same, no need for interpolation if (interval.TimeBefore == interval.TimeAfter) { ValueKeyframe value = timeline.GetPropertyKey(property, interval.TimeBefore) as ValueKeyframe; if (value == null) { //Property had no keyframes or was not a value keyframe there is nothing to do, just return return; } property.Property.SetValue(value.Target, value.Value); } else { if (interpolatorCache.ContainsKey(valueType)) { ValueKeyframe from = timeline.GetPropertyKey(property, interval.TimeBefore) as ValueKeyframe; ValueKeyframe to = timeline.GetPropertyKey(property, interval.TimeAfter) as ValueKeyframe; double diff = interval.TimeAfter - interval.TimeBefore; double diffFromLowest = time - interval.TimeBefore; if (diff == 0) { DebugUtil.LogWithLocation($"Difference between keyframes was 0, cannot continue"); return; } double t = diffFromLowest / diff; object interpolatedValue = interpolatorCache[valueType].InterpolateBetween(from.Value, to.Value, t); property.Property.SetValue(from.Target, interpolatedValue); } else { DebugUtil.LogWithLocation($"Interpolator cache did not contain a implementation for type {valueType}"); } } }
public static void Send(KeyframeTimeline timeline, KeyframeEngine engine) { Messenger.Default.Send <ActiveTimelineChanged>(new ActiveTimelineChanged(timeline, engine)); }
private ActiveTimelineChanged(KeyframeTimeline timeline, KeyframeEngine engine) { this.Timeline = timeline; Engine = engine; }