| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/skeleton_2d.h" |
| 34 |
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
class SkeletonModification2DFABRIK : public SkeletonModification2D { |
| 41 |
GDCLASS(SkeletonModification2DFABRIK, SkeletonModification2D); |
| 42 |
|
| 43 |
private: |
| 44 |
struct FABRIK_Joint_Data2D { |
| 45 |
int bone_idx = -1; |
| 46 |
NodePath bone2d_node; |
| 47 |
ObjectID bone2d_node_cache; |
| 48 |
|
| 49 |
Vector2 magnet_position = Vector2(0, 0); |
| 50 |
bool use_target_rotation = false; |
| 51 |
|
| 52 |
bool editor_draw_gizmo = true; |
| 53 |
}; |
| 54 |
|
| 55 |
Vector<FABRIK_Joint_Data2D> fabrik_data_chain; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
Vector<Transform2D> fabrik_transform_chain; |
| 62 |
|
| 63 |
NodePath target_node; |
| 64 |
ObjectID target_node_cache; |
| 65 |
void update_target_cache(); |
| 66 |
|
| 67 |
float chain_tolarance = 0.01; |
| 68 |
int chain_max_iterations = 10; |
| 69 |
int chain_iterations = 0; |
| 70 |
Transform2D target_global_pose; |
| 71 |
Transform2D origin_global_pose; |
| 72 |
|
| 73 |
void fabrik_joint_update_bone2d_cache(int p_joint_idx); |
| 74 |
void chain_backwards(); |
| 75 |
void chain_forwards(); |
| 76 |
|
| 77 |
protected: |
| 78 |
static void _bind_methods(); |
| 79 |
bool _set(const StringName &p_path, const Variant &p_value); |
| 80 |
bool _get(const StringName &p_path, Variant &r_ret) const; |
| 81 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 82 |
|
| 83 |
public: |
| 84 |
void _execute(float p_delta) override; |
| 85 |
void _setup_modification(SkeletonModificationStack2D *p_stack) override; |
| 86 |
|
| 87 |
void set_target_node(const NodePath &p_target_node); |
| 88 |
NodePath get_target_node() const; |
| 89 |
|
| 90 |
int get_fabrik_data_chain_length(); |
| 91 |
void set_fabrik_data_chain_length(int p_new_length); |
| 92 |
|
| 93 |
void set_fabrik_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node); |
| 94 |
NodePath get_fabrik_joint_bone2d_node(int p_joint_idx) const; |
| 95 |
void set_fabrik_joint_bone_index(int p_joint_idx, int p_bone_idx); |
| 96 |
int get_fabrik_joint_bone_index(int p_joint_idx) const; |
| 97 |
|
| 98 |
void set_fabrik_joint_magnet_position(int p_joint_idx, Vector2 p_magnet_position); |
| 99 |
Vector2 get_fabrik_joint_magnet_position(int p_joint_idx) const; |
| 100 |
void set_fabrik_joint_use_target_rotation(int p_joint_idx, bool p_use_target_rotation); |
| 101 |
bool get_fabrik_joint_use_target_rotation(int p_joint_idx) const; |
| 102 |
|
| 103 |
SkeletonModification2DFABRIK(); |
| 104 |
~SkeletonModification2DFABRIK(); |
| 105 |
}; |