| 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/2d/node_2d.h" |
| 34 |
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h" |
| 35 |
|
| 36 |
class Skeleton2D; |
| 37 |
|
| 38 |
class Bone2D : public Node2D { |
| 39 |
GDCLASS(Bone2D, Node2D); |
| 40 |
|
| 41 |
friend class Skeleton2D; |
| 42 |
#ifdef TOOLS_ENABLED |
| 43 |
friend class AnimatedValuesBackup; |
| 44 |
#endif |
| 45 |
|
| 46 |
Bone2D *parent_bone = nullptr; |
| 47 |
Skeleton2D *skeleton = nullptr; |
| 48 |
Transform2D rest; |
| 49 |
|
| 50 |
bool autocalculate_length_and_angle = true; |
| 51 |
real_t length = 16; |
| 52 |
real_t bone_angle = 0; |
| 53 |
|
| 54 |
int skeleton_index = -1; |
| 55 |
|
| 56 |
void calculate_length_and_rotation(); |
| 57 |
|
| 58 |
#ifdef TOOLS_ENABLED |
| 59 |
RID editor_gizmo_rid; |
| 60 |
bool _editor_get_bone_shape(Vector<Vector2> *p_shape, Vector<Vector2> *p_outline_shape, Bone2D *p_other_bone); |
| 61 |
bool _editor_show_bone_gizmo = true; |
| 62 |
#endif |
| 63 |
|
| 64 |
protected: |
| 65 |
void _notification(int p_what); |
| 66 |
static void _bind_methods(); |
| 67 |
bool _set(const StringName &p_path, const Variant &p_value); |
| 68 |
bool _get(const StringName &p_path, Variant &r_ret) const; |
| 69 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 70 |
|
| 71 |
public: |
| 72 |
Transform2D cache_transform; |
| 73 |
bool copy_transform_to_cache = true; |
| 74 |
|
| 75 |
void set_rest(const Transform2D &p_rest); |
| 76 |
Transform2D get_rest() const; |
| 77 |
void apply_rest(); |
| 78 |
Transform2D get_skeleton_rest() const; |
| 79 |
|
| 80 |
PackedStringArray get_configuration_warnings() const override; |
| 81 |
|
| 82 |
void set_autocalculate_length_and_angle(bool p_autocalculate); |
| 83 |
bool get_autocalculate_length_and_angle() const; |
| 84 |
void set_length(real_t p_length); |
| 85 |
real_t get_length() const; |
| 86 |
void set_bone_angle(real_t p_angle); |
| 87 |
real_t get_bone_angle() const; |
| 88 |
|
| 89 |
int get_index_in_skeleton() const; |
| 90 |
|
| 91 |
#ifdef TOOLS_ENABLED |
| 92 |
void _editor_set_show_bone_gizmo(bool p_show_gizmo); |
| 93 |
bool _editor_get_show_bone_gizmo() const; |
| 94 |
#endif |
| 95 |
|
| 96 |
Bone2D(); |
| 97 |
~Bone2D(); |
| 98 |
}; |
| 99 |
|
| 100 |
class SkeletonModificationStack2D; |
| 101 |
|
| 102 |
class Skeleton2D : public Node2D { |
| 103 |
GDCLASS(Skeleton2D, Node2D); |
| 104 |
|
| 105 |
friend class Bone2D; |
| 106 |
#ifdef TOOLS_ENABLED |
| 107 |
friend class AnimatedValuesBackup; |
| 108 |
#endif |
| 109 |
|
| 110 |
struct Bone { |
| 111 |
bool operator<(const Bone &p_bone) const { |
| 112 |
return p_bone.bone->is_greater_than(bone); |
| 113 |
} |
| 114 |
Bone2D *bone = nullptr; |
| 115 |
int parent_index = 0; |
| 116 |
Transform2D accum_transform; |
| 117 |
Transform2D rest_inverse; |
| 118 |
|
| 119 |
|
| 120 |
Transform2D local_pose_override; |
| 121 |
real_t local_pose_override_amount = 0; |
| 122 |
bool local_pose_override_persistent = false; |
| 123 |
}; |
| 124 |
|
| 125 |
LocalVector<Bone> bones; |
| 126 |
|
| 127 |
bool bone_setup_dirty = true; |
| 128 |
void _make_bone_setup_dirty(); |
| 129 |
void _update_bone_setup(); |
| 130 |
|
| 131 |
bool transform_dirty = true; |
| 132 |
void _make_transform_dirty(); |
| 133 |
void _update_transform(); |
| 134 |
|
| 135 |
RID skeleton; |
| 136 |
|
| 137 |
Ref<SkeletonModificationStack2D> modification_stack; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
struct InterpolationData { |
| 142 |
Transform2D xform_curr; |
| 143 |
Transform2D xform_prev; |
| 144 |
uint32_t last_update_physics_tick = UINT32_MAX; |
| 145 |
} _interpolation_data; |
| 146 |
|
| 147 |
void _update_process_mode(); |
| 148 |
void _ensure_update_interpolation_data(); |
| 149 |
|
| 150 |
protected: |
| 151 |
virtual void _physics_interpolated_changed() override; |
| 152 |
|
| 153 |
|
| 154 |
void _notification(int p_what); |
| 155 |
static void _bind_methods(); |
| 156 |
bool _set(const StringName &p_path, const Variant &p_value); |
| 157 |
bool _get(const StringName &p_path, Variant &r_ret) const; |
| 158 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 159 |
|
| 160 |
public: |
| 161 |
int get_bone_count() const; |
| 162 |
Bone2D *get_bone(int p_idx); |
| 163 |
|
| 164 |
RID get_skeleton() const; |
| 165 |
|
| 166 |
void set_bone_local_pose_override(int p_bone_idx, Transform2D p_override, real_t p_amount, bool p_persistent = true); |
| 167 |
Transform2D get_bone_local_pose_override(int p_bone_idx); |
| 168 |
|
| 169 |
Ref<SkeletonModificationStack2D> get_modification_stack() const; |
| 170 |
void set_modification_stack(Ref<SkeletonModificationStack2D> p_stack); |
| 171 |
void execute_modifications(real_t p_delta, int p_execution_mode); |
| 172 |
|
| 173 |
Skeleton2D(); |
| 174 |
~Skeleton2D(); |
| 175 |
}; |