| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 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; |
| 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 |
|
| 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 |
|
| 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); |