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