BsSkeleton.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsIReflectable.h"
  6. #include "BsMatrix4.h"
  7. #include "BsVector3.h"
  8. #include "BsQuaternion.h"
  9. #include "BsCurveEvaluator.h"
  10. namespace BansheeEngine
  11. {
  12. /** @addtogroup Animation-Internal
  13. * @{
  14. */
  15. /** Contains indices for position/rotation/scale animation curves. */
  16. struct AnimationCurveMapping
  17. {
  18. UINT32 position;
  19. UINT32 rotation;
  20. UINT32 scale;
  21. };
  22. struct BONE_DESC
  23. {
  24. String name;
  25. UINT32 parent;
  26. Matrix4 invBindPose;
  27. };
  28. struct AnimationState
  29. {
  30. SPtr<AnimationCurves> curves;
  31. Vector<AnimationCurveMapping> boneToCurveMapping;
  32. TCurveEvaluatorData<Vector3> positionEval;
  33. TCurveEvaluatorData<Quaternion> rotationEval;
  34. TCurveEvaluatorData<Vector3> scaleEval;
  35. float weight;
  36. bool loop;
  37. };
  38. struct AnimationStateLayer
  39. {
  40. AnimationState* states;
  41. UINT32 numStates;
  42. UINT8 index;
  43. bool normalizeWeights;
  44. };
  45. struct SkeletonPose
  46. {
  47. SkeletonPose(UINT32 numBones);
  48. ~SkeletonPose();
  49. Matrix4* bonePoses; // Global bone poses
  50. Vector3* positions; // Local positions
  51. Quaternion* rotations; // Local rotations
  52. Vector3* scales; // Local scales
  53. UINT32 numBones;
  54. };
  55. struct SkeletonBoneInfo
  56. {
  57. String name;
  58. UINT32 parent;
  59. };
  60. class BS_CORE_EXPORT Skeleton : public IReflectable // Note: Must be immutable in order to be usable on multiple threads
  61. {
  62. public:
  63. ~Skeleton();
  64. void getPose(SkeletonPose& pose, const AnimationClip& clip, float time, bool loop = true);
  65. void getPose(SkeletonPose& pose, const AnimationStateLayer* layers, UINT32 numLayers);
  66. UINT32 getNumBones() const { return mNumBones; }
  67. const SkeletonBoneInfo& getBoneInfo(UINT32 idx) const { return mBoneInfo[idx]; }
  68. const Matrix4& getBindPose(UINT32 idx) const { return mInvBindPoses[idx]; }
  69. static SPtr<Skeleton> create(BONE_DESC* bones, UINT32 numBones);
  70. private:
  71. Skeleton();
  72. Skeleton(BONE_DESC* bones, UINT32 numBones);
  73. UINT32 mNumBones;
  74. Matrix4* mInvBindPoses;
  75. SkeletonBoneInfo* mBoneInfo;
  76. /************************************************************************/
  77. /* SERIALIZATION */
  78. /************************************************************************/
  79. public:
  80. friend class SkeletonRTTI;
  81. static RTTITypeBase* getRTTIStatic();
  82. RTTITypeBase* getRTTI() const override;
  83. /**
  84. * Creates a Skeleton with no data. You must populate its data manually.
  85. *
  86. * @note For serialization use only.
  87. */
  88. static SPtr<Skeleton> createEmpty();
  89. };
  90. /** @} */
  91. }