BsSkeleton.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 ANIM_BLEND_STATE_DESC
  29. {
  30. SPtr<AnimationCurves> curves;
  31. Vector<AnimationCurveMapping> boneToCurveMapping;
  32. TCurveEvaluator<Vector3> positionEval;
  33. TCurveEvaluator<Quaternion> rotationEval;
  34. TCurveEvaluator<Vector3> scaleEval;
  35. float weight;
  36. bool loop;
  37. UINT8 layer;
  38. };
  39. struct SkeletonPose
  40. {
  41. SkeletonPose(UINT32 numBones);
  42. ~SkeletonPose();
  43. Matrix4* bonePoses; // Global bone poses
  44. Vector3* positions; // Local positions
  45. Quaternion* rotations; // Local rotations
  46. Vector3* scales; // Local scales
  47. UINT32 numBones;
  48. };
  49. struct SkeletonBoneInfo
  50. {
  51. String name;
  52. UINT32 parent;
  53. };
  54. class BS_CORE_EXPORT Skeleton : public IReflectable // Note: Must be immutable in order to be usable on multiple threads
  55. {
  56. public:
  57. ~Skeleton();
  58. void getPose(SkeletonPose& pose, const AnimationClip& clip, float time, bool loop = true);
  59. // Animations in same layer must be consecutive. Layers must be arranged in ascending order.
  60. void getPose(SkeletonPose& pose, const ANIM_BLEND_STATE_DESC* states, UINT32 numStates);
  61. UINT32 getNumBones() const { return mNumBones; }
  62. const SkeletonBoneInfo& getBoneInfo(UINT32 idx) const { return mBoneInfo[idx]; }
  63. const Matrix4& getBindPose(UINT32 idx) const { return mInvBindPoses[idx]; }
  64. static SPtr<Skeleton> create(BONE_DESC* bones, UINT32 numBones);
  65. private:
  66. Skeleton();
  67. Skeleton(BONE_DESC* bones, UINT32 numBones);
  68. UINT32 mNumBones;
  69. Matrix4* mInvBindPoses;
  70. SkeletonBoneInfo* mBoneInfo;
  71. /************************************************************************/
  72. /* SERIALIZATION */
  73. /************************************************************************/
  74. public:
  75. friend class SkeletonRTTI;
  76. static RTTITypeBase* getRTTIStatic();
  77. RTTITypeBase* getRTTI() const override;
  78. /**
  79. * Creates a Skeleton with no data. You must populate its data manually.
  80. *
  81. * @note For serialization use only.
  82. */
  83. static SPtr<Skeleton> createEmpty();
  84. };
  85. /** @} */
  86. }