skeleton_modification_2d_twoboneik.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /**************************************************************************/
  2. /* skeleton_modification_2d_twoboneik.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #include "skeleton_modification_2d_twoboneik.h"
  31. #include "scene/2d/skeleton_2d.h"
  32. #ifdef TOOLS_ENABLED
  33. #include "editor/editor_settings.h"
  34. #endif // TOOLS_ENABLED
  35. bool SkeletonModification2DTwoBoneIK::_set(const StringName &p_path, const Variant &p_value) {
  36. String path = p_path;
  37. if (path == "joint_one_bone_idx") {
  38. set_joint_one_bone_idx(p_value);
  39. } else if (path == "joint_one_bone2d_node") {
  40. set_joint_one_bone2d_node(p_value);
  41. } else if (path == "joint_two_bone_idx") {
  42. set_joint_two_bone_idx(p_value);
  43. } else if (path == "joint_two_bone2d_node") {
  44. set_joint_two_bone2d_node(p_value);
  45. }
  46. #ifdef TOOLS_ENABLED
  47. else if (path.begins_with("editor/draw_gizmo")) {
  48. set_editor_draw_gizmo(p_value);
  49. } else if (path.begins_with("editor/draw_min_max")) {
  50. set_editor_draw_min_max(p_value);
  51. }
  52. #endif // TOOLS_ENABLED
  53. else {
  54. return false;
  55. }
  56. return true;
  57. }
  58. bool SkeletonModification2DTwoBoneIK::_get(const StringName &p_path, Variant &r_ret) const {
  59. String path = p_path;
  60. if (path == "joint_one_bone_idx") {
  61. r_ret = get_joint_one_bone_idx();
  62. } else if (path == "joint_one_bone2d_node") {
  63. r_ret = get_joint_one_bone2d_node();
  64. } else if (path == "joint_two_bone_idx") {
  65. r_ret = get_joint_two_bone_idx();
  66. } else if (path == "joint_two_bone2d_node") {
  67. r_ret = get_joint_two_bone2d_node();
  68. }
  69. #ifdef TOOLS_ENABLED
  70. else if (path.begins_with("editor/draw_gizmo")) {
  71. r_ret = get_editor_draw_gizmo();
  72. } else if (path.begins_with("editor/draw_min_max")) {
  73. r_ret = get_editor_draw_min_max();
  74. }
  75. #endif // TOOLS_ENABLED
  76. else {
  77. return false;
  78. }
  79. return true;
  80. }
  81. void SkeletonModification2DTwoBoneIK::_get_property_list(List<PropertyInfo> *p_list) const {
  82. p_list->push_back(PropertyInfo(Variant::INT, "joint_one_bone_idx", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
  83. p_list->push_back(PropertyInfo(Variant::NODE_PATH, "joint_one_bone2d_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Bone2D", PROPERTY_USAGE_DEFAULT));
  84. p_list->push_back(PropertyInfo(Variant::INT, "joint_two_bone_idx", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
  85. p_list->push_back(PropertyInfo(Variant::NODE_PATH, "joint_two_bone2d_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Bone2D", PROPERTY_USAGE_DEFAULT));
  86. #ifdef TOOLS_ENABLED
  87. if (Engine::get_singleton()->is_editor_hint()) {
  88. p_list->push_back(PropertyInfo(Variant::BOOL, "editor/draw_gizmo", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
  89. p_list->push_back(PropertyInfo(Variant::BOOL, "editor/draw_min_max", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
  90. }
  91. #endif // TOOLS_ENABLED
  92. }
  93. void SkeletonModification2DTwoBoneIK::_execute(float p_delta) {
  94. ERR_FAIL_COND_MSG(!stack || !is_setup || stack->skeleton == nullptr,
  95. "Modification is not setup and therefore cannot execute!");
  96. if (!enabled) {
  97. return;
  98. }
  99. if (target_node_cache.is_null()) {
  100. WARN_PRINT_ONCE("Target cache is out of date. Attempting to update...");
  101. update_target_cache();
  102. return;
  103. }
  104. if (joint_one_bone2d_node_cache.is_null() && !joint_one_bone2d_node.is_empty()) {
  105. WARN_PRINT_ONCE("Joint one Bone2D node cache is out of date. Attempting to update...");
  106. update_joint_one_bone2d_cache();
  107. }
  108. if (joint_two_bone2d_node_cache.is_null() && !joint_two_bone2d_node.is_empty()) {
  109. WARN_PRINT_ONCE("Joint two Bone2D node cache is out of date. Attempting to update...");
  110. update_joint_two_bone2d_cache();
  111. }
  112. Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
  113. if (!target || !target->is_inside_tree()) {
  114. ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
  115. return;
  116. }
  117. Bone2D *joint_one_bone = stack->skeleton->get_bone(joint_one_bone_idx);
  118. if (joint_one_bone == nullptr) {
  119. ERR_PRINT_ONCE("Joint one bone_idx does not point to a valid bone! Cannot execute modification!");
  120. return;
  121. }
  122. Bone2D *joint_two_bone = stack->skeleton->get_bone(joint_two_bone_idx);
  123. if (joint_two_bone == nullptr) {
  124. ERR_PRINT_ONCE("Joint two bone_idx does not point to a valid bone! Cannot execute modification!");
  125. return;
  126. }
  127. // Adopted from the links below:
  128. // http://theorangeduck.com/page/simple-two-joint
  129. // https://www.alanzucconi.com/2018/05/02/ik-2d-2/
  130. // With modifications by TwistedTwigleg
  131. Vector2 target_difference = target->get_global_position() - joint_one_bone->get_global_position();
  132. float joint_one_to_target = target_difference.length();
  133. float angle_atan = target_difference.angle();
  134. float bone_one_length = joint_one_bone->get_length() * MIN(joint_one_bone->get_global_scale().x, joint_one_bone->get_global_scale().y);
  135. float bone_two_length = joint_two_bone->get_length() * MIN(joint_two_bone->get_global_scale().x, joint_two_bone->get_global_scale().y);
  136. bool override_angles_due_to_out_of_range = false;
  137. if (joint_one_to_target < target_minimum_distance) {
  138. joint_one_to_target = target_minimum_distance;
  139. }
  140. if (joint_one_to_target > target_maximum_distance && target_maximum_distance > 0.0) {
  141. joint_one_to_target = target_maximum_distance;
  142. }
  143. if (bone_one_length + bone_two_length < joint_one_to_target) {
  144. override_angles_due_to_out_of_range = true;
  145. }
  146. if (!override_angles_due_to_out_of_range) {
  147. float angle_0 = Math::acos(((joint_one_to_target * joint_one_to_target) + (bone_one_length * bone_one_length) - (bone_two_length * bone_two_length)) / (2.0 * joint_one_to_target * bone_one_length));
  148. float angle_1 = Math::acos(((bone_two_length * bone_two_length) + (bone_one_length * bone_one_length) - (joint_one_to_target * joint_one_to_target)) / (2.0 * bone_two_length * bone_one_length));
  149. if (flip_bend_direction) {
  150. angle_0 = -angle_0;
  151. angle_1 = -angle_1;
  152. }
  153. if (isnan(angle_0) || isnan(angle_1)) {
  154. // We cannot solve for this angle! Do nothing to avoid setting the rotation (and scale) to NaN.
  155. } else {
  156. joint_one_bone->set_global_rotation(angle_atan - angle_0 - joint_one_bone->get_bone_angle());
  157. joint_two_bone->set_rotation(-Math_PI - angle_1 - joint_two_bone->get_bone_angle() + joint_one_bone->get_bone_angle());
  158. }
  159. } else {
  160. joint_one_bone->set_global_rotation(angle_atan - joint_one_bone->get_bone_angle());
  161. joint_two_bone->set_global_rotation(angle_atan - joint_two_bone->get_bone_angle());
  162. }
  163. stack->skeleton->set_bone_local_pose_override(joint_one_bone_idx, joint_one_bone->get_transform(), stack->strength, true);
  164. stack->skeleton->set_bone_local_pose_override(joint_two_bone_idx, joint_two_bone->get_transform(), stack->strength, true);
  165. }
  166. void SkeletonModification2DTwoBoneIK::_setup_modification(SkeletonModificationStack2D *p_stack) {
  167. stack = p_stack;
  168. if (stack) {
  169. is_setup = true;
  170. update_target_cache();
  171. update_joint_one_bone2d_cache();
  172. update_joint_two_bone2d_cache();
  173. }
  174. }
  175. void SkeletonModification2DTwoBoneIK::_draw_editor_gizmo() {
  176. if (!enabled || !is_setup) {
  177. return;
  178. }
  179. Bone2D *operation_bone_one = stack->skeleton->get_bone(joint_one_bone_idx);
  180. if (!operation_bone_one) {
  181. return;
  182. }
  183. stack->skeleton->draw_set_transform(
  184. stack->skeleton->to_local(operation_bone_one->get_global_position()),
  185. operation_bone_one->get_global_rotation() - stack->skeleton->get_global_rotation());
  186. Color bone_ik_color = Color(1.0, 0.65, 0.0, 0.4);
  187. #ifdef TOOLS_ENABLED
  188. if (Engine::get_singleton()->is_editor_hint()) {
  189. bone_ik_color = EDITOR_GET("editors/2d/bone_ik_color");
  190. }
  191. #endif // TOOLS_ENABLED
  192. if (flip_bend_direction) {
  193. float angle = -(Math_PI * 0.5) + operation_bone_one->get_bone_angle();
  194. stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0);
  195. } else {
  196. float angle = (Math_PI * 0.5) + operation_bone_one->get_bone_angle();
  197. stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0);
  198. }
  199. #ifdef TOOLS_ENABLED
  200. if (Engine::get_singleton()->is_editor_hint()) {
  201. if (editor_draw_min_max) {
  202. if (target_maximum_distance != 0.0 || target_minimum_distance != 0.0) {
  203. Vector2 target_direction = Vector2(0, 1);
  204. if (target_node_cache.is_valid()) {
  205. stack->skeleton->draw_set_transform(Vector2(0, 0), 0.0);
  206. Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
  207. target_direction = operation_bone_one->get_global_position().direction_to(target->get_global_position());
  208. }
  209. stack->skeleton->draw_circle(target_direction * target_minimum_distance, 8, bone_ik_color);
  210. stack->skeleton->draw_circle(target_direction * target_maximum_distance, 8, bone_ik_color);
  211. stack->skeleton->draw_line(target_direction * target_minimum_distance, target_direction * target_maximum_distance, bone_ik_color, 2.0);
  212. }
  213. }
  214. }
  215. #endif // TOOLS_ENABLED
  216. }
  217. void SkeletonModification2DTwoBoneIK::update_target_cache() {
  218. if (!is_setup || !stack) {
  219. if (is_setup) {
  220. ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
  221. }
  222. return;
  223. }
  224. target_node_cache = ObjectID();
  225. if (stack->skeleton) {
  226. if (stack->skeleton->is_inside_tree()) {
  227. if (stack->skeleton->has_node(target_node)) {
  228. Node *node = stack->skeleton->get_node(target_node);
  229. ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
  230. "Cannot update target cache: node is this modification's skeleton or cannot be found!");
  231. ERR_FAIL_COND_MSG(!node->is_inside_tree(),
  232. "Cannot update target cache: node is not in the scene tree!");
  233. target_node_cache = node->get_instance_id();
  234. }
  235. }
  236. }
  237. }
  238. void SkeletonModification2DTwoBoneIK::update_joint_one_bone2d_cache() {
  239. if (!is_setup || !stack) {
  240. if (is_setup) {
  241. ERR_PRINT_ONCE("Cannot update joint one Bone2D cache: modification is not properly setup!");
  242. }
  243. return;
  244. }
  245. joint_one_bone2d_node_cache = ObjectID();
  246. if (stack->skeleton) {
  247. if (stack->skeleton->is_inside_tree()) {
  248. if (stack->skeleton->has_node(joint_one_bone2d_node)) {
  249. Node *node = stack->skeleton->get_node(joint_one_bone2d_node);
  250. ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
  251. "Cannot update joint one Bone2D cache: node is this modification's skeleton or cannot be found!");
  252. ERR_FAIL_COND_MSG(!node->is_inside_tree(),
  253. "Cannot update joint one Bone2D cache: node is not in the scene tree!");
  254. joint_one_bone2d_node_cache = node->get_instance_id();
  255. Bone2D *bone = Object::cast_to<Bone2D>(node);
  256. if (bone) {
  257. joint_one_bone_idx = bone->get_index_in_skeleton();
  258. } else {
  259. ERR_FAIL_MSG("Update joint one Bone2D cache: Nodepath to Bone2D is not a Bone2D node!");
  260. }
  261. }
  262. }
  263. }
  264. }
  265. void SkeletonModification2DTwoBoneIK::update_joint_two_bone2d_cache() {
  266. if (!is_setup || !stack) {
  267. if (is_setup) {
  268. ERR_PRINT_ONCE("Cannot update joint two Bone2D cache: modification is not properly setup!");
  269. }
  270. return;
  271. }
  272. joint_two_bone2d_node_cache = ObjectID();
  273. if (stack->skeleton) {
  274. if (stack->skeleton->is_inside_tree()) {
  275. if (stack->skeleton->has_node(joint_two_bone2d_node)) {
  276. Node *node = stack->skeleton->get_node(joint_two_bone2d_node);
  277. ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
  278. "Cannot update joint two Bone2D cache: node is this modification's skeleton or cannot be found!");
  279. ERR_FAIL_COND_MSG(!node->is_inside_tree(),
  280. "Cannot update joint two Bone2D cache: node is not in scene tree!");
  281. joint_two_bone2d_node_cache = node->get_instance_id();
  282. Bone2D *bone = Object::cast_to<Bone2D>(node);
  283. if (bone) {
  284. joint_two_bone_idx = bone->get_index_in_skeleton();
  285. } else {
  286. ERR_FAIL_MSG("Update joint two Bone2D cache: Nodepath to Bone2D is not a Bone2D node!");
  287. }
  288. }
  289. }
  290. }
  291. }
  292. void SkeletonModification2DTwoBoneIK::set_target_node(const NodePath &p_target_node) {
  293. target_node = p_target_node;
  294. update_target_cache();
  295. }
  296. NodePath SkeletonModification2DTwoBoneIK::get_target_node() const {
  297. return target_node;
  298. }
  299. void SkeletonModification2DTwoBoneIK::set_joint_one_bone2d_node(const NodePath &p_target_node) {
  300. joint_one_bone2d_node = p_target_node;
  301. update_joint_one_bone2d_cache();
  302. notify_property_list_changed();
  303. }
  304. void SkeletonModification2DTwoBoneIK::set_target_minimum_distance(float p_distance) {
  305. ERR_FAIL_COND_MSG(p_distance < 0, "Target minimum distance cannot be less than zero!");
  306. target_minimum_distance = p_distance;
  307. }
  308. float SkeletonModification2DTwoBoneIK::get_target_minimum_distance() const {
  309. return target_minimum_distance;
  310. }
  311. void SkeletonModification2DTwoBoneIK::set_target_maximum_distance(float p_distance) {
  312. ERR_FAIL_COND_MSG(p_distance < 0, "Target maximum distance cannot be less than zero!");
  313. target_maximum_distance = p_distance;
  314. }
  315. float SkeletonModification2DTwoBoneIK::get_target_maximum_distance() const {
  316. return target_maximum_distance;
  317. }
  318. void SkeletonModification2DTwoBoneIK::set_flip_bend_direction(bool p_flip_direction) {
  319. flip_bend_direction = p_flip_direction;
  320. #ifdef TOOLS_ENABLED
  321. if (stack && is_setup) {
  322. stack->set_editor_gizmos_dirty(true);
  323. }
  324. #endif // TOOLS_ENABLED
  325. }
  326. bool SkeletonModification2DTwoBoneIK::get_flip_bend_direction() const {
  327. return flip_bend_direction;
  328. }
  329. NodePath SkeletonModification2DTwoBoneIK::get_joint_one_bone2d_node() const {
  330. return joint_one_bone2d_node;
  331. }
  332. void SkeletonModification2DTwoBoneIK::set_joint_two_bone2d_node(const NodePath &p_target_node) {
  333. joint_two_bone2d_node = p_target_node;
  334. update_joint_two_bone2d_cache();
  335. notify_property_list_changed();
  336. }
  337. NodePath SkeletonModification2DTwoBoneIK::get_joint_two_bone2d_node() const {
  338. return joint_two_bone2d_node;
  339. }
  340. void SkeletonModification2DTwoBoneIK::set_joint_one_bone_idx(int p_bone_idx) {
  341. ERR_FAIL_COND_MSG(p_bone_idx < 0, "Bone index is out of range: The index is too low!");
  342. if (is_setup) {
  343. if (stack->skeleton) {
  344. ERR_FAIL_INDEX_MSG(p_bone_idx, stack->skeleton->get_bone_count(), "Passed-in Bone index is out of range!");
  345. joint_one_bone_idx = p_bone_idx;
  346. joint_one_bone2d_node_cache = stack->skeleton->get_bone(p_bone_idx)->get_instance_id();
  347. joint_one_bone2d_node = stack->skeleton->get_path_to(stack->skeleton->get_bone(p_bone_idx));
  348. } else {
  349. WARN_PRINT("TwoBoneIK: Cannot verify the joint bone index for joint one...");
  350. joint_one_bone_idx = p_bone_idx;
  351. }
  352. } else {
  353. joint_one_bone_idx = p_bone_idx;
  354. }
  355. notify_property_list_changed();
  356. }
  357. int SkeletonModification2DTwoBoneIK::get_joint_one_bone_idx() const {
  358. return joint_one_bone_idx;
  359. }
  360. void SkeletonModification2DTwoBoneIK::set_joint_two_bone_idx(int p_bone_idx) {
  361. ERR_FAIL_COND_MSG(p_bone_idx < 0, "Bone index is out of range: The index is too low!");
  362. if (is_setup) {
  363. if (stack->skeleton) {
  364. ERR_FAIL_INDEX_MSG(p_bone_idx, stack->skeleton->get_bone_count(), "Passed-in Bone index is out of range!");
  365. joint_two_bone_idx = p_bone_idx;
  366. joint_two_bone2d_node_cache = stack->skeleton->get_bone(p_bone_idx)->get_instance_id();
  367. joint_two_bone2d_node = stack->skeleton->get_path_to(stack->skeleton->get_bone(p_bone_idx));
  368. } else {
  369. WARN_PRINT("TwoBoneIK: Cannot verify the joint bone index for joint two...");
  370. joint_two_bone_idx = p_bone_idx;
  371. }
  372. } else {
  373. joint_two_bone_idx = p_bone_idx;
  374. }
  375. notify_property_list_changed();
  376. }
  377. int SkeletonModification2DTwoBoneIK::get_joint_two_bone_idx() const {
  378. return joint_two_bone_idx;
  379. }
  380. #ifdef TOOLS_ENABLED
  381. void SkeletonModification2DTwoBoneIK::set_editor_draw_min_max(bool p_draw) {
  382. editor_draw_min_max = p_draw;
  383. }
  384. bool SkeletonModification2DTwoBoneIK::get_editor_draw_min_max() const {
  385. return editor_draw_min_max;
  386. }
  387. #endif // TOOLS_ENABLED
  388. void SkeletonModification2DTwoBoneIK::_bind_methods() {
  389. ClassDB::bind_method(D_METHOD("set_target_node", "target_nodepath"), &SkeletonModification2DTwoBoneIK::set_target_node);
  390. ClassDB::bind_method(D_METHOD("get_target_node"), &SkeletonModification2DTwoBoneIK::get_target_node);
  391. ClassDB::bind_method(D_METHOD("set_target_minimum_distance", "minimum_distance"), &SkeletonModification2DTwoBoneIK::set_target_minimum_distance);
  392. ClassDB::bind_method(D_METHOD("get_target_minimum_distance"), &SkeletonModification2DTwoBoneIK::get_target_minimum_distance);
  393. ClassDB::bind_method(D_METHOD("set_target_maximum_distance", "maximum_distance"), &SkeletonModification2DTwoBoneIK::set_target_maximum_distance);
  394. ClassDB::bind_method(D_METHOD("get_target_maximum_distance"), &SkeletonModification2DTwoBoneIK::get_target_maximum_distance);
  395. ClassDB::bind_method(D_METHOD("set_flip_bend_direction", "flip_direction"), &SkeletonModification2DTwoBoneIK::set_flip_bend_direction);
  396. ClassDB::bind_method(D_METHOD("get_flip_bend_direction"), &SkeletonModification2DTwoBoneIK::get_flip_bend_direction);
  397. ClassDB::bind_method(D_METHOD("set_joint_one_bone2d_node", "bone2d_node"), &SkeletonModification2DTwoBoneIK::set_joint_one_bone2d_node);
  398. ClassDB::bind_method(D_METHOD("get_joint_one_bone2d_node"), &SkeletonModification2DTwoBoneIK::get_joint_one_bone2d_node);
  399. ClassDB::bind_method(D_METHOD("set_joint_one_bone_idx", "bone_idx"), &SkeletonModification2DTwoBoneIK::set_joint_one_bone_idx);
  400. ClassDB::bind_method(D_METHOD("get_joint_one_bone_idx"), &SkeletonModification2DTwoBoneIK::get_joint_one_bone_idx);
  401. ClassDB::bind_method(D_METHOD("set_joint_two_bone2d_node", "bone2d_node"), &SkeletonModification2DTwoBoneIK::set_joint_two_bone2d_node);
  402. ClassDB::bind_method(D_METHOD("get_joint_two_bone2d_node"), &SkeletonModification2DTwoBoneIK::get_joint_two_bone2d_node);
  403. ClassDB::bind_method(D_METHOD("set_joint_two_bone_idx", "bone_idx"), &SkeletonModification2DTwoBoneIK::set_joint_two_bone_idx);
  404. ClassDB::bind_method(D_METHOD("get_joint_two_bone_idx"), &SkeletonModification2DTwoBoneIK::get_joint_two_bone_idx);
  405. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target_nodepath", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node2D"), "set_target_node", "get_target_node");
  406. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "target_minimum_distance", PROPERTY_HINT_RANGE, "0,100000000,0.01,suffix:px"), "set_target_minimum_distance", "get_target_minimum_distance");
  407. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "target_maximum_distance", PROPERTY_HINT_NONE, "0,100000000,0.01,suffix:px"), "set_target_maximum_distance", "get_target_maximum_distance");
  408. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_bend_direction", PROPERTY_HINT_NONE, ""), "set_flip_bend_direction", "get_flip_bend_direction");
  409. ADD_GROUP("", "");
  410. }
  411. SkeletonModification2DTwoBoneIK::SkeletonModification2DTwoBoneIK() {
  412. stack = nullptr;
  413. is_setup = false;
  414. enabled = true;
  415. editor_draw_gizmo = true;
  416. }
  417. SkeletonModification2DTwoBoneIK::~SkeletonModification2DTwoBoneIK() {
  418. }