4 using System.Collections.Generic;
6 using System.Runtime.InteropServices;
7 using SiliconStudio.Core;
8 using SiliconStudio.Core.Collections;
9 using SiliconStudio.Core.Serialization;
10 using SiliconStudio.Core.Serialization.Contents;
12 namespace SiliconStudio.
Paradox.DataModel
14 [DataContract(Inherited =
true)]
17 public const int AnimationSortedValueBlock = 4096;
19 public int AnimationSortedValueCount {
get; set; }
20 public string[] TargetKeys {
get; set; }
28 public TimeSpan Duration
30 get {
return AnimationSortedValueCount == 0 ? TimeSpan.FromSeconds(1) : AnimationSortedValues[(AnimationSortedValueCount - 1) / AnimationSortedValueBlock][(AnimationSortedValueCount - 1) % AnimationSortedValueBlock].Value.Time; }
38 var animationChannelsKeyValuePair = animationChannelsByName.ToList();
39 var animationChannels = animationChannelsKeyValuePair.Select(x => x.Value).ToList();
40 result.TargetKeys = animationChannelsKeyValuePair.Select(x => x.Key).ToArray();
43 var animationValues =
new List<AnimationKeyValuePair<T>>[animationChannels.Count];
45 for (
int channelIndex = 0; channelIndex < animationChannels.Count; ++channelIndex)
47 var channel = animationChannels[channelIndex];
48 var animationChannelValues = animationValues[channelIndex] =
new List<AnimationKeyValuePair<T>>();
49 if (channel.KeyFrames.Count > 0)
52 result.AnimationInitialValues[channelIndex].InterpolationType = channel.InterpolationType;
53 result.AnimationInitialValues[channelIndex].Value1 = channel.KeyFrames[0];
54 result.AnimationInitialValues[channelIndex].Value2 = channel.KeyFrames[channel.KeyFrames.Count > 1 ? 1 : 0];
57 for (
int keyIndex = 2; keyIndex < channel.KeyFrames.Count; ++keyIndex)
60 var requiredTime = channel.KeyFrames[keyIndex - 2].Time;
62 animationChannelValues.Add(
new AnimationKeyValuePair<T> { ChannelIndex = channelIndex, RequiredTime = requiredTime, Value = channel.KeyFrames[keyIndex] });
65 if (keyIndex == channel.KeyFrames.Count - 1)
67 requiredTime = channel.KeyFrames[keyIndex - 1].Time;
68 animationChannelValues.Add(
new AnimationKeyValuePair<T> { ChannelIndex = channelIndex, RequiredTime = requiredTime, Value = channel.KeyFrames[keyIndex] });
79 int animationValueCount = 0;
82 var animationChannelByNextTime =
new MultiValueSortedDictionary<CompressedTimeSpan, KeyValuePair<int, int>>();
83 for (
int channelIndex = 0; channelIndex < animationChannels.Count; ++channelIndex)
85 var animationChannelValues = animationValues[channelIndex];
86 animationValueCount += animationChannelValues.Count;
87 if (animationChannelValues.Count > 0)
88 animationChannelByNextTime.Add(animationChannelValues[0].RequiredTime,
new KeyValuePair<int, int>(channelIndex, 0));
92 result.AnimationSortedValueCount = animationValueCount;
93 var animationSortedValues =
new AnimationKeyValuePair<T>[(animationValueCount + AnimationSortedValueBlock - 1) / AnimationSortedValueBlock][];
94 result.AnimationSortedValues = animationSortedValues;
95 for (
int i = 0; i < animationSortedValues.Length; ++i)
97 var remainingValueCount = animationValueCount - i * AnimationSortedValueBlock;
102 animationValueCount = 0;
103 while (animationChannelByNextTime.Count > 0)
105 var firstItem = animationChannelByNextTime.First();
106 animationSortedValues[animationValueCount / AnimationSortedValueBlock][animationValueCount % AnimationSortedValueBlock] = animationValues[firstItem.Value.Key][firstItem.Value.Value];
107 animationValueCount++;
108 animationChannelByNextTime.Remove(firstItem);
111 if (firstItem.Value.Value + 1 < animationValues[firstItem.Value.Key].Count)
112 animationChannelByNextTime.Add(animationValues[firstItem.Value.Key][firstItem.Value.Value + 1].RequiredTime,
new KeyValuePair<int, int>(firstItem.Value.Key, firstItem.Value.Value + 1));
120 [StructLayout(LayoutKind.Sequential)]
123 public string Name {
get; set; }
127 [StructLayout(LayoutKind.Sequential)]
128 public struct AnimationKeyValuePair<T>
140 [StructLayout(LayoutKind.Sequential)]
141 public struct AnimationInitialValues<T>
AnimationCurveInterpolationType
Describes how a curve should be interpolated.
static AnimationData< T > FromAnimationChannels(IDictionary< string, AnimationCurve< T >> animationChannelsByName)
CompressedTimeSpan RequiredTime
AnimationCurveInterpolationType InterpolationType
Typed class for animation curves.
A single key frame value.