AnimationClip.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Animation
  8. * @{
  9. */
  10. /// <summary>
  11. /// Contains animation curves for translation/rotation/scale of scene object/skeleton bones, as well as curves for
  12. /// generic property animation.
  13. /// </summary>
  14. public class AnimationClip : Resource
  15. {
  16. // Constructor for runtime use only (dummy parameter to differentiate from the normal constructor)
  17. private AnimationClip(bool dummy)
  18. { }
  19. /// <summary>
  20. /// Creates a new animation clip with no curves or events.
  21. /// </summary>
  22. public AnimationClip()
  23. {
  24. Internal_CreateInstance(this);
  25. }
  26. /// <summary>
  27. /// Returns the length of the animation clip, in seconds.
  28. /// </summary>
  29. public float Length
  30. {
  31. get { return Internal_GetLength(mCachedPtr); }
  32. }
  33. /// <summary>
  34. /// Returns the number of samples per second the animation clip curves were sampled at. This value is not used by
  35. /// the animation clip or curves directly since unevenly spaced keyframes are supported. But it can be of value when
  36. /// determining the original sample rate of an imported animation or similar.
  37. /// </summary>
  38. public int SampleRate
  39. {
  40. get { return Internal_GetSampleRate(mCachedPtr); }
  41. set { Internal_SetSampleRate(mCachedPtr, value); }
  42. }
  43. /// <summary>
  44. /// A set of all curves stored in the animation clip.
  45. /// </summary>
  46. public AnimationCurves Curves
  47. {
  48. get { return Internal_GetAnimationCurves(mCachedPtr); }
  49. set { Internal_SetAnimationCurves(mCachedPtr, value); }
  50. }
  51. /// <summary>
  52. /// A set of all events stored in the animation clip.
  53. /// </summary>
  54. public AnimationEvent[] Events
  55. {
  56. get { return Internal_GetAnimationEvents(mCachedPtr); }
  57. set { Internal_SetAnimationEvents(mCachedPtr, value); }
  58. }
  59. /// <summary>
  60. /// Returns a set of curves containing motion of the root bone. This allows the user to evaluate the root bone
  61. /// animation curves manually, instead of through the normal animation process. This property is only available
  62. /// if animation clip was imported with root motion import enabled.
  63. /// </summary>
  64. public RootMotion RootMotion
  65. {
  66. get { return Internal_GetRootMotion(mCachedPtr); }
  67. }
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern void Internal_CreateInstance(AnimationClip instance);
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern AnimationCurves Internal_GetAnimationCurves(IntPtr thisPtr);
  72. [MethodImpl(MethodImplOptions.InternalCall)]
  73. private static extern void Internal_SetAnimationCurves(IntPtr thisPtr, AnimationCurves curves);
  74. [MethodImpl(MethodImplOptions.InternalCall)]
  75. private static extern AnimationEvent[] Internal_GetAnimationEvents(IntPtr thisPtr);
  76. [MethodImpl(MethodImplOptions.InternalCall)]
  77. private static extern void Internal_SetAnimationEvents(IntPtr thisPtr, AnimationEvent[] events);
  78. [MethodImpl(MethodImplOptions.InternalCall)]
  79. private static extern RootMotion Internal_GetRootMotion(IntPtr thisPtr);
  80. [MethodImpl(MethodImplOptions.InternalCall)]
  81. private static extern float Internal_GetLength(IntPtr thisPtr);
  82. [MethodImpl(MethodImplOptions.InternalCall)]
  83. private static extern int Internal_GetSampleRate(IntPtr thisPtr);
  84. [MethodImpl(MethodImplOptions.InternalCall)]
  85. private static extern void Internal_SetSampleRate(IntPtr thisPtr, int sampleRate);
  86. }
  87. /// <summary>
  88. /// Event that is triggered when animation reaches a certain point.
  89. /// </summary>
  90. public class AnimationEvent
  91. {
  92. /// <summary>
  93. /// Constructs a new animation event.
  94. /// </summary>
  95. /// <param name="name">Name used to identify the event when it is triggered.</param>
  96. /// <param name="time">Time at which to trigger the event, in seconds.</param>
  97. public AnimationEvent(string name, float time)
  98. {
  99. Name = name;
  100. Time = time;
  101. }
  102. /// <summary>
  103. /// Name used to identify the event when it is triggered.
  104. /// </summary>
  105. public string Name;
  106. /// <summary>
  107. /// Time at which to trigger the event, in seconds.
  108. /// </summary>
  109. public float Time;
  110. }
  111. /// <summary>
  112. /// Contains a set of animation curves used for moving and rotating the root bone.
  113. /// </summary>
  114. public class RootMotion
  115. {
  116. /// <summary>
  117. /// Animation curve representing the movement of the root bone.
  118. /// </summary>
  119. public Vector3Curve Position;
  120. /// <summary>
  121. /// Animation curve representing the rotation of the root bone.
  122. /// </summary>
  123. public QuaternionCurve Rotation;
  124. }
  125. /** @} */
  126. }