SkeletonPose.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Skeleton/Skeleton.h>
  5. #include <Jolt/Skeleton/SkeletalAnimation.h>
  6. JPH_NAMESPACE_BEGIN
  7. #ifdef JPH_DEBUG_RENDERER
  8. class DebugRenderer;
  9. #endif // JPH_DEBUG_RENDERER
  10. /// Instance of a skeleton, contains the pose the current skeleton is in
  11. class SkeletonPose
  12. {
  13. public:
  14. JPH_OVERRIDE_NEW_DELETE
  15. using JointState = SkeletalAnimation::JointState;
  16. using JointStateVector = Array<JointState>;
  17. using Mat44Vector = Array<Mat44>;
  18. ///@name Skeleton
  19. ///@{
  20. void SetSkeleton(const Skeleton *inSkeleton);
  21. const Skeleton * GetSkeleton() const { return mSkeleton; }
  22. ///@}
  23. ///@name Properties of the joints
  24. ///@{
  25. uint GetJointCount() const { return (uint)mJoints.size(); }
  26. const JointStateVector & GetJoints() const { return mJoints; }
  27. JointStateVector & GetJoints() { return mJoints; }
  28. const JointState & GetJoint(int inJoint) const { return mJoints[inJoint]; }
  29. JointState & GetJoint(int inJoint) { return mJoints[inJoint]; }
  30. ///@}
  31. ///@name Joint matrices
  32. ///@{
  33. const Mat44Vector & GetJointMatrices() const { return mJointMatrices; }
  34. Mat44Vector & GetJointMatrices() { return mJointMatrices; }
  35. const Mat44 & GetJointMatrix(int inJoint) const { return mJointMatrices[inJoint]; }
  36. Mat44 & GetJointMatrix(int inJoint) { return mJointMatrices[inJoint]; }
  37. ///@}
  38. /// Convert the joint states to joint matrices
  39. void CalculateJointMatrices();
  40. /// Convert joint matrices to joint states
  41. void CalculateJointStates();
  42. /// Outputs the joint matrices in local space (ensure that outMatrices has GetJointCount() elements, assumes that values in GetJoints() is up to date)
  43. void CalculateLocalSpaceJointMatrices(Mat44 *outMatrices) const;
  44. #ifdef JPH_DEBUG_RENDERER
  45. /// Draw settings
  46. struct DrawSettings
  47. {
  48. bool mDrawJoints = true;
  49. bool mDrawJointOrientations = true;
  50. bool mDrawJointNames = false;
  51. };
  52. /// Draw current pose
  53. void Draw(const DrawSettings &inDrawSettings, DebugRenderer *inRenderer, Mat44Arg inOffset = Mat44::sIdentity()) const;
  54. #endif // JPH_DEBUG_RENDERER
  55. private:
  56. RefConst<Skeleton> mSkeleton; ///< Skeleton definition
  57. JointStateVector mJoints; ///< Local joint orientations (local to parent Joint)
  58. Mat44Vector mJointMatrices; ///< Local joint matrices (local to world matrix)
  59. };
  60. JPH_NAMESPACE_END