Debian Codegraph @

scene/3d/ik_modifier_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* ik_modifier_3d.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 #pragma once
32
33 #include "scene/3d/skeleton_modifier_3d.h"
34
35 class IKModifier3D : public SkeletonModifier3D {
36 GDCLASS(IKModifier3D, SkeletonModifier3D);
37
38 protected:
39 #ifdef TOOLS_ENABLED
40 bool saving = false;
41 #endif // TOOLS_ENABLED
42
43 bool mutable_bone_axes = true;
44 Transform3D cached_space;
45 bool joints_dirty = false;
46
47 public:
48 struct BoneJoint {
49 StringName name;
50 int bone = -1;
51 };
52
53 struct IKModifier3DSolverInfo {
54 Quaternion current_lpose;
55 Quaternion current_lrest;
56 Quaternion current_gpose;
57 Quaternion current_grest;
58 Vector3 current_vector; // Global so needs xfrom_inv by gpose or grest in the process.
59 Vector3 forward_vector; // Local.
60 float length = 0.0;
61 };
62
63 struct IKModifier3DSetting {
64 bool simulation_dirty = true;
65 bool joints_dirty = false;
66 };
67
68 protected:
69 LocalVector<IKModifier3DSetting *> settings;
70
71 void _notification(int p_what);
72 static void _bind_methods();
73
74 virtual void _set_active(bool p_active) override;
75 virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;
76
77 virtual void _validate_bone_names() override;
78
79 void _rest_updated();
80 virtual void _make_all_joints_dirty();
81 virtual void _init_joints(Skeleton3D *p_skeleton, int p_index);
82 virtual void _update_joints(int p_index);
83 virtual void _make_simulation_dirty(int p_index);
84 virtual void _update_bone_axis(Skeleton3D *p_skeleton, int p_index);
85
86 #ifdef TOOLS_ENABLED
87 bool gizmo_dirty = false;
88 void _make_gizmo_dirty();
89 virtual void _update_mutable_info();
90 void _redraw_gizmo();
91 #endif // TOOLS_ENABLED
92
93 virtual void _process_modification(double p_delta) override;
94 virtual void _process_ik(Skeleton3D *p_skeleton, double p_delta);
95
96 template <typename T>
97 void _set_setting_count(int p_count) {
98 ERR_FAIL_COND(p_count < 0);
99 int delta = p_count - settings.size();
100 if (delta < 0) {
101 for (int i = delta; i < 0; i++) {
102 memdelete(static_cast<T *>(settings[settings.size() + i]));
103 settings[settings.size() + i] = nullptr;
104 }
105 }
106 settings.resize(p_count);
107 delta++;
108 if (delta > 1) {
109 for (int i = 1; i < delta; i++) {
110 settings[p_count - i] = memnew(T);
111 }
112 }
113 notify_property_list_changed();
114 }
115 template <typename T>
116 LocalVector<T *> _cast_settings() const {
117 LocalVector<T *> result;
118 for (uint32_t i = 0; i < settings.size(); i++) {
119 result.push_back(static_cast<T *>(settings[i]));
120 }
121 return result;
122 }
123
124 public:
125 int get_setting_count() const;
126
127 virtual void set_setting_count(int p_count) {
128 _set_setting_count<IKModifier3DSetting>(p_count);
129 }
130 virtual void clear_settings() {
131 _set_setting_count<IKModifier3DSetting>(0);
132 }
133
134 void set_mutable_bone_axes(bool p_enabled);
135 bool are_bone_axes_mutable() const;
136
137 // Helper.
138 static Quaternion get_local_pose_rotation(Skeleton3D *p_skeleton, int p_bone, const Quaternion &p_global_pose_rotation);
139 static Vector3 get_bone_axis(Skeleton3D *p_skeleton, int p_end_bone, BoneDirection p_direction, bool p_mutable_bone_axes);
140
141 // To process manually.
142 void reset();
143
144 ~IKModifier3D();
145 };