SpineTransformConstraintData.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "SpineTransformConstraintData.h"
  30. #include "SpineCommon.h"
  31. void SpineTransformConstraintData::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_bones"), &SpineTransformConstraintData::get_bones);
  33. ClassDB::bind_method(D_METHOD("get_target"), &SpineTransformConstraintData::get_target);
  34. ClassDB::bind_method(D_METHOD("get_mix_rotate"), &SpineTransformConstraintData::get_mix_rotate);
  35. ClassDB::bind_method(D_METHOD("get_mix_x"), &SpineTransformConstraintData::get_mix_x);
  36. ClassDB::bind_method(D_METHOD("get_mix_y"), &SpineTransformConstraintData::get_mix_y);
  37. ClassDB::bind_method(D_METHOD("get_mix_scale_x"), &SpineTransformConstraintData::get_mix_scale_x);
  38. ClassDB::bind_method(D_METHOD("get_mix_scale_y"), &SpineTransformConstraintData::get_mix_scale_y);
  39. ClassDB::bind_method(D_METHOD("get_mix_shear_y"), &SpineTransformConstraintData::get_mix_shear_y);
  40. ClassDB::bind_method(D_METHOD("get_offset_rotation"), &SpineTransformConstraintData::get_offset_rotation);
  41. ClassDB::bind_method(D_METHOD("get_offset_x"), &SpineTransformConstraintData::get_offset_x);
  42. ClassDB::bind_method(D_METHOD("get_offset_y"), &SpineTransformConstraintData::get_offset_y);
  43. ClassDB::bind_method(D_METHOD("get_offset_scale_x"), &SpineTransformConstraintData::get_offset_scale_x);
  44. ClassDB::bind_method(D_METHOD("get_offset_scale_y"), &SpineTransformConstraintData::get_offset_scale_y);
  45. ClassDB::bind_method(D_METHOD("get_offset_shear_y"), &SpineTransformConstraintData::get_offset_shear_y);
  46. ClassDB::bind_method(D_METHOD("is_relative"), &SpineTransformConstraintData::is_relative);
  47. ClassDB::bind_method(D_METHOD("is_local"), &SpineTransformConstraintData::is_local);
  48. }
  49. Array SpineTransformConstraintData::get_bones() {
  50. Array result;
  51. SPINE_CHECK(get_spine_constraint_data(), result)
  52. auto bones = get_spine_constraint_data()->getBones();
  53. result.resize((int) bones.size());
  54. for (int i = 0; i < (int) bones.size(); ++i) {
  55. Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
  56. bone_ref->set_spine_object(get_spine_owner(), bones[i]);
  57. result[i] = bone_ref;
  58. }
  59. return result;
  60. }
  61. Ref<SpineBoneData> SpineTransformConstraintData::get_target() {
  62. SPINE_CHECK(get_spine_constraint_data(), nullptr)
  63. auto bone = get_spine_constraint_data()->getTarget();
  64. if (!bone) return nullptr;
  65. Ref<SpineBoneData> slot_ref(memnew(SpineBoneData));
  66. slot_ref->set_spine_object(get_spine_owner(), bone);
  67. return slot_ref;
  68. }
  69. float SpineTransformConstraintData::get_mix_rotate() {
  70. SPINE_CHECK(get_spine_constraint_data(), 0)
  71. return get_spine_constraint_data()->getMixRotate();
  72. }
  73. float SpineTransformConstraintData::get_mix_x() {
  74. SPINE_CHECK(get_spine_constraint_data(), 0)
  75. return get_spine_constraint_data()->getMixX();
  76. }
  77. float SpineTransformConstraintData::get_mix_y() {
  78. SPINE_CHECK(get_spine_constraint_data(), 0)
  79. return get_spine_constraint_data()->getMixY();
  80. }
  81. float SpineTransformConstraintData::get_mix_scale_x() {
  82. SPINE_CHECK(get_spine_constraint_data(), 0)
  83. return get_spine_constraint_data()->getMixScaleX();
  84. }
  85. float SpineTransformConstraintData::get_mix_scale_y() {
  86. SPINE_CHECK(get_spine_constraint_data(), 0)
  87. return get_spine_constraint_data()->getMixScaleY();
  88. }
  89. float SpineTransformConstraintData::get_mix_shear_y() {
  90. SPINE_CHECK(get_spine_constraint_data(), 0)
  91. return get_spine_constraint_data()->getMixShearY();
  92. }
  93. float SpineTransformConstraintData::get_offset_rotation() {
  94. SPINE_CHECK(get_spine_constraint_data(), 0)
  95. return get_spine_constraint_data()->getOffsetRotation();
  96. }
  97. float SpineTransformConstraintData::get_offset_x() {
  98. SPINE_CHECK(get_spine_constraint_data(), 0)
  99. return get_spine_constraint_data()->getOffsetX();
  100. }
  101. float SpineTransformConstraintData::get_offset_y() {
  102. SPINE_CHECK(get_spine_constraint_data(), 0)
  103. return get_spine_constraint_data()->getOffsetY();
  104. }
  105. float SpineTransformConstraintData::get_offset_scale_x() {
  106. SPINE_CHECK(get_spine_constraint_data(), 0)
  107. return get_spine_constraint_data()->getOffsetScaleX();
  108. }
  109. float SpineTransformConstraintData::get_offset_scale_y() {
  110. SPINE_CHECK(get_spine_constraint_data(), 0)
  111. return get_spine_constraint_data()->getOffsetScaleY();
  112. }
  113. float SpineTransformConstraintData::get_offset_shear_y() {
  114. SPINE_CHECK(get_spine_constraint_data(), 0)
  115. return get_spine_constraint_data()->getOffsetShearY();
  116. }
  117. bool SpineTransformConstraintData::is_relative() {
  118. SPINE_CHECK(get_spine_constraint_data(), false)
  119. return get_spine_constraint_data()->isRelative();
  120. }
  121. bool SpineTransformConstraintData::is_local() {
  122. SPINE_CHECK(get_spine_constraint_data(), false)
  123. return get_spine_constraint_data()->isLocal();
  124. }