SpineIkConstraintData.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 "SpineIkConstraintData.h"
  30. #include "SpineCommon.h"
  31. void SpineIkConstraintData::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_bones"), &SpineIkConstraintData::get_bones);
  33. ClassDB::bind_method(D_METHOD("get_target"), &SpineIkConstraintData::get_target);
  34. ClassDB::bind_method(D_METHOD("set_target", "v"), &SpineIkConstraintData::set_target);
  35. ClassDB::bind_method(D_METHOD("get_bend_direction"), &SpineIkConstraintData::get_bend_direction);
  36. ClassDB::bind_method(D_METHOD("set_bend_direction", "v"), &SpineIkConstraintData::set_bend_direction);
  37. ClassDB::bind_method(D_METHOD("get_compress"), &SpineIkConstraintData::get_compress);
  38. ClassDB::bind_method(D_METHOD("set_compress", "v"), &SpineIkConstraintData::set_compress);
  39. ClassDB::bind_method(D_METHOD("get_stretch"), &SpineIkConstraintData::get_stretch);
  40. ClassDB::bind_method(D_METHOD("set_stretch", "v"), &SpineIkConstraintData::set_stretch);
  41. ClassDB::bind_method(D_METHOD("get_uniform"), &SpineIkConstraintData::get_uniform);
  42. ClassDB::bind_method(D_METHOD("set_uniform", "v"), &SpineIkConstraintData::set_uniform);
  43. ClassDB::bind_method(D_METHOD("get_mix"), &SpineIkConstraintData::get_mix);
  44. ClassDB::bind_method(D_METHOD("set_mix", "v"), &SpineIkConstraintData::set_mix);
  45. ClassDB::bind_method(D_METHOD("get_softness"), &SpineIkConstraintData::get_softness);
  46. ClassDB::bind_method(D_METHOD("set_softness", "v"), &SpineIkConstraintData::set_softness);
  47. }
  48. Array SpineIkConstraintData::get_bones() {
  49. Array result;
  50. SPINE_CHECK(get_spine_object(), result)
  51. auto bones = get_spine_constraint_data()->getBones();
  52. result.resize((int) bones.size());
  53. for (int i = 0; i < bones.size(); ++i) {
  54. Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
  55. bone_ref->set_spine_object(get_spine_owner(), bones[i]);
  56. result[i] = bone_ref;
  57. }
  58. return result;
  59. }
  60. Ref<SpineBoneData> SpineIkConstraintData::get_target() {
  61. SPINE_CHECK(get_spine_object(), nullptr)
  62. auto target = get_spine_constraint_data()->getTarget();
  63. if (!target) return nullptr;
  64. Ref<SpineBoneData> target_ref(memnew(SpineBoneData));
  65. target_ref->set_spine_object(get_spine_owner(), target);
  66. return target_ref;
  67. }
  68. void SpineIkConstraintData::set_target(Ref<SpineBoneData> v) {
  69. SPINE_CHECK(get_spine_object(), )
  70. get_spine_constraint_data()->setTarget(v.is_valid() && v->get_spine_object() ? v->get_spine_object() : nullptr);
  71. }
  72. int SpineIkConstraintData::get_bend_direction() {
  73. SPINE_CHECK(get_spine_object(), 0)
  74. return get_spine_constraint_data()->getBendDirection();
  75. }
  76. void SpineIkConstraintData::set_bend_direction(int v) {
  77. SPINE_CHECK(get_spine_object(), )
  78. get_spine_constraint_data()->setBendDirection(v);
  79. }
  80. bool SpineIkConstraintData::get_compress() {
  81. SPINE_CHECK(get_spine_object(), false)
  82. return get_spine_constraint_data()->getCompress();
  83. }
  84. void SpineIkConstraintData::set_compress(bool v) {
  85. SPINE_CHECK(get_spine_object(), )
  86. get_spine_constraint_data()->setCompress(v);
  87. }
  88. bool SpineIkConstraintData::get_stretch() {
  89. SPINE_CHECK(get_spine_object(), false)
  90. return get_spine_constraint_data()->getStretch();
  91. }
  92. void SpineIkConstraintData::set_stretch(bool v) {
  93. SPINE_CHECK(get_spine_object(), )
  94. get_spine_constraint_data()->setStretch(v);
  95. }
  96. bool SpineIkConstraintData::get_uniform() {
  97. SPINE_CHECK(get_spine_object(), false)
  98. return get_spine_constraint_data()->getUniform();
  99. }
  100. void SpineIkConstraintData::set_uniform(bool v) {
  101. SPINE_CHECK(get_spine_object(), )
  102. get_spine_constraint_data()->setUniform(v);
  103. }
  104. float SpineIkConstraintData::get_mix() {
  105. SPINE_CHECK(get_spine_object(), 0)
  106. return get_spine_constraint_data()->getMix();
  107. }
  108. void SpineIkConstraintData::set_mix(float v) {
  109. SPINE_CHECK(get_spine_object(), )
  110. get_spine_constraint_data()->setMix(v);
  111. }
  112. float SpineIkConstraintData::get_softness() {
  113. SPINE_CHECK(get_spine_object(), 0)
  114. return get_spine_constraint_data()->getSoftness();
  115. }
  116. void SpineIkConstraintData::set_softness(float v) {
  117. SPINE_CHECK(get_spine_object(), )
  118. get_spine_constraint_data()->setSoftness(v);
  119. }