Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PlayingAnimation.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Linq;
5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Extensions;
7 using SiliconStudio.Core.Mathematics;
8 using SiliconStudio.Core.Serialization;
9 using SiliconStudio.Core.Serialization.Converters;
10 using SiliconStudio.Paradox.DataModel;
11 using SiliconStudio.Paradox.Effects;
12 
13 namespace SiliconStudio.Paradox.Engine
14 {
15  [DataContract]
16  public class PlayingAnimation
17  {
18  // Used internally by animation system
19  // TODO: Stored in AnimationProcessor?
20  internal AnimationClipEvaluator Evaluator;
21  internal float[] NodeFactors;
23 
24  internal PlayingAnimation(AnimationComponent animationComponent, string name)
25  {
26  AnimationComponent = animationComponent;
27  IsPlaying = true;
28  TimeFactor = 1.0f;
29  BlendOperation = AnimationBlendOperation.LinearBlend;
30  Name = name;
31  Clip = animationComponent.Animations[name];
32  RepeatMode = Clip.RepeatMode;
33  }
34 
35  /// <summary>
36  /// Gets or sets the blend operation.
37  /// </summary>
38  /// <value>
39  /// The blend operation.
40  /// </value>
41  public AnimationBlendOperation BlendOperation { get; set; }
42 
43  /// <summary>
44  /// Gets or sets the repeat mode.
45  /// </summary>
46  /// <value>
47  /// The repeat mode.
48  /// </value>
49  public AnimationRepeatMode RepeatMode { get; set; }
50 
51  /// <summary>
52  /// Gets or sets the animation weight.
53  /// </summary>
54  /// <value>
55  /// The weight.
56  /// </value>
57  public float Weight { get; set; }
58 
59  public string Name { get; private set; }
60 
61  public AnimationClip Clip { get; private set; }
62 
63  /// <summary>
64  /// Gets or sets the current time.
65  /// </summary>
66  /// <value>
67  /// The current time.
68  /// </value>
69  public TimeSpan CurrentTime { get; set; }
70 
71  /// <summary>
72  /// Gets or sets the playback speed factor.
73  /// </summary>
74  /// <value>
75  /// The playback speed factor.
76  /// </value>
77  public float TimeFactor { get; set; }
78 
79  /// <summary>
80  /// Gets or sets a value indicating whether animation is playing.
81  /// </summary>
82  /// <value>
83  /// <c>true</c> if animation is playing; otherwise, <c>false</c>.
84  /// </value>
85  public bool IsPlaying { get; set; }
86 
87  // Animation
88  public float WeightTarget { get; set; }
89  public TimeSpan RemainingTime { get; set; }
90 
91  /// <summary>
92  /// Filters the animation to the specified sub-trees given by <see cref="roots"/>.
93  /// </summary>
94  /// <param name="nodes">The node hierarchy.</param>
95  /// <param name="roots">The node roots of sub-trees that should be active (others will be filtered out).</param>
96  public void FilterNodes(ModelNodeDefinition[] nodes, params string[] roots)
97  {
98  // Initialize list of factors (matching nodes list)
99  var nodeFactors = new float[nodes.Length];
100  for (int index = 0; index < nodes.Length; index++)
101  {
102  var node = nodes[index];
103  if (roots.Contains(node.Name)
104  || (node.ParentIndex != -1 && nodeFactors[node.ParentIndex] == 1.0f))
105  {
106  nodeFactors[index] = 1.0f;
107  }
108  }
109 
110  // Update animation channel factors
111  var blenderChannels = Evaluator.BlenderChannels;
112  var channels = Evaluator.Channels.Items;
113  for (int index = 0; index < blenderChannels.Count; index++)
114  {
115  var blenderChannel = blenderChannels[index];
116 
117  // Find node index
118  var nodeName = MeshAnimationUpdater.GetNodeName(blenderChannel.PropertyName);
119  var nodeIndex = nodes.IndexOf(x => x.Name == nodeName);
120 
121  if (nodeIndex != -1)
122  {
123  // Update factor
124  channels[index].Factor *= nodeFactors[nodeIndex];
125  }
126  }
127  }
128  }
129 }
void FilterNodes(ModelNodeDefinition[] nodes, params string[] roots)
Filters the animation to the specified sub-trees given by roots.
AnimationBlendOperation
Describes the type of animation blend operation.
Add animation capabilities to an Entity. It will usually apply to ModelComponent.ModelViewHierarchy ...
An aggregation of AnimationCurve with their channel names.
AnimationRepeatMode
Enumeration describing how an animation should be repeated.
Describes a single transformation node, usually in a Model node hierarchy.
Evaluates AnimationClip to a AnimationClipResult at a given time.