skeleton_2d.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*************************************************************************/
  2. /* skeleton_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef SKELETON_2D_H
  31. #define SKELETON_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class Skeleton2D;
  34. class Bone2D : public Node2D {
  35. GDCLASS(Bone2D, Node2D);
  36. friend class Skeleton2D;
  37. #ifdef TOOLS_ENABLED
  38. friend class AnimatedValuesBackup;
  39. #endif
  40. Bone2D *parent_bone;
  41. Skeleton2D *skeleton;
  42. Transform2D rest;
  43. float default_length;
  44. int skeleton_index;
  45. protected:
  46. void _notification(int p_what);
  47. static void _bind_methods();
  48. public:
  49. void set_rest(const Transform2D &p_rest);
  50. Transform2D get_rest() const;
  51. void apply_rest();
  52. Transform2D get_skeleton_rest() const;
  53. String get_configuration_warning() const;
  54. void set_default_length(float p_length);
  55. float get_default_length() const;
  56. int get_index_in_skeleton() const;
  57. Bone2D();
  58. };
  59. class Skeleton2D : public Node2D {
  60. GDCLASS(Skeleton2D, Node2D);
  61. friend class Bone2D;
  62. #ifdef TOOLS_ENABLED
  63. friend class AnimatedValuesBackup;
  64. #endif
  65. struct Bone {
  66. bool operator<(const Bone &p_bone) const {
  67. return p_bone.bone->is_greater_than(bone);
  68. }
  69. Bone2D *bone;
  70. int parent_index;
  71. Transform2D accum_transform;
  72. Transform2D rest_inverse;
  73. };
  74. Vector<Bone> bones;
  75. bool bone_setup_dirty;
  76. void _make_bone_setup_dirty();
  77. void _update_bone_setup();
  78. bool transform_dirty;
  79. void _make_transform_dirty();
  80. void _update_transform();
  81. RID skeleton;
  82. protected:
  83. void _notification(int p_what);
  84. static void _bind_methods();
  85. public:
  86. int get_bone_count() const;
  87. Bone2D *get_bone(int p_idx);
  88. RID get_skeleton() const;
  89. Skeleton2D();
  90. ~Skeleton2D();
  91. };
  92. #endif // SKELETON_2D_H