skeleton_ik_3d.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /**************************************************************************/
  2. /* skeleton_ik_3d.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_ik_3d.h"
  31. FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::find_child(const BoneId p_bone_id) {
  32. for (int i = children.size() - 1; 0 <= i; --i) {
  33. if (p_bone_id == children[i].bone) {
  34. return &children.write[i];
  35. }
  36. }
  37. return nullptr;
  38. }
  39. FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::add_child(const BoneId p_bone_id) {
  40. const int infant_child_id = children.size();
  41. children.resize(infant_child_id + 1);
  42. children.write[infant_child_id].bone = p_bone_id;
  43. children.write[infant_child_id].parent_item = this;
  44. return &children.write[infant_child_id];
  45. }
  46. /// Build a chain that starts from the root to tip
  47. bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain) {
  48. ERR_FAIL_COND_V(-1 == p_task->root_bone, false);
  49. Chain &chain(p_task->chain);
  50. chain.tips.resize(p_task->end_effectors.size());
  51. chain.chain_root.bone = p_task->root_bone;
  52. chain.chain_root.initial_transform = p_task->skeleton->get_bone_global_pose(chain.chain_root.bone);
  53. chain.chain_root.current_pos = chain.chain_root.initial_transform.origin;
  54. chain.middle_chain_item = nullptr;
  55. // Holds all IDs that are composing a single chain in reverse order
  56. Vector<BoneId> chain_ids;
  57. // This is used to know the chain size
  58. int sub_chain_size;
  59. // Resize only one time in order to fit all joints for performance reason
  60. chain_ids.resize(p_task->skeleton->get_bone_count());
  61. for (int x = p_task->end_effectors.size() - 1; 0 <= x; --x) {
  62. const EndEffector *ee(&p_task->end_effectors[x]);
  63. ERR_FAIL_COND_V(p_task->root_bone >= ee->tip_bone, false);
  64. ERR_FAIL_INDEX_V(ee->tip_bone, p_task->skeleton->get_bone_count(), false);
  65. sub_chain_size = 0;
  66. // Picks all IDs that composing a single chain in reverse order (except the root)
  67. BoneId chain_sub_tip(ee->tip_bone);
  68. while (chain_sub_tip > p_task->root_bone) {
  69. chain_ids.write[sub_chain_size++] = chain_sub_tip;
  70. chain_sub_tip = p_task->skeleton->get_bone_parent(chain_sub_tip);
  71. }
  72. BoneId middle_chain_item_id = (BoneId)(sub_chain_size * 0.5);
  73. // Build chain by reading chain ids in reverse order
  74. // For each chain item id will be created a ChainItem if doesn't exists
  75. ChainItem *sub_chain(&chain.chain_root);
  76. for (int i = sub_chain_size - 1; 0 <= i; --i) {
  77. ChainItem *child_ci(sub_chain->find_child(chain_ids[i]));
  78. if (!child_ci) {
  79. child_ci = sub_chain->add_child(chain_ids[i]);
  80. child_ci->initial_transform = p_task->skeleton->get_bone_global_pose(child_ci->bone);
  81. child_ci->current_pos = child_ci->initial_transform.origin;
  82. if (child_ci->parent_item) {
  83. child_ci->length = child_ci->parent_item->current_pos.distance_to(child_ci->current_pos);
  84. }
  85. }
  86. sub_chain = child_ci;
  87. if (middle_chain_item_id == i) {
  88. chain.middle_chain_item = child_ci;
  89. }
  90. }
  91. if (!middle_chain_item_id) {
  92. chain.middle_chain_item = nullptr;
  93. }
  94. // Initialize current tip
  95. chain.tips.write[x].chain_item = sub_chain;
  96. chain.tips.write[x].end_effector = ee;
  97. if (p_force_simple_chain) {
  98. // NOTE:
  99. // This is a "hack" that force to create only one tip per chain since the solver of multi tip (end effector)
  100. // is not yet created.
  101. // Remove this code when this is done
  102. break;
  103. }
  104. }
  105. return true;
  106. }
  107. void FabrikInverseKinematic::solve_simple(Task *p_task, bool p_solve_magnet, Vector3 p_origin_pos) {
  108. real_t distance_to_goal(1e4);
  109. real_t previous_distance_to_goal(0);
  110. int can_solve(p_task->max_iterations);
  111. while (distance_to_goal > p_task->min_distance && Math::abs(previous_distance_to_goal - distance_to_goal) > 0.005 && can_solve) {
  112. previous_distance_to_goal = distance_to_goal;
  113. --can_solve;
  114. solve_simple_backwards(p_task->chain, p_solve_magnet);
  115. solve_simple_forwards(p_task->chain, p_solve_magnet, p_origin_pos);
  116. distance_to_goal = p_task->chain.tips[0].end_effector->goal_transform.origin.distance_to(p_task->chain.tips[0].chain_item->current_pos);
  117. }
  118. }
  119. void FabrikInverseKinematic::solve_simple_backwards(const Chain &r_chain, bool p_solve_magnet) {
  120. if (p_solve_magnet && !r_chain.middle_chain_item) {
  121. return;
  122. }
  123. Vector3 goal;
  124. ChainItem *sub_chain_tip;
  125. if (p_solve_magnet) {
  126. goal = r_chain.magnet_position;
  127. sub_chain_tip = r_chain.middle_chain_item;
  128. } else {
  129. goal = r_chain.tips[0].end_effector->goal_transform.origin;
  130. sub_chain_tip = r_chain.tips[0].chain_item;
  131. }
  132. while (sub_chain_tip) {
  133. sub_chain_tip->current_pos = goal;
  134. if (sub_chain_tip->parent_item) {
  135. // Not yet in the chain root
  136. // So calculate next goal location
  137. const Vector3 look_parent((sub_chain_tip->parent_item->current_pos - sub_chain_tip->current_pos).normalized());
  138. goal = sub_chain_tip->current_pos + (look_parent * sub_chain_tip->length);
  139. // [TODO] Constraints goes here
  140. }
  141. sub_chain_tip = sub_chain_tip->parent_item;
  142. }
  143. }
  144. void FabrikInverseKinematic::solve_simple_forwards(Chain &r_chain, bool p_solve_magnet, Vector3 p_origin_pos) {
  145. if (p_solve_magnet && !r_chain.middle_chain_item) {
  146. return;
  147. }
  148. ChainItem *sub_chain_root(&r_chain.chain_root);
  149. Vector3 origin = p_origin_pos;
  150. while (sub_chain_root) { // Reach the tip
  151. sub_chain_root->current_pos = origin;
  152. if (!sub_chain_root->children.is_empty()) {
  153. ChainItem &child(sub_chain_root->children.write[0]);
  154. // Is not tip
  155. // So calculate next origin location
  156. // Look child
  157. sub_chain_root->current_ori = (child.current_pos - sub_chain_root->current_pos).normalized();
  158. origin = sub_chain_root->current_pos + (sub_chain_root->current_ori * child.length);
  159. // [TODO] Constraints goes here
  160. if (p_solve_magnet && sub_chain_root == r_chain.middle_chain_item) {
  161. // In case of magnet solving this is the tip
  162. sub_chain_root = nullptr;
  163. } else {
  164. sub_chain_root = &child;
  165. }
  166. } else {
  167. // Is tip
  168. sub_chain_root = nullptr;
  169. }
  170. }
  171. }
  172. FabrikInverseKinematic::Task *FabrikInverseKinematic::create_simple_task(Skeleton3D *p_sk, BoneId root_bone, BoneId tip_bone, const Transform3D &goal_transform) {
  173. FabrikInverseKinematic::EndEffector ee;
  174. ee.tip_bone = tip_bone;
  175. Task *task(memnew(Task));
  176. task->skeleton = p_sk;
  177. task->root_bone = root_bone;
  178. task->end_effectors.push_back(ee);
  179. task->goal_global_transform = goal_transform;
  180. if (!build_chain(task)) {
  181. free_task(task);
  182. return nullptr;
  183. }
  184. return task;
  185. }
  186. void FabrikInverseKinematic::free_task(Task *p_task) {
  187. if (p_task) {
  188. memdelete(p_task);
  189. }
  190. }
  191. void FabrikInverseKinematic::set_goal(Task *p_task, const Transform3D &p_goal) {
  192. p_task->goal_global_transform = p_goal;
  193. }
  194. void FabrikInverseKinematic::make_goal(Task *p_task, const Transform3D &p_inverse_transf) {
  195. // Update the end_effector (local transform) by blending with current pose
  196. p_task->end_effectors.write[0].goal_transform = p_inverse_transf * p_task->goal_global_transform;
  197. }
  198. void FabrikInverseKinematic::solve(Task *p_task, bool override_tip_basis, bool p_use_magnet, const Vector3 &p_magnet_position) {
  199. // Update the initial root transform so its synced with any animation changes
  200. _update_chain(p_task->skeleton, &p_task->chain.chain_root);
  201. Vector3 origin_pos = p_task->skeleton->get_bone_global_pose(p_task->chain.chain_root.bone).origin;
  202. make_goal(p_task, p_task->skeleton->get_global_transform().affine_inverse());
  203. if (p_use_magnet && p_task->chain.middle_chain_item) {
  204. p_task->chain.magnet_position = p_magnet_position;
  205. solve_simple(p_task, true, origin_pos);
  206. }
  207. solve_simple(p_task, false, origin_pos);
  208. // Assign new bone position.
  209. ChainItem *ci(&p_task->chain.chain_root);
  210. while (ci) {
  211. Transform3D new_bone_pose(ci->initial_transform);
  212. new_bone_pose.origin = ci->current_pos;
  213. if (!ci->children.is_empty()) {
  214. Vector3 forward_vector = (ci->children[0].initial_transform.origin - ci->initial_transform.origin).normalized();
  215. // Rotate the bone towards the next bone in the chain:
  216. new_bone_pose.basis.rotate_to_align(forward_vector, new_bone_pose.origin.direction_to(ci->children[0].current_pos));
  217. } else {
  218. // Set target orientation to tip
  219. if (override_tip_basis) {
  220. new_bone_pose.basis = p_task->chain.tips[0].end_effector->goal_transform.basis;
  221. } else {
  222. new_bone_pose.basis = new_bone_pose.basis * p_task->chain.tips[0].end_effector->goal_transform.basis;
  223. }
  224. }
  225. // IK should not affect scale, so undo any scaling
  226. new_bone_pose.basis.orthonormalize();
  227. new_bone_pose.basis.scale(p_task->skeleton->get_bone_global_pose(ci->bone).basis.get_scale());
  228. p_task->skeleton->set_bone_global_pose(ci->bone, Transform3D(new_bone_pose.basis, p_task->skeleton->get_bone_global_pose(ci->bone).origin));
  229. if (!ci->children.is_empty()) {
  230. ci = &ci->children.write[0];
  231. } else {
  232. ci = nullptr;
  233. }
  234. }
  235. }
  236. void FabrikInverseKinematic::_update_chain(const Skeleton3D *p_sk, ChainItem *p_chain_item) {
  237. if (!p_chain_item) {
  238. return;
  239. }
  240. p_chain_item->initial_transform = p_sk->get_bone_global_pose(p_chain_item->bone);
  241. p_chain_item->current_pos = p_chain_item->initial_transform.origin;
  242. ChainItem *items = p_chain_item->children.ptrw();
  243. for (int i = 0; i < p_chain_item->children.size(); i += 1) {
  244. _update_chain(p_sk, items + i);
  245. }
  246. }
  247. void SkeletonIK3D::_validate_property(PropertyInfo &p_property) const {
  248. SkeletonModifier3D::_validate_property(p_property);
  249. if (p_property.name == "root_bone" || p_property.name == "tip_bone") {
  250. Skeleton3D *skeleton = get_skeleton();
  251. if (skeleton) {
  252. p_property.hint = PROPERTY_HINT_ENUM;
  253. p_property.hint_string = skeleton->get_concatenated_bone_names();
  254. } else {
  255. p_property.hint = PROPERTY_HINT_NONE;
  256. p_property.hint_string = "";
  257. }
  258. }
  259. }
  260. void SkeletonIK3D::_bind_methods() {
  261. ClassDB::bind_method(D_METHOD("set_root_bone", "root_bone"), &SkeletonIK3D::set_root_bone);
  262. ClassDB::bind_method(D_METHOD("get_root_bone"), &SkeletonIK3D::get_root_bone);
  263. ClassDB::bind_method(D_METHOD("set_tip_bone", "tip_bone"), &SkeletonIK3D::set_tip_bone);
  264. ClassDB::bind_method(D_METHOD("get_tip_bone"), &SkeletonIK3D::get_tip_bone);
  265. ClassDB::bind_method(D_METHOD("set_target_transform", "target"), &SkeletonIK3D::set_target_transform);
  266. ClassDB::bind_method(D_METHOD("get_target_transform"), &SkeletonIK3D::get_target_transform);
  267. ClassDB::bind_method(D_METHOD("set_target_node", "node"), &SkeletonIK3D::set_target_node);
  268. ClassDB::bind_method(D_METHOD("get_target_node"), &SkeletonIK3D::get_target_node);
  269. ClassDB::bind_method(D_METHOD("set_override_tip_basis", "override"), &SkeletonIK3D::set_override_tip_basis);
  270. ClassDB::bind_method(D_METHOD("is_override_tip_basis"), &SkeletonIK3D::is_override_tip_basis);
  271. ClassDB::bind_method(D_METHOD("set_use_magnet", "use"), &SkeletonIK3D::set_use_magnet);
  272. ClassDB::bind_method(D_METHOD("is_using_magnet"), &SkeletonIK3D::is_using_magnet);
  273. ClassDB::bind_method(D_METHOD("set_magnet_position", "local_position"), &SkeletonIK3D::set_magnet_position);
  274. ClassDB::bind_method(D_METHOD("get_magnet_position"), &SkeletonIK3D::get_magnet_position);
  275. ClassDB::bind_method(D_METHOD("get_parent_skeleton"), &SkeletonIK3D::get_parent_skeleton);
  276. ClassDB::bind_method(D_METHOD("is_running"), &SkeletonIK3D::is_running);
  277. ClassDB::bind_method(D_METHOD("set_min_distance", "min_distance"), &SkeletonIK3D::set_min_distance);
  278. ClassDB::bind_method(D_METHOD("get_min_distance"), &SkeletonIK3D::get_min_distance);
  279. ClassDB::bind_method(D_METHOD("set_max_iterations", "iterations"), &SkeletonIK3D::set_max_iterations);
  280. ClassDB::bind_method(D_METHOD("get_max_iterations"), &SkeletonIK3D::get_max_iterations);
  281. ClassDB::bind_method(D_METHOD("start", "one_time"), &SkeletonIK3D::start, DEFVAL(false));
  282. ClassDB::bind_method(D_METHOD("stop"), &SkeletonIK3D::stop);
  283. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "root_bone"), "set_root_bone", "get_root_bone");
  284. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "tip_bone"), "set_tip_bone", "get_tip_bone");
  285. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "target", PROPERTY_HINT_NONE, "suffix:m"), "set_target_transform", "get_target_transform");
  286. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_tip_basis"), "set_override_tip_basis", "is_override_tip_basis");
  287. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_magnet"), "set_use_magnet", "is_using_magnet");
  288. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "magnet", PROPERTY_HINT_NONE, "suffix:m"), "set_magnet_position", "get_magnet_position");
  289. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target_node"), "set_target_node", "get_target_node");
  290. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_distance", PROPERTY_HINT_NONE, "suffix:m"), "set_min_distance", "get_min_distance");
  291. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_iterations"), "set_max_iterations", "get_max_iterations");
  292. #ifndef DISABLE_DEPRECATED
  293. ClassDB::bind_method(D_METHOD("set_interpolation", "interpolation"), &SkeletonIK3D::_set_interpolation);
  294. ClassDB::bind_method(D_METHOD("get_interpolation"), &SkeletonIK3D::_get_interpolation);
  295. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "interpolation", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_NONE), "set_interpolation", "get_interpolation");
  296. #endif
  297. }
  298. void SkeletonIK3D::_process_modification() {
  299. if (!internal_active) {
  300. return;
  301. }
  302. if (target_node_override_ref) {
  303. reload_goal();
  304. }
  305. _solve_chain();
  306. }
  307. void SkeletonIK3D::_notification(int p_what) {
  308. switch (p_what) {
  309. case NOTIFICATION_ENTER_TREE: {
  310. reload_chain();
  311. } break;
  312. case NOTIFICATION_EXIT_TREE: {
  313. stop();
  314. } break;
  315. }
  316. }
  317. SkeletonIK3D::SkeletonIK3D() {
  318. }
  319. SkeletonIK3D::~SkeletonIK3D() {
  320. FabrikInverseKinematic::free_task(task);
  321. task = nullptr;
  322. }
  323. void SkeletonIK3D::set_root_bone(const StringName &p_root_bone) {
  324. root_bone = p_root_bone;
  325. reload_chain();
  326. }
  327. StringName SkeletonIK3D::get_root_bone() const {
  328. return root_bone;
  329. }
  330. void SkeletonIK3D::set_tip_bone(const StringName &p_tip_bone) {
  331. tip_bone = p_tip_bone;
  332. reload_chain();
  333. }
  334. StringName SkeletonIK3D::get_tip_bone() const {
  335. return tip_bone;
  336. }
  337. #ifndef DISABLE_DEPRECATED
  338. void SkeletonIK3D::_set_interpolation(real_t p_interpolation) {
  339. set_influence(p_interpolation);
  340. }
  341. real_t SkeletonIK3D::_get_interpolation() const {
  342. return get_influence();
  343. }
  344. #endif
  345. void SkeletonIK3D::set_target_transform(const Transform3D &p_target) {
  346. target = p_target;
  347. reload_goal();
  348. }
  349. const Transform3D &SkeletonIK3D::get_target_transform() const {
  350. return target;
  351. }
  352. void SkeletonIK3D::set_target_node(const NodePath &p_node) {
  353. target_node_path_override = p_node;
  354. target_node_override_ref = Variant();
  355. reload_goal();
  356. }
  357. NodePath SkeletonIK3D::get_target_node() {
  358. return target_node_path_override;
  359. }
  360. void SkeletonIK3D::set_override_tip_basis(bool p_override) {
  361. override_tip_basis = p_override;
  362. }
  363. bool SkeletonIK3D::is_override_tip_basis() const {
  364. return override_tip_basis;
  365. }
  366. void SkeletonIK3D::set_use_magnet(bool p_use) {
  367. use_magnet = p_use;
  368. }
  369. bool SkeletonIK3D::is_using_magnet() const {
  370. return use_magnet;
  371. }
  372. void SkeletonIK3D::set_magnet_position(const Vector3 &p_local_position) {
  373. magnet_position = p_local_position;
  374. }
  375. const Vector3 &SkeletonIK3D::get_magnet_position() const {
  376. return magnet_position;
  377. }
  378. void SkeletonIK3D::set_min_distance(real_t p_min_distance) {
  379. min_distance = p_min_distance;
  380. }
  381. void SkeletonIK3D::set_max_iterations(int p_iterations) {
  382. max_iterations = p_iterations;
  383. }
  384. Skeleton3D *SkeletonIK3D::get_parent_skeleton() const {
  385. return get_skeleton();
  386. }
  387. bool SkeletonIK3D::is_running() {
  388. return internal_active;
  389. }
  390. void SkeletonIK3D::start(bool p_one_time) {
  391. if (p_one_time) {
  392. internal_active = true;
  393. SkeletonModifier3D::process_modification();
  394. internal_active = false;
  395. } else {
  396. internal_active = true;
  397. }
  398. }
  399. void SkeletonIK3D::stop() {
  400. internal_active = false;
  401. }
  402. Transform3D SkeletonIK3D::_get_target_transform() {
  403. if (!target_node_override_ref && !target_node_path_override.is_empty()) {
  404. target_node_override_ref = Object::cast_to<Node3D>(get_node(target_node_path_override));
  405. }
  406. Node3D *target_node_override = cast_to<Node3D>(target_node_override_ref.get_validated_object());
  407. if (target_node_override && target_node_override->is_inside_tree()) {
  408. // Make sure to use the interpolated transform as target.
  409. // When physics interpolation is off this will pass through to get_global_transform().
  410. // When using interpolation, ensure that the target matches the interpolated visual position
  411. // of the target when updating the IK each frame.
  412. return target_node_override->get_global_transform_interpolated();
  413. } else {
  414. return target;
  415. }
  416. }
  417. void SkeletonIK3D::reload_chain() {
  418. FabrikInverseKinematic::free_task(task);
  419. task = nullptr;
  420. Skeleton3D *skeleton = get_skeleton();
  421. if (!skeleton) {
  422. return;
  423. }
  424. task = FabrikInverseKinematic::create_simple_task(skeleton, skeleton->find_bone(root_bone), skeleton->find_bone(tip_bone), _get_target_transform());
  425. if (task) {
  426. task->max_iterations = max_iterations;
  427. task->min_distance = min_distance;
  428. }
  429. }
  430. void SkeletonIK3D::reload_goal() {
  431. if (!task) {
  432. return;
  433. }
  434. FabrikInverseKinematic::set_goal(task, _get_target_transform());
  435. }
  436. void SkeletonIK3D::_solve_chain() {
  437. if (!task) {
  438. return;
  439. }
  440. FabrikInverseKinematic::solve(task, override_tip_basis, use_magnet, magnet_position);
  441. }