/// <summary> /// Creates a new animation push operation. /// </summary> /// <param name="evaluator">The evaluator.</param> /// <returns></returns> public static AnimationOperation NewPush(AnimationClipEvaluator evaluator) { return(new AnimationOperation { Type = AnimationOperationType.Push, Evaluator = evaluator, Time = TimeSpan.Zero }); }
/// <summary> /// Creates a new animation pop operation. /// </summary> /// <param name="evaluator">The evaluator.</param> /// <param name="time">The time.</param> /// <returns></returns> public static AnimationOperation NewPop(AnimationClipEvaluator evaluator, TimeSpan time) { return(new AnimationOperation { Type = AnimationOperationType.Pop, Evaluator = evaluator, Time = time }); }
public AnimationClipEvaluator CreateEvaluator(AnimationClip clip) { // Check if this clip has already been used if (clips.Add(clip) || clip.ShouldRescanChannels) { // If new clip, let's scan its channel to add new ones. foreach (var curve in clip.Channels) { Channel channel; if (channelsByName.TryGetValue(curve.Key, out channel)) { // TODO: Check if channel matches } else { // New channel, add it to every evaluator // Find blend type BlendType blendType; var elementType = curve.Value.ElementType; if (elementType == typeof(Quaternion)) { blendType = BlendType.Quaternion; } else if (elementType == typeof(float)) { blendType = BlendType.Float1; } else if (elementType == typeof(Vector2)) { blendType = BlendType.Float2; } else if (elementType == typeof(Vector3)) { blendType = BlendType.Float3; } else if (elementType == typeof(Vector4)) { blendType = BlendType.Float4; } else { blendType = BlittableHelper.IsBlittable(elementType) ? BlendType.Blit : BlendType.Object; } // Create channel structure channel.BlendType = blendType; channel.Offset = blendType == BlendType.Object ? objectsSize : structureSize; channel.PropertyName = curve.Key; channel.Size = curve.Value.ElementSize; channel.IsUserCustomProperty = curve.Value.IsUserCustomProperty; // Add channel channelsByName.Add(channel.PropertyName, channel); channels.Add(channel); if (blendType == BlendType.Object) { objectsSize++; } else { // Update new structure size // We also reserve space for a float that will specify channel existence and factor in case of subtree blending structureSize += sizeof(float) + channel.Size; } // Add new channel update info to every evaluator // TODO: Maybe it's better lazily done? (avoid need to store list of all evaluators) foreach (var currentEvaluator in evaluators) { currentEvaluator.AddChannel(ref channel); } } } } // Update results to fit the new data size lock (availableResultsPool) { foreach (var result in availableResultsPool) { if (result.DataSize < structureSize) { result.DataSize = structureSize; result.Data = new byte[structureSize]; } } } // Create evaluator and store it in list of instantiated evaluators AnimationClipEvaluator evaluator; lock (evaluatorPool) { if (evaluatorPool.Count > 0) { evaluator = evaluatorPool.Pop(); } else { evaluator = new AnimationClipEvaluator(); } } evaluator.Initialize(clip, channels); evaluators.Add(evaluator); return(evaluator); }