SpineSkeleton.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated April 5, 2025. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2025, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #pragma once
  30. #include "SpineCommon.h"
  31. #include "SpineSkeletonDataResource.h"
  32. #include "SpineBone.h"
  33. #include "SpineSlot.h"
  34. #include "SpineIkConstraint.h"
  35. #include "SpineTransformConstraint.h"
  36. #include "SpinePathConstraint.h"
  37. #include "SpinePhysicsConstraint.h"
  38. #include <unordered_map>
  39. class SpineSprite;
  40. class SpineSkeleton : public REFCOUNTED {
  41. GDCLASS(SpineSkeleton, REFCOUNTED);
  42. friend class SpineBone;
  43. friend class SpineSlot;
  44. friend class SpineTimeline;
  45. friend class SpineSprite;
  46. friend class SpineAnimation;
  47. friend class SpineAnimationState;
  48. friend class SpineAnimationTrack;
  49. friend class SpineBoneNode;
  50. friend class SpineSlotNode;
  51. protected:
  52. static void _bind_methods();
  53. void set_spine_sprite(SpineSprite *_sprite);
  54. spine::Skeleton *get_spine_object() { return skeleton; }
  55. SpineSprite *get_spine_owner() { return sprite; }
  56. Ref<SpineSkeletonDataResource> get_skeleton_data_res() const;
  57. private:
  58. spine::Skeleton *skeleton;
  59. SpineSprite *sprite;
  60. spine::Vector<float> bounds_vertex_buffer;
  61. Ref<SpineSkin> last_skin;
  62. std::unordered_map<spine::Bone *, Ref<SpineBone>> _cached_bones;
  63. std::unordered_map<spine::Slot *, Ref<SpineSlot>> _cached_slots;
  64. public:
  65. SpineSkeleton();
  66. ~SpineSkeleton() override;
  67. void update_world_transform(SpineConstant::Physics physics);
  68. void set_to_setup_pose();
  69. void set_bones_to_setup_pose();
  70. void set_slots_to_setup_pose();
  71. Ref<SpineBone> find_bone(const String &name);
  72. Ref<SpineSlot> find_slot(const String &name);
  73. void set_skin_by_name(const String &skin_name);
  74. void set_skin(Ref<SpineSkin> new_skin);
  75. Ref<SpineAttachment> get_attachment_by_slot_name(const String &slot_name, const String &attachment_name);
  76. Ref<SpineAttachment> get_attachment_by_slot_index(int slot_index, const String &attachment_name);
  77. void set_attachment(const String &slot_name, const String &attachment_name);
  78. Ref<SpineIkConstraint> find_ik_constraint(const String &constraint_name);
  79. Ref<SpineTransformConstraint> find_transform_constraint(const String &constraint_name);
  80. Ref<SpinePathConstraint> find_path_constraint(const String &constraint_name);
  81. Ref<SpinePhysicsConstraint> find_physics_constraint(const String &constraint_name);
  82. Rect2 get_bounds();
  83. Ref<SpineBone> get_root_bone();
  84. Array get_bones();
  85. Array get_slots();
  86. Array get_draw_order();
  87. Array get_ik_constraints();
  88. Array get_transform_constraints();
  89. Array get_path_constraints();
  90. Array get_physics_constraints();
  91. Ref<SpineSkin> get_skin();
  92. Color get_color();
  93. void set_color(Color v);
  94. void set_position(Vector2 position);
  95. float get_x();
  96. void set_x(float v);
  97. float get_y();
  98. void set_y(float v);
  99. float get_scale_x();
  100. void set_scale_x(float v);
  101. float get_scale_y();
  102. void set_scale_y(float v);
  103. float get_time();
  104. void set_time(float time);
  105. void update(float delta);
  106. void physics_translate(float x, float y);
  107. void physics_rotate(float x, float y, float degrees);
  108. };