Debian Codegraph @

scene/3d/bone_twist_disperser_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* bone_twist_disperser_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 BoneTwistDisperser3D : public SkeletonModifier3D {
36 GDCLASS(BoneTwistDisperser3D, SkeletonModifier3D);
37
38 bool mutable_bone_axes = true;
39
40 public:
41 enum DisperseMode {
42 DISPERSE_MODE_EVEN,
43 DISPERSE_MODE_WEIGHTED,
44 DISPERSE_MODE_CUSTOM,
45 };
46
47 struct BoneJoint {
48 StringName name;
49 int bone = -1;
50 };
51
52 struct DisperseJointSetting {
53 BoneJoint joint;
54 double custom_amount = 1.0;
55 // For processing.
56 double amount = 1.0;
57 Vector3 axis;
58 };
59
60 struct BoneTwistDisperser3DSetting {
61 bool joints_dirty = false;
62
63 DisperseMode disperse_mode = DISPERSE_MODE_EVEN;
64 bool twist_from_rest = true;
65 Quaternion twist_from;
66
67 BoneJoint root_bone;
68 BoneJoint end_bone;
69 LocalVector<DisperseJointSetting> joints;
70
71 bool extend_end_bone = false;
72 BoneDirection end_bone_direction = BONE_DIRECTION_FROM_PARENT;
73
74 float weight_position = 0.5;
75 Ref<Curve> damping_curve;
76
77 BoneJoint reference_bone; // To cache.
78
79 ~BoneTwistDisperser3DSetting() {
80 joints.clear();
81 damping_curve.unref();
82 }
83 };
84
85 protected:
86 LocalVector<BoneTwistDisperser3DSetting *> settings;
87
88 bool _get(const StringName &p_path, Variant &r_ret) const;
89 bool _set(const StringName &p_path, const Variant &p_value);
90 void _get_property_list(List<PropertyInfo> *p_list) const;
91 void _validate_dynamic_prop(PropertyInfo &p_property) const;
92
93 void _notification(int p_what);
94 static void _bind_methods();
95
96 virtual void _set_active(bool p_active) override;
97 virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;
98 virtual void _validate_bone_names() override;
99
100 void _make_all_joints_dirty();
101
102 void _make_joints_dirty(int p_index);
103 void _update_joints(int p_index);
104 void _set_joint_bone(int p_index, int p_joint, int p_bone);
105
106 void _update_reference_bone(int p_index);
107 void _update_curve(int p_index);
108
109 virtual void _process_modification(double p_delta) override;
110
111 public:
112 void set_mutable_bone_axes(bool p_enabled);
113 bool are_bone_axes_mutable() const;
114
115 int get_setting_count() const;
116 void set_setting_count(int p_count);
117 void clear_settings();
118
119 // Setting.
120 void set_root_bone_name(int p_index, const String &p_bone_name);
121 String get_root_bone_name(int p_index) const;
122 void set_root_bone(int p_index, int p_bone);
123 int get_root_bone(int p_index) const;
124
125 void set_end_bone_name(int p_index, const String &p_bone_name);
126 String get_end_bone_name(int p_index) const;
127 void set_end_bone(int p_index, int p_bone);
128 int get_end_bone(int p_index) const;
129
130 void set_extend_end_bone(int p_index, bool p_enabled);
131 bool is_end_bone_extended(int p_index) const;
132 void set_end_bone_direction(int p_index, BoneDirection p_bone_direction);
133 BoneDirection get_end_bone_direction(int p_index) const;
134
135 void set_twist_from_rest(int p_index, bool p_enabled);
136 bool is_twist_from_rest(int p_index) const;
137 void set_twist_from(int p_index, const Quaternion &p_from);
138 Quaternion get_twist_from(int p_index) const;
139
140 String get_reference_bone_name(int p_index) const;
141 int get_reference_bone(int p_index) const;
142
143 void set_disperse_mode(int p_index, DisperseMode p_disperse_mode);
144 DisperseMode get_disperse_mode(int p_index) const;
145 void set_weight_position(int p_index, float p_position);
146 float get_weight_position(int p_index) const;
147 void set_damping_curve(int p_index, const Ref<Curve> &p_damping_curve);
148 Ref<Curve> get_damping_curve(int p_index) const;
149
150 // Individual joints.
151 String get_joint_bone_name(int p_index, int p_joint) const;
152 int get_joint_bone(int p_index, int p_joint) const;
153
154 void set_joint_twist_amount(int p_index, int p_joint, float p_amount);
155 float get_joint_twist_amount(int p_index, int p_joint) const;
156
157 void set_joint_count(int p_index, int p_count);
158 int get_joint_count(int p_index) const;
159
160 ~BoneTwistDisperser3D();
161 };
162
163 VARIANT_ENUM_CAST(BoneTwistDisperser3D::DisperseMode);