skeleton_modification_2d_twoboneik.cpp 20 KB

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