1 | /**************************************************************************/ |
2 | /* skeleton_modification_2d_ccdik.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_CCDIK_H |
32 | #define SKELETON_MODIFICATION_2D_CCDIK_H |
33 | |
34 | #include "scene/2d/skeleton_2d.h" |
35 | #include "scene/resources/skeleton_modification_2d.h" |
36 | |
37 | /////////////////////////////////////// |
38 | // SkeletonModification2DCCDIK |
39 | /////////////////////////////////////// |
40 | |
41 | class SkeletonModification2DCCDIK : public SkeletonModification2D { |
42 | GDCLASS(SkeletonModification2DCCDIK, SkeletonModification2D); |
43 | |
44 | private: |
45 | struct CCDIK_Joint_Data2D { |
46 | int bone_idx = -1; |
47 | NodePath bone2d_node; |
48 | ObjectID bone2d_node_cache; |
49 | bool rotate_from_joint = false; |
50 | |
51 | bool enable_constraint = false; |
52 | float constraint_angle_min = 0; |
53 | float constraint_angle_max = (2.0 * Math_PI); |
54 | bool constraint_angle_invert = false; |
55 | bool constraint_in_localspace = true; |
56 | |
57 | bool editor_draw_gizmo = true; |
58 | }; |
59 | |
60 | Vector<CCDIK_Joint_Data2D> ccdik_data_chain; |
61 | |
62 | NodePath target_node; |
63 | ObjectID target_node_cache; |
64 | void update_target_cache(); |
65 | |
66 | NodePath tip_node; |
67 | ObjectID tip_node_cache; |
68 | void update_tip_cache(); |
69 | |
70 | void ccdik_joint_update_bone2d_cache(int p_joint_idx); |
71 | void _execute_ccdik_joint(int p_joint_idx, Node2D *p_target, Node2D *p_tip); |
72 | |
73 | protected: |
74 | static void _bind_methods(); |
75 | bool _set(const StringName &p_path, const Variant &p_value); |
76 | bool _get(const StringName &p_path, Variant &r_ret) const; |
77 | void _get_property_list(List<PropertyInfo> *p_list) const; |
78 | |
79 | public: |
80 | void _execute(float p_delta) override; |
81 | void _setup_modification(SkeletonModificationStack2D *p_stack) override; |
82 | void _draw_editor_gizmo() override; |
83 | |
84 | void set_target_node(const NodePath &p_target_node); |
85 | NodePath get_target_node() const; |
86 | void set_tip_node(const NodePath &p_tip_node); |
87 | NodePath get_tip_node() const; |
88 | |
89 | int get_ccdik_data_chain_length(); |
90 | void set_ccdik_data_chain_length(int p_new_length); |
91 | |
92 | void set_ccdik_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node); |
93 | NodePath get_ccdik_joint_bone2d_node(int p_joint_idx) const; |
94 | void set_ccdik_joint_bone_index(int p_joint_idx, int p_bone_idx); |
95 | int get_ccdik_joint_bone_index(int p_joint_idx) const; |
96 | |
97 | void set_ccdik_joint_rotate_from_joint(int p_joint_idx, bool p_rotate_from_joint); |
98 | bool get_ccdik_joint_rotate_from_joint(int p_joint_idx) const; |
99 | void set_ccdik_joint_enable_constraint(int p_joint_idx, bool p_constraint); |
100 | bool get_ccdik_joint_enable_constraint(int p_joint_idx) const; |
101 | void set_ccdik_joint_constraint_angle_min(int p_joint_idx, float p_angle_min); |
102 | float get_ccdik_joint_constraint_angle_min(int p_joint_idx) const; |
103 | void set_ccdik_joint_constraint_angle_max(int p_joint_idx, float p_angle_max); |
104 | float get_ccdik_joint_constraint_angle_max(int p_joint_idx) const; |
105 | void set_ccdik_joint_constraint_angle_invert(int p_joint_idx, bool p_invert); |
106 | bool get_ccdik_joint_constraint_angle_invert(int p_joint_idx) const; |
107 | void set_ccdik_joint_constraint_in_localspace(int p_joint_idx, bool p_constraint_in_localspace); |
108 | bool get_ccdik_joint_constraint_in_localspace(int p_joint_idx) const; |
109 | void set_ccdik_joint_editor_draw_gizmo(int p_joint_idx, bool p_draw_gizmo); |
110 | bool get_ccdik_joint_editor_draw_gizmo(int p_joint_idx) const; |
111 | |
112 | SkeletonModification2DCCDIK(); |
113 | ~SkeletonModification2DCCDIK(); |
114 | }; |
115 | |
116 | #endif // SKELETON_MODIFICATION_2D_CCDIK_H |
117 | |