SpineTransformConstraint.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #include "SpineTransformConstraint.h"
  30. #include "SpineCommon.h"
  31. #include "SpineSprite.h"
  32. void SpineTransformConstraint::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("update"), &SpineTransformConstraint::update);
  34. ClassDB::bind_method(D_METHOD("get_data"), &SpineTransformConstraint::get_data);
  35. ClassDB::bind_method(D_METHOD("get_bones"), &SpineTransformConstraint::get_bones);
  36. ClassDB::bind_method(D_METHOD("get_target"), &SpineTransformConstraint::get_target);
  37. ClassDB::bind_method(D_METHOD("set_target", "v"), &SpineTransformConstraint::set_target);
  38. ClassDB::bind_method(D_METHOD("get_mix_rotate"), &SpineTransformConstraint::get_mix_rotate);
  39. ClassDB::bind_method(D_METHOD("set_mix_rotate", "v"), &SpineTransformConstraint::set_mix_rotate);
  40. ClassDB::bind_method(D_METHOD("get_mix_x"), &SpineTransformConstraint::get_mix_x);
  41. ClassDB::bind_method(D_METHOD("set_mix_x", "v"), &SpineTransformConstraint::set_mix_x);
  42. ClassDB::bind_method(D_METHOD("get_mix_y"), &SpineTransformConstraint::get_mix_y);
  43. ClassDB::bind_method(D_METHOD("set_mix_y", "v"), &SpineTransformConstraint::set_mix_y);
  44. ClassDB::bind_method(D_METHOD("get_mix_scale_x"), &SpineTransformConstraint::get_mix_scale_x);
  45. ClassDB::bind_method(D_METHOD("set_mix_scale_x", "v"), &SpineTransformConstraint::set_mix_scale_x);
  46. ClassDB::bind_method(D_METHOD("get_mix_scale_y"), &SpineTransformConstraint::get_mix_scale_y);
  47. ClassDB::bind_method(D_METHOD("set_mix_scale_y", "v"), &SpineTransformConstraint::set_mix_scale_y);
  48. ClassDB::bind_method(D_METHOD("get_mix_shear_y"), &SpineTransformConstraint::get_mix_shear_y);
  49. ClassDB::bind_method(D_METHOD("set_mix_shear_y", "v"), &SpineTransformConstraint::set_mix_shear_y);
  50. ClassDB::bind_method(D_METHOD("is_active"), &SpineTransformConstraint::is_active);
  51. ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineTransformConstraint::set_active);
  52. }
  53. void SpineTransformConstraint::update() {
  54. SPINE_CHECK(get_spine_object(), )
  55. get_spine_object()->update(spine::Physics_Update);
  56. }
  57. int SpineTransformConstraint::get_order() {
  58. SPINE_CHECK(get_spine_object(), 0)
  59. return get_spine_object()->getOrder();
  60. }
  61. Ref<SpineTransformConstraintData> SpineTransformConstraint::get_data() {
  62. SPINE_CHECK(get_spine_object(), nullptr)
  63. auto &data = get_spine_object()->getData();
  64. Ref<SpineTransformConstraintData> data_ref(memnew(SpineTransformConstraintData));
  65. data_ref->set_spine_object(*get_spine_owner()->get_skeleton_data_res(), &data);
  66. return data_ref;
  67. }
  68. Array SpineTransformConstraint::get_bones() {
  69. Array result;
  70. SPINE_CHECK(get_spine_object(), result)
  71. auto &bones = get_spine_object()->getBones();
  72. result.resize((int) bones.size());
  73. for (int i = 0; i < bones.size(); ++i) {
  74. auto bone = bones[i];
  75. Ref<SpineBone> bone_ref(memnew(SpineBone));
  76. bone_ref->set_spine_object(get_spine_owner(), bone);
  77. result[i] = bone_ref;
  78. }
  79. return result;
  80. }
  81. Ref<SpineBone> SpineTransformConstraint::get_target() {
  82. SPINE_CHECK(get_spine_object(), nullptr)
  83. auto target = get_spine_object()->getTarget();
  84. if (!target) return nullptr;
  85. Ref<SpineBone> target_ref(memnew(SpineBone));
  86. target_ref->set_spine_object(get_spine_owner(), target);
  87. return target_ref;
  88. }
  89. void SpineTransformConstraint::set_target(Ref<SpineBone> v) {
  90. SPINE_CHECK(get_spine_object(), )
  91. get_spine_object()->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr);
  92. }
  93. float SpineTransformConstraint::get_mix_rotate() {
  94. SPINE_CHECK(get_spine_object(), 0)
  95. return get_spine_object()->getMixRotate();
  96. }
  97. void SpineTransformConstraint::set_mix_rotate(float v) {
  98. SPINE_CHECK(get_spine_object(), )
  99. get_spine_object()->setMixRotate(v);
  100. }
  101. float SpineTransformConstraint::get_mix_x() {
  102. SPINE_CHECK(get_spine_object(), 0)
  103. return get_spine_object()->getMixX();
  104. }
  105. void SpineTransformConstraint::set_mix_x(float v) {
  106. SPINE_CHECK(get_spine_object(), )
  107. get_spine_object()->setMixX(v);
  108. }
  109. float SpineTransformConstraint::get_mix_y() {
  110. SPINE_CHECK(get_spine_object(), 0)
  111. return get_spine_object()->getMixY();
  112. }
  113. void SpineTransformConstraint::set_mix_y(float v) {
  114. SPINE_CHECK(get_spine_object(), )
  115. get_spine_object()->setMixY(v);
  116. }
  117. float SpineTransformConstraint::get_mix_scale_x() {
  118. SPINE_CHECK(get_spine_object(), 0)
  119. return get_spine_object()->getMixScaleX();
  120. }
  121. void SpineTransformConstraint::set_mix_scale_x(float v) {
  122. SPINE_CHECK(get_spine_object(), )
  123. get_spine_object()->setMixScaleX(v);
  124. }
  125. float SpineTransformConstraint::get_mix_scale_y() {
  126. SPINE_CHECK(get_spine_object(), 0)
  127. return get_spine_object()->getMixScaleY();
  128. }
  129. void SpineTransformConstraint::set_mix_scale_y(float v) {
  130. SPINE_CHECK(get_spine_object(), )
  131. get_spine_object()->setMixScaleY(v);
  132. }
  133. float SpineTransformConstraint::get_mix_shear_y() {
  134. SPINE_CHECK(get_spine_object(), 0)
  135. return get_spine_object()->getMixShearY();
  136. }
  137. void SpineTransformConstraint::set_mix_shear_y(float v) {
  138. SPINE_CHECK(get_spine_object(), )
  139. get_spine_object()->setMixShearY(v);
  140. }
  141. bool SpineTransformConstraint::is_active() {
  142. SPINE_CHECK(get_spine_object(), false)
  143. return get_spine_object()->isActive();
  144. }
  145. void SpineTransformConstraint::set_active(bool v) {
  146. SPINE_CHECK(get_spine_object(), )
  147. get_spine_object()->setActive(v);
  148. }