skeleton_modification_2d_fabrik.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /*************************************************************************/
  2. /* skeleton_modification_2d_fabrik.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_fabrik.h"
  31. #include "scene/2d/skeleton_2d.h"
  32. #ifdef TOOLS_ENABLED
  33. #include "editor/editor_settings.h"
  34. #endif // TOOLS_ENABLED
  35. bool SkeletonModification2DFABRIK::_set(const StringName &p_path, const Variant &p_value) {
  36. String path = p_path;
  37. if (path.begins_with("joint_data/")) {
  38. int which = path.get_slicec('/', 1).to_int();
  39. String what = path.get_slicec('/', 2);
  40. ERR_FAIL_INDEX_V(which, fabrik_data_chain.size(), false);
  41. if (what == "bone2d_node") {
  42. set_fabrik_joint_bone2d_node(which, p_value);
  43. } else if (what == "bone_index") {
  44. set_fabrik_joint_bone_index(which, p_value);
  45. } else if (what == "magnet_position") {
  46. set_fabrik_joint_magnet_position(which, p_value);
  47. } else if (what == "use_target_rotation") {
  48. set_fabrik_joint_use_target_rotation(which, p_value);
  49. }
  50. }
  51. return true;
  52. }
  53. bool SkeletonModification2DFABRIK::_get(const StringName &p_path, Variant &r_ret) const {
  54. String path = p_path;
  55. if (path.begins_with("joint_data/")) {
  56. int which = path.get_slicec('/', 1).to_int();
  57. String what = path.get_slicec('/', 2);
  58. ERR_FAIL_INDEX_V(which, fabrik_data_chain.size(), false);
  59. if (what == "bone2d_node") {
  60. r_ret = get_fabrik_joint_bone2d_node(which);
  61. } else if (what == "bone_index") {
  62. r_ret = get_fabrik_joint_bone_index(which);
  63. } else if (what == "magnet_position") {
  64. r_ret = get_fabrik_joint_magnet_position(which);
  65. } else if (what == "use_target_rotation") {
  66. r_ret = get_fabrik_joint_use_target_rotation(which);
  67. }
  68. return true;
  69. }
  70. return true;
  71. }
  72. void SkeletonModification2DFABRIK::_get_property_list(List<PropertyInfo> *p_list) const {
  73. for (int i = 0; i < fabrik_data_chain.size(); i++) {
  74. String base_string = "joint_data/" + itos(i) + "/";
  75. p_list->push_back(PropertyInfo(Variant::INT, base_string + "bone_index", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
  76. p_list->push_back(PropertyInfo(Variant::NODE_PATH, base_string + "bone2d_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Bone2D", PROPERTY_USAGE_DEFAULT));
  77. if (i > 0) {
  78. p_list->push_back(PropertyInfo(Variant::VECTOR2, base_string + "magnet_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
  79. }
  80. if (i == fabrik_data_chain.size() - 1) {
  81. p_list->push_back(PropertyInfo(Variant::BOOL, base_string + "use_target_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT));
  82. }
  83. }
  84. }
  85. void SkeletonModification2DFABRIK::_execute(float p_delta) {
  86. ERR_FAIL_COND_MSG(!stack || !is_setup || stack->skeleton == nullptr,
  87. "Modification is not setup and therefore cannot execute!");
  88. if (!enabled) {
  89. return;
  90. }
  91. if (target_node_cache.is_null()) {
  92. WARN_PRINT_ONCE("Target cache is out of date. Attempting to update...");
  93. update_target_cache();
  94. return;
  95. }
  96. if (fabrik_data_chain.size() <= 1) {
  97. ERR_PRINT_ONCE("FABRIK requires at least two joints to operate! Cannot execute modification!");
  98. return;
  99. }
  100. Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
  101. if (!target || !target->is_inside_tree()) {
  102. ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
  103. return;
  104. }
  105. target_global_pose = target->get_global_transform();
  106. if (fabrik_data_chain[0].bone2d_node_cache.is_null() && !fabrik_data_chain[0].bone2d_node.is_empty()) {
  107. fabrik_joint_update_bone2d_cache(0);
  108. WARN_PRINT("Bone2D cache for origin joint is out of date. Updating...");
  109. }
  110. Bone2D *origin_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[0].bone2d_node_cache));
  111. if (!origin_bone2d_node || !origin_bone2d_node->is_inside_tree()) {
  112. ERR_PRINT_ONCE("Origin joint's Bone2D node is not in the scene tree. Cannot execute modification!");
  113. return;
  114. }
  115. origin_global_pose = origin_bone2d_node->get_global_transform();
  116. if (fabrik_transform_chain.size() != fabrik_data_chain.size()) {
  117. fabrik_transform_chain.resize(fabrik_data_chain.size());
  118. }
  119. for (int i = 0; i < fabrik_data_chain.size(); i++) {
  120. // Update the transform chain
  121. if (fabrik_data_chain[i].bone2d_node_cache.is_null() && !fabrik_data_chain[i].bone2d_node.is_empty()) {
  122. WARN_PRINT_ONCE("Bone2D cache for joint " + itos(i) + " is out of date.. Attempting to update...");
  123. fabrik_joint_update_bone2d_cache(i);
  124. }
  125. Bone2D *joint_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
  126. if (!joint_bone2d_node) {
  127. ERR_PRINT_ONCE("FABRIK Joint " + itos(i) + " does not have a Bone2D node set! Cannot execute modification!");
  128. return;
  129. }
  130. fabrik_transform_chain.write[i] = joint_bone2d_node->get_global_transform();
  131. }
  132. Bone2D *final_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[fabrik_data_chain.size() - 1].bone2d_node_cache));
  133. float final_bone2d_angle = final_bone2d_node->get_global_rotation();
  134. if (fabrik_data_chain[fabrik_data_chain.size() - 1].use_target_rotation) {
  135. final_bone2d_angle = target_global_pose.get_rotation();
  136. }
  137. Vector2 final_bone2d_direction = Vector2(Math::cos(final_bone2d_angle), Math::sin(final_bone2d_angle));
  138. float final_bone2d_length = final_bone2d_node->get_length() * MIN(final_bone2d_node->get_global_scale().x, final_bone2d_node->get_global_scale().y);
  139. float target_distance = (final_bone2d_node->get_global_position() + (final_bone2d_direction * final_bone2d_length)).distance_to(target->get_global_position());
  140. chain_iterations = 0;
  141. while (target_distance > chain_tolarance) {
  142. chain_backwards();
  143. chain_forwards();
  144. final_bone2d_angle = final_bone2d_node->get_global_rotation();
  145. if (fabrik_data_chain[fabrik_data_chain.size() - 1].use_target_rotation) {
  146. final_bone2d_angle = target_global_pose.get_rotation();
  147. }
  148. final_bone2d_direction = Vector2(Math::cos(final_bone2d_angle), Math::sin(final_bone2d_angle));
  149. target_distance = (final_bone2d_node->get_global_position() + (final_bone2d_direction * final_bone2d_length)).distance_to(target->get_global_position());
  150. chain_iterations += 1;
  151. if (chain_iterations >= chain_max_iterations) {
  152. break;
  153. }
  154. }
  155. // Apply all of the saved transforms to the Bone2D nodes
  156. for (int i = 0; i < fabrik_data_chain.size(); i++) {
  157. Bone2D *joint_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
  158. if (!joint_bone2d_node) {
  159. ERR_PRINT_ONCE("FABRIK Joint " + itos(i) + " does not have a Bone2D node set!");
  160. continue;
  161. }
  162. Transform2D chain_trans = fabrik_transform_chain[i];
  163. // Apply rotation
  164. if (i + 1 < fabrik_data_chain.size()) {
  165. chain_trans = chain_trans.looking_at(fabrik_transform_chain[i + 1].get_origin());
  166. } else {
  167. if (fabrik_data_chain[i].use_target_rotation) {
  168. chain_trans.set_rotation(target_global_pose.get_rotation());
  169. } else {
  170. chain_trans = chain_trans.looking_at(target_global_pose.get_origin());
  171. }
  172. }
  173. // Adjust for the bone angle
  174. chain_trans.set_rotation(chain_trans.get_rotation() - joint_bone2d_node->get_bone_angle());
  175. // Reset scale
  176. chain_trans.set_scale(joint_bone2d_node->get_global_scale());
  177. // Apply to the bone, and to the override
  178. joint_bone2d_node->set_global_transform(chain_trans);
  179. stack->skeleton->set_bone_local_pose_override(fabrik_data_chain[i].bone_idx, joint_bone2d_node->get_transform(), stack->strength, true);
  180. }
  181. }
  182. void SkeletonModification2DFABRIK::chain_backwards() {
  183. int final_joint_index = fabrik_data_chain.size() - 1;
  184. Bone2D *final_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[final_joint_index].bone2d_node_cache));
  185. Transform2D final_bone2d_trans = fabrik_transform_chain[final_joint_index];
  186. // Apply magnet position
  187. if (final_joint_index != 0) {
  188. final_bone2d_trans.set_origin(final_bone2d_trans.get_origin() + fabrik_data_chain[final_joint_index].magnet_position);
  189. }
  190. // Set the rotation of the tip bone
  191. final_bone2d_trans = final_bone2d_trans.looking_at(target_global_pose.get_origin());
  192. // Set the position of the tip bone
  193. float final_bone2d_angle = final_bone2d_trans.get_rotation();
  194. if (fabrik_data_chain[final_joint_index].use_target_rotation) {
  195. final_bone2d_angle = target_global_pose.get_rotation();
  196. }
  197. Vector2 final_bone2d_direction = Vector2(Math::cos(final_bone2d_angle), Math::sin(final_bone2d_angle));
  198. float final_bone2d_length = final_bone2d_node->get_length() * MIN(final_bone2d_node->get_global_scale().x, final_bone2d_node->get_global_scale().y);
  199. final_bone2d_trans.set_origin(target_global_pose.get_origin() - (final_bone2d_direction * final_bone2d_length));
  200. // Save the transform
  201. fabrik_transform_chain.write[final_joint_index] = final_bone2d_trans;
  202. int i = final_joint_index;
  203. while (i >= 1) {
  204. Transform2D previous_pose = fabrik_transform_chain[i];
  205. i -= 1;
  206. Bone2D *current_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
  207. Transform2D current_pose = fabrik_transform_chain[i];
  208. // Apply magnet position
  209. if (i != 0) {
  210. current_pose.set_origin(current_pose.get_origin() + fabrik_data_chain[i].magnet_position);
  211. }
  212. float current_bone2d_node_length = current_bone2d_node->get_length() * MIN(current_bone2d_node->get_global_scale().x, current_bone2d_node->get_global_scale().y);
  213. float length = current_bone2d_node_length / (current_pose.get_origin().distance_to(previous_pose.get_origin()));
  214. Vector2 finish_position = previous_pose.get_origin().lerp(current_pose.get_origin(), length);
  215. current_pose.set_origin(finish_position);
  216. // Save the transform
  217. fabrik_transform_chain.write[i] = current_pose;
  218. }
  219. }
  220. void SkeletonModification2DFABRIK::chain_forwards() {
  221. Transform2D origin_bone2d_trans = fabrik_transform_chain[0];
  222. origin_bone2d_trans.set_origin(origin_global_pose.get_origin());
  223. // Save the position
  224. fabrik_transform_chain.write[0] = origin_bone2d_trans;
  225. for (int i = 0; i < fabrik_data_chain.size() - 1; i++) {
  226. Bone2D *current_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
  227. Transform2D current_pose = fabrik_transform_chain[i];
  228. Transform2D next_pose = fabrik_transform_chain[i + 1];
  229. float current_bone2d_node_length = current_bone2d_node->get_length() * MIN(current_bone2d_node->get_global_scale().x, current_bone2d_node->get_global_scale().y);
  230. float length = current_bone2d_node_length / (next_pose.get_origin().distance_to(current_pose.get_origin()));
  231. Vector2 finish_position = current_pose.get_origin().lerp(next_pose.get_origin(), length);
  232. current_pose.set_origin(finish_position);
  233. // Apply to the bone
  234. fabrik_transform_chain.write[i + 1] = current_pose;
  235. }
  236. }
  237. void SkeletonModification2DFABRIK::_setup_modification(SkeletonModificationStack2D *p_stack) {
  238. stack = p_stack;
  239. if (stack != nullptr) {
  240. is_setup = true;
  241. update_target_cache();
  242. }
  243. }
  244. void SkeletonModification2DFABRIK::update_target_cache() {
  245. if (!is_setup || !stack) {
  246. ERR_PRINT_ONCE("Cannot update target cache: modification is not properly setup!");
  247. return;
  248. }
  249. target_node_cache = ObjectID();
  250. if (stack->skeleton) {
  251. if (stack->skeleton->is_inside_tree()) {
  252. if (stack->skeleton->has_node(target_node)) {
  253. Node *node = stack->skeleton->get_node(target_node);
  254. ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
  255. "Cannot update target cache: node is this modification's skeleton or cannot be found!");
  256. ERR_FAIL_COND_MSG(!node->is_inside_tree(),
  257. "Cannot update target cache: node is not in scene tree!");
  258. target_node_cache = node->get_instance_id();
  259. }
  260. }
  261. }
  262. }
  263. void SkeletonModification2DFABRIK::fabrik_joint_update_bone2d_cache(int p_joint_idx) {
  264. ERR_FAIL_INDEX_MSG(p_joint_idx, fabrik_data_chain.size(), "Cannot update bone2d cache: joint index out of range!");
  265. if (!is_setup || !stack) {
  266. ERR_PRINT_ONCE("Cannot update FABRIK Bone2D cache: modification is not properly setup!");
  267. return;
  268. }
  269. fabrik_data_chain.write[p_joint_idx].bone2d_node_cache = ObjectID();
  270. if (stack->skeleton) {
  271. if (stack->skeleton->is_inside_tree()) {
  272. if (stack->skeleton->has_node(fabrik_data_chain[p_joint_idx].bone2d_node)) {
  273. Node *node = stack->skeleton->get_node(fabrik_data_chain[p_joint_idx].bone2d_node);
  274. ERR_FAIL_COND_MSG(!node || stack->skeleton == node,
  275. "Cannot update FABRIK joint " + itos(p_joint_idx) + " Bone2D cache: node is this modification's skeleton or cannot be found!");
  276. ERR_FAIL_COND_MSG(!node->is_inside_tree(),
  277. "Cannot update FABRIK joint " + itos(p_joint_idx) + " Bone2D cache: node is not in scene tree!");
  278. fabrik_data_chain.write[p_joint_idx].bone2d_node_cache = node->get_instance_id();
  279. Bone2D *bone = Object::cast_to<Bone2D>(node);
  280. if (bone) {
  281. fabrik_data_chain.write[p_joint_idx].bone_idx = bone->get_index_in_skeleton();
  282. } else {
  283. ERR_FAIL_MSG("FABRIK joint " + itos(p_joint_idx) + " Bone2D cache: Nodepath to Bone2D is not a Bone2D node!");
  284. }
  285. }
  286. }
  287. }
  288. }
  289. void SkeletonModification2DFABRIK::set_target_node(const NodePath &p_target_node) {
  290. target_node = p_target_node;
  291. update_target_cache();
  292. }
  293. NodePath SkeletonModification2DFABRIK::get_target_node() const {
  294. return target_node;
  295. }
  296. void SkeletonModification2DFABRIK::set_fabrik_data_chain_length(int p_length) {
  297. fabrik_data_chain.resize(p_length);
  298. notify_property_list_changed();
  299. }
  300. int SkeletonModification2DFABRIK::get_fabrik_data_chain_length() {
  301. return fabrik_data_chain.size();
  302. }
  303. void SkeletonModification2DFABRIK::set_fabrik_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node) {
  304. ERR_FAIL_INDEX_MSG(p_joint_idx, fabrik_data_chain.size(), "FABRIK joint out of range!");
  305. fabrik_data_chain.write[p_joint_idx].bone2d_node = p_target_node;
  306. fabrik_joint_update_bone2d_cache(p_joint_idx);
  307. notify_property_list_changed();
  308. }
  309. NodePath SkeletonModification2DFABRIK::get_fabrik_joint_bone2d_node(int p_joint_idx) const {
  310. ERR_FAIL_INDEX_V_MSG(p_joint_idx, fabrik_data_chain.size(), NodePath(), "FABRIK joint out of range!");
  311. return fabrik_data_chain[p_joint_idx].bone2d_node;
  312. }
  313. void SkeletonModification2DFABRIK::set_fabrik_joint_bone_index(int p_joint_idx, int p_bone_idx) {
  314. ERR_FAIL_INDEX_MSG(p_joint_idx, fabrik_data_chain.size(), "FABRIK joint out of range!");
  315. ERR_FAIL_COND_MSG(p_bone_idx < 0, "Bone index is out of range: The index is too low!");
  316. if (is_setup) {
  317. if (stack->skeleton) {
  318. ERR_FAIL_INDEX_MSG(p_bone_idx, stack->skeleton->get_bone_count(), "Passed-in Bone index is out of range!");
  319. fabrik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
  320. fabrik_data_chain.write[p_joint_idx].bone2d_node_cache = stack->skeleton->get_bone(p_bone_idx)->get_instance_id();
  321. fabrik_data_chain.write[p_joint_idx].bone2d_node = stack->skeleton->get_path_to(stack->skeleton->get_bone(p_bone_idx));
  322. } else {
  323. WARN_PRINT("Cannot verify the FABRIK joint " + itos(p_joint_idx) + " bone index for this modification...");
  324. fabrik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
  325. }
  326. } else {
  327. WARN_PRINT("Cannot verify the FABRIK joint " + itos(p_joint_idx) + " bone index for this modification...");
  328. fabrik_data_chain.write[p_joint_idx].bone_idx = p_bone_idx;
  329. }
  330. notify_property_list_changed();
  331. }
  332. int SkeletonModification2DFABRIK::get_fabrik_joint_bone_index(int p_joint_idx) const {
  333. ERR_FAIL_INDEX_V_MSG(p_joint_idx, fabrik_data_chain.size(), -1, "FABRIK joint out of range!");
  334. return fabrik_data_chain[p_joint_idx].bone_idx;
  335. }
  336. void SkeletonModification2DFABRIK::set_fabrik_joint_magnet_position(int p_joint_idx, Vector2 p_magnet_position) {
  337. ERR_FAIL_INDEX_MSG(p_joint_idx, fabrik_data_chain.size(), "FABRIK joint out of range!");
  338. fabrik_data_chain.write[p_joint_idx].magnet_position = p_magnet_position;
  339. }
  340. Vector2 SkeletonModification2DFABRIK::get_fabrik_joint_magnet_position(int p_joint_idx) const {
  341. ERR_FAIL_INDEX_V_MSG(p_joint_idx, fabrik_data_chain.size(), Vector2(), "FABRIK joint out of range!");
  342. return fabrik_data_chain[p_joint_idx].magnet_position;
  343. }
  344. void SkeletonModification2DFABRIK::set_fabrik_joint_use_target_rotation(int p_joint_idx, bool p_use_target_rotation) {
  345. ERR_FAIL_INDEX_MSG(p_joint_idx, fabrik_data_chain.size(), "FABRIK joint out of range!");
  346. fabrik_data_chain.write[p_joint_idx].use_target_rotation = p_use_target_rotation;
  347. }
  348. bool SkeletonModification2DFABRIK::get_fabrik_joint_use_target_rotation(int p_joint_idx) const {
  349. ERR_FAIL_INDEX_V_MSG(p_joint_idx, fabrik_data_chain.size(), false, "FABRIK joint out of range!");
  350. return fabrik_data_chain[p_joint_idx].use_target_rotation;
  351. }
  352. void SkeletonModification2DFABRIK::_bind_methods() {
  353. ClassDB::bind_method(D_METHOD("set_target_node", "target_nodepath"), &SkeletonModification2DFABRIK::set_target_node);
  354. ClassDB::bind_method(D_METHOD("get_target_node"), &SkeletonModification2DFABRIK::get_target_node);
  355. ClassDB::bind_method(D_METHOD("set_fabrik_data_chain_length", "length"), &SkeletonModification2DFABRIK::set_fabrik_data_chain_length);
  356. ClassDB::bind_method(D_METHOD("get_fabrik_data_chain_length"), &SkeletonModification2DFABRIK::get_fabrik_data_chain_length);
  357. ClassDB::bind_method(D_METHOD("set_fabrik_joint_bone2d_node", "joint_idx", "bone2d_nodepath"), &SkeletonModification2DFABRIK::set_fabrik_joint_bone2d_node);
  358. ClassDB::bind_method(D_METHOD("get_fabrik_joint_bone2d_node", "joint_idx"), &SkeletonModification2DFABRIK::get_fabrik_joint_bone2d_node);
  359. ClassDB::bind_method(D_METHOD("set_fabrik_joint_bone_index", "joint_idx", "bone_idx"), &SkeletonModification2DFABRIK::set_fabrik_joint_bone_index);
  360. ClassDB::bind_method(D_METHOD("get_fabrik_joint_bone_index", "joint_idx"), &SkeletonModification2DFABRIK::get_fabrik_joint_bone_index);
  361. ClassDB::bind_method(D_METHOD("set_fabrik_joint_magnet_position", "joint_idx", "magnet_position"), &SkeletonModification2DFABRIK::set_fabrik_joint_magnet_position);
  362. ClassDB::bind_method(D_METHOD("get_fabrik_joint_magnet_position", "joint_idx"), &SkeletonModification2DFABRIK::get_fabrik_joint_magnet_position);
  363. ClassDB::bind_method(D_METHOD("set_fabrik_joint_use_target_rotation", "joint_idx", "use_target_rotation"), &SkeletonModification2DFABRIK::set_fabrik_joint_use_target_rotation);
  364. ClassDB::bind_method(D_METHOD("get_fabrik_joint_use_target_rotation", "joint_idx"), &SkeletonModification2DFABRIK::get_fabrik_joint_use_target_rotation);
  365. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target_nodepath", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node2D"), "set_target_node", "get_target_node");
  366. ADD_PROPERTY(PropertyInfo(Variant::INT, "fabrik_data_chain_length", PROPERTY_HINT_RANGE, "0, 100, 1"), "set_fabrik_data_chain_length", "get_fabrik_data_chain_length");
  367. }
  368. SkeletonModification2DFABRIK::SkeletonModification2DFABRIK() {
  369. stack = nullptr;
  370. is_setup = false;
  371. enabled = true;
  372. editor_draw_gizmo = false;
  373. }
  374. SkeletonModification2DFABRIK::~SkeletonModification2DFABRIK() {
  375. }