Skeleton.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Core/Reference.h>
  5. #include <Core/Result.h>
  6. #include <ObjectStream/SerializableObject.h>
  7. namespace JPH {
  8. class StreamIn;
  9. class StreamOut;
  10. /// Resource that contains the joint hierarchy for a skeleton
  11. class Skeleton : public RefTarget<Skeleton>
  12. {
  13. public:
  14. JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(Skeleton)
  15. using SkeletonResult = Result<Ref<Skeleton>>;
  16. /// Declare internal structure for a joint
  17. class Joint
  18. {
  19. public:
  20. JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(Joint)
  21. string mName; ///< Name of the joint
  22. string mParentName; ///< Name of parent joint
  23. int mParentJointIndex = -1; ///< Index of parent joint (in mJoints) or -1 if it has no parent
  24. };
  25. using JointVector = vector<Joint>;
  26. ///@name Access to the joints
  27. ///@{
  28. const JointVector & GetJoints() const { return mJoints; }
  29. JointVector & GetJoints() { return mJoints; }
  30. int GetJointCount() const { return (int)mJoints.size(); }
  31. const Joint & GetJoint(int inJoint) const { return mJoints[inJoint]; }
  32. Joint & GetJoint(int inJoint) { return mJoints[inJoint]; }
  33. ///@}
  34. /// Find joint by name
  35. int GetJointIndex(const string &inName) const;
  36. /// Fill in parent joint indices based on name
  37. void CalculateParentJointIndices();
  38. /// Saves the state of this object in binary form to inStream.
  39. void SaveBinaryState(StreamOut &inStream) const;
  40. /// Restore the state of this object from inStream.
  41. static SkeletonResult sRestoreFromBinaryState(StreamIn &inStream);
  42. private:
  43. /// Joints
  44. JointVector mJoints;
  45. };
  46. } // JPH