BsSkeleton.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. namespace BansheeEngine
  8. {
  9. /** @addtogroup Animation-Internal
  10. * @{
  11. */
  12. struct BONE_DESC
  13. {
  14. String name;
  15. UINT32 parent;
  16. Matrix4 invBindPose;
  17. };
  18. struct ANIM_BLEND_STATE_DESC
  19. {
  20. const AnimationClip* clip;
  21. float weight;
  22. bool loop;
  23. UINT8 layer;
  24. };
  25. struct SkeletonPose
  26. {
  27. SkeletonPose(UINT32 numBones)
  28. :numBones(numBones), bonePoses(bs_newN<Matrix4>(numBones))
  29. {}
  30. ~SkeletonPose()
  31. {
  32. bs_deleteN(bonePoses, numBones);
  33. }
  34. Matrix4* bonePoses;
  35. UINT32 numBones;
  36. };
  37. struct SkeletonBoneInfo
  38. {
  39. String name;
  40. UINT32 parent;
  41. };
  42. class BS_CORE_EXPORT Skeleton : public IReflectable // Note: Must be immutable in order to be usable on multiple threads
  43. {
  44. public:
  45. ~Skeleton();
  46. void getPose(SkeletonPose& pose, const AnimationClip& clip, float time, bool loop = true);
  47. void getPose(SkeletonPose& pose, const ANIM_BLEND_STATE_DESC* states, UINT32 numStates, float time);
  48. UINT32 getNumBones() const { return mNumBones; }
  49. const SkeletonBoneInfo& getBoneInfo(UINT32 idx) const { return mBoneInfo[idx]; }
  50. const Matrix4& getBindPose(UINT32 idx) const { return mBindPoses[idx]; }
  51. static SPtr<Skeleton> create(BONE_DESC* bones, UINT32 numBones);
  52. private:
  53. Skeleton();
  54. Skeleton(BONE_DESC* bones, UINT32 numBones);
  55. UINT32 mNumBones;
  56. Matrix4* mBindPoses;
  57. SkeletonBoneInfo* mBoneInfo;
  58. /************************************************************************/
  59. /* SERIALIZATION */
  60. /************************************************************************/
  61. public:
  62. friend class SkeletonRTTI;
  63. static RTTITypeBase* getRTTIStatic();
  64. RTTITypeBase* getRTTI() const override;
  65. /**
  66. * Creates a Skeleton with no data. You must populate its data manually.
  67. *
  68. * @note For serialization use only.
  69. */
  70. static SPtr<Skeleton> createEmpty();
  71. };
  72. /** @} */
  73. }