SkeletonPose.h 2.9 KB

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