1 | /**************************************************************************/ |
2 | /* skeleton_modification_2d_twoboneik.h */ |
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 | |
31 | #ifndef SKELETON_MODIFICATION_2D_TWOBONEIK_H |
32 | #define SKELETON_MODIFICATION_2D_TWOBONEIK_H |
33 | |
34 | #include "scene/2d/skeleton_2d.h" |
35 | #include "scene/resources/skeleton_modification_2d.h" |
36 | |
37 | /////////////////////////////////////// |
38 | // SkeletonModification2DJIGGLE |
39 | /////////////////////////////////////// |
40 | |
41 | class SkeletonModification2DTwoBoneIK : public SkeletonModification2D { |
42 | GDCLASS(SkeletonModification2DTwoBoneIK, SkeletonModification2D); |
43 | |
44 | private: |
45 | NodePath target_node; |
46 | ObjectID target_node_cache; |
47 | float target_minimum_distance = 0; |
48 | float target_maximum_distance = 0; |
49 | bool flip_bend_direction = false; |
50 | |
51 | NodePath joint_one_bone2d_node; |
52 | ObjectID joint_one_bone2d_node_cache; |
53 | int joint_one_bone_idx = -1; |
54 | |
55 | NodePath joint_two_bone2d_node; |
56 | ObjectID joint_two_bone2d_node_cache; |
57 | int joint_two_bone_idx = -1; |
58 | |
59 | #ifdef TOOLS_ENABLED |
60 | bool editor_draw_min_max = false; |
61 | #endif // TOOLS_ENABLED |
62 | |
63 | void update_target_cache(); |
64 | void update_joint_one_bone2d_cache(); |
65 | void update_joint_two_bone2d_cache(); |
66 | |
67 | protected: |
68 | static void _bind_methods(); |
69 | bool _get(const StringName &p_path, Variant &r_ret) const; |
70 | bool _set(const StringName &p_path, const Variant &p_value); |
71 | void _get_property_list(List<PropertyInfo> *p_list) const; |
72 | |
73 | public: |
74 | void _execute(float p_delta) override; |
75 | void _setup_modification(SkeletonModificationStack2D *p_stack) override; |
76 | void _draw_editor_gizmo() override; |
77 | |
78 | void set_target_node(const NodePath &p_target_node); |
79 | NodePath get_target_node() const; |
80 | |
81 | void set_target_minimum_distance(float p_minimum_distance); |
82 | float get_target_minimum_distance() const; |
83 | void set_target_maximum_distance(float p_maximum_distance); |
84 | float get_target_maximum_distance() const; |
85 | void set_flip_bend_direction(bool p_flip_direction); |
86 | bool get_flip_bend_direction() const; |
87 | |
88 | void set_joint_one_bone2d_node(const NodePath &p_node); |
89 | NodePath get_joint_one_bone2d_node() const; |
90 | void set_joint_one_bone_idx(int p_bone_idx); |
91 | int get_joint_one_bone_idx() const; |
92 | |
93 | void set_joint_two_bone2d_node(const NodePath &p_node); |
94 | NodePath get_joint_two_bone2d_node() const; |
95 | void set_joint_two_bone_idx(int p_bone_idx); |
96 | int get_joint_two_bone_idx() const; |
97 | |
98 | #ifdef TOOLS_ENABLED |
99 | void set_editor_draw_min_max(bool p_draw); |
100 | bool get_editor_draw_min_max() const; |
101 | #endif // TOOLS_ENABLED |
102 | |
103 | SkeletonModification2DTwoBoneIK(); |
104 | ~SkeletonModification2DTwoBoneIK(); |
105 | }; |
106 | |
107 | #endif // SKELETON_MODIFICATION_2D_TWOBONEIK_H |
108 | |