Example #1
0
 //Timeline collection method
 /// <summary>
 /// Gets the keyframe for the given property at the given time
 /// </summary>
 /// <param name="time">time to fetch</param>
 /// <param name="property">property to fetch</param>
 /// <returns></returns>
 public KeyframePropertyData GetAtTime(int time, KeyframePropertyInfo property)
 {
     if (!propertiesMappedKeyframes.ContainsKey(property))
     {
         return(null);
     }
     if (!propertiesMappedKeyframes[property].ContainsKey(time))
     {
         return(null);
     }
     return(propertiesMappedKeyframes[property][time]);
 }
Example #2
0
        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}");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Retrieves the closest keys for the given time and property
        /// </summary>
        /// <param name="property"></param>
        /// <param name="time"></param>
        /// <returns>A tuple cotaining before as item1 and after as item2</returns>
        public Tuple <int, int> GetClosestKeys(KeyframePropertyInfo property, int time)
        {
            IList <int> keyframeTimeKeys = propertiesMappedKeyframes[property].Keys;

            if (propertiesMappedKeyframes.Count < 1)
            {
                return(new Tuple <int, int>(0, 0));
            }
            int firstKey = 0, lastKey = 0;
            //Find closest lower bound index
            int index = BinarySearch(keyframeTimeKeys, time);

            //Get the keys for our retrieved indices
            if (index != 0)
            {
                //We have at least one item before us
                firstKey = keyframeTimeKeys[index - 1];
                //Check if our first key is also the last, in this case lastkey
                //will be the same as first key.. If we are not at the end we
                //assign lastkey to one the content of one index higher
                if (index < keyframeTimeKeys.Count)
                {
                    lastKey = keyframeTimeKeys[index];
                }
                else
                {
                    lastKey = firstKey;
                }
            }
            else
            {
                //if index is 0 this means there are no keyframes before our
                //given time. We know there is at least one entry therefore we can
                //assume that the first entry in our list of keyframes is the closest one
                firstKey = keyframeTimeKeys[0];
                lastKey  = firstKey;
            }

            return(new Tuple <int, int>(firstKey, lastKey));
        }
Example #4
0
 protected KeyframePropertyData(KeyframePropertyInfo property, object target)
 {
     Property = property;
     Target   = target;
 }
Example #5
0
 public EventKeyframe(KeyframePropertyInfo property, object target,
                      Action action) : base(property, target)
 {
     ActionToExecute = action;
 }
Example #6
0
 public ValueKeyframe(KeyframePropertyInfo property, object target,
                      object value) : base(property, target)
 {
     Value = value;
 }