| 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 "editor/editor_node.h" |
| 34 |
#include "editor/inspector/editor_properties.h" |
| 35 |
#include "editor/plugins/editor_plugin.h" |
| 36 |
|
| 37 |
#include "scene/3d/skeleton_3d.h" |
| 38 |
#include "scene/gui/box_container.h" |
| 39 |
#include "scene/gui/color_rect.h" |
| 40 |
#include "scene/gui/dialogs.h" |
| 41 |
#include "scene/resources/bone_map.h" |
| 42 |
#include "scene/resources/texture.h" |
| 43 |
|
| 44 |
class AspectRatioContainer; |
| 45 |
|
| 46 |
class BoneMapperButton : public TextureButton { |
| 47 |
GDCLASS(BoneMapperButton, TextureButton); |
| 48 |
|
| 49 |
public: |
| 50 |
enum BoneMapState { |
| 51 |
BONE_MAP_STATE_UNSET, |
| 52 |
BONE_MAP_STATE_SET, |
| 53 |
BONE_MAP_STATE_MISSING, |
| 54 |
BONE_MAP_STATE_ERROR |
| 55 |
}; |
| 56 |
|
| 57 |
private: |
| 58 |
StringName profile_bone_name; |
| 59 |
bool selected = false; |
| 60 |
bool require = false; |
| 61 |
|
| 62 |
TextureRect *circle = nullptr; |
| 63 |
|
| 64 |
void fetch_textures(); |
| 65 |
|
| 66 |
protected: |
| 67 |
void _notification(int p_what); |
| 68 |
|
| 69 |
public: |
| 70 |
StringName get_profile_bone_name() const; |
| 71 |
void set_state(BoneMapState p_state); |
| 72 |
|
| 73 |
bool is_require() const; |
| 74 |
|
| 75 |
BoneMapperButton(const StringName &p_profile_bone_name, bool p_require, bool p_selected); |
| 76 |
}; |
| 77 |
|
| 78 |
class BoneMapperItem : public VBoxContainer { |
| 79 |
GDCLASS(BoneMapperItem, VBoxContainer); |
| 80 |
|
| 81 |
StringName profile_bone_name; |
| 82 |
|
| 83 |
Ref<BoneMap> bone_map; |
| 84 |
|
| 85 |
EditorPropertyText *skeleton_bone_selector = nullptr; |
| 86 |
Button *picker_button = nullptr; |
| 87 |
|
| 88 |
void _update_property(); |
| 89 |
void _open_picker(); |
| 90 |
|
| 91 |
protected: |
| 92 |
void _notification(int p_what); |
| 93 |
static void _bind_methods(); |
| 94 |
virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing); |
| 95 |
virtual void create_editor(); |
| 96 |
|
| 97 |
public: |
| 98 |
void assign_button_id(int p_button_id); |
| 99 |
|
| 100 |
BoneMapperItem(Ref<BoneMap> &p_bone_map, const StringName &p_profile_bone_name = StringName()); |
| 101 |
}; |
| 102 |
|
| 103 |
class BonePicker : public AcceptDialog { |
| 104 |
GDCLASS(BonePicker, AcceptDialog); |
| 105 |
|
| 106 |
Skeleton3D *skeleton = nullptr; |
| 107 |
Tree *bones = nullptr; |
| 108 |
|
| 109 |
public: |
| 110 |
void popup_bones_tree(const Size2i &p_minsize = Size2i()); |
| 111 |
bool has_selected_bone(); |
| 112 |
StringName get_selected_bone(); |
| 113 |
|
| 114 |
protected: |
| 115 |
void _notification(int p_what); |
| 116 |
void _confirm(); |
| 117 |
|
| 118 |
private: |
| 119 |
void create_editors(); |
| 120 |
void create_bones_tree(Skeleton3D *p_skeleton); |
| 121 |
|
| 122 |
public: |
| 123 |
BonePicker(Skeleton3D *p_skeleton); |
| 124 |
}; |
| 125 |
|
| 126 |
class BoneMapper : public VBoxContainer { |
| 127 |
GDCLASS(BoneMapper, VBoxContainer); |
| 128 |
|
| 129 |
Skeleton3D *skeleton = nullptr; |
| 130 |
Ref<BoneMap> bone_map; |
| 131 |
|
| 132 |
EditorPropertyResource *profile_selector = nullptr; |
| 133 |
|
| 134 |
Vector<BoneMapperItem *> bone_mapper_items; |
| 135 |
|
| 136 |
Button *clear_mapping_button = nullptr; |
| 137 |
|
| 138 |
VBoxContainer *mapper_item_vbox = nullptr; |
| 139 |
|
| 140 |
int current_group_idx = 0; |
| 141 |
int current_bone_idx = -1; |
| 142 |
|
| 143 |
AspectRatioContainer *bone_mapper_field = nullptr; |
| 144 |
EditorPropertyEnum *profile_group_selector = nullptr; |
| 145 |
ColorRect *profile_bg = nullptr; |
| 146 |
TextureRect *profile_texture = nullptr; |
| 147 |
Vector<BoneMapperButton *> bone_mapper_buttons; |
| 148 |
|
| 149 |
void create_editor(); |
| 150 |
void recreate_editor(); |
| 151 |
void clear_items(); |
| 152 |
void recreate_items(); |
| 153 |
void update_group_idx(); |
| 154 |
void _update_state(); |
| 155 |
|
| 156 |
|
| 157 |
BonePicker *picker = nullptr; |
| 158 |
StringName picker_key_name; |
| 159 |
void _pick_bone(const StringName &p_bone_name); |
| 160 |
void _apply_picker_selection(); |
| 161 |
void _clear_mapping_current_group(); |
| 162 |
|
| 163 |
|
| 164 |
enum BoneSegregation { |
| 165 |
BONE_SEGREGATION_NONE, |
| 166 |
BONE_SEGREGATION_LEFT, |
| 167 |
BONE_SEGREGATION_RIGHT |
| 168 |
}; |
| 169 |
bool is_match_with_bone_name(const String &p_bone_name, const String &p_word); |
| 170 |
int search_bone_by_name(Skeleton3D *p_skeleton, const Vector<String> &p_picklist, BoneSegregation p_segregation = BONE_SEGREGATION_NONE, int p_parent = -1, int p_child = -1, int p_children_count = -1); |
| 171 |
BoneSegregation guess_bone_segregation(const String &p_bone_name); |
| 172 |
void auto_mapping_process(Ref<BoneMap> &p_bone_map); |
| 173 |
void _run_auto_mapping(); |
| 174 |
|
| 175 |
protected: |
| 176 |
void _notification(int p_what); |
| 177 |
static void _bind_methods(); |
| 178 |
virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing); |
| 179 |
virtual void _profile_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing); |
| 180 |
|
| 181 |
public: |
| 182 |
void set_current_group_idx(int p_group_idx); |
| 183 |
int get_current_group_idx() const; |
| 184 |
void set_current_bone_idx(int p_bone_idx); |
| 185 |
int get_current_bone_idx() const; |
| 186 |
|
| 187 |
BoneMapper(Skeleton3D *p_skeleton, Ref<BoneMap> &p_bone_map); |
| 188 |
}; |
| 189 |
|
| 190 |
class BoneMapEditor : public VBoxContainer { |
| 191 |
GDCLASS(BoneMapEditor, VBoxContainer); |
| 192 |
|
| 193 |
Skeleton3D *skeleton = nullptr; |
| 194 |
Ref<BoneMap> bone_map; |
| 195 |
BoneMapper *bone_mapper = nullptr; |
| 196 |
|
| 197 |
void fetch_objects(); |
| 198 |
void create_editors(); |
| 199 |
|
| 200 |
protected: |
| 201 |
void _notification(int p_what); |
| 202 |
|
| 203 |
public: |
| 204 |
BoneMapEditor(Ref<BoneMap> &p_bone_map); |
| 205 |
}; |
| 206 |
|
| 207 |
class EditorInspectorPluginBoneMap : public EditorInspectorPlugin { |
| 208 |
GDCLASS(EditorInspectorPluginBoneMap, EditorInspectorPlugin); |
| 209 |
BoneMapEditor *editor = nullptr; |
| 210 |
|
| 211 |
public: |
| 212 |
virtual bool can_handle(Object *p_object) override; |
| 213 |
virtual void parse_begin(Object *p_object) override; |
| 214 |
}; |
| 215 |
|
| 216 |
class BoneMapEditorPlugin : public EditorPlugin { |
| 217 |
GDCLASS(BoneMapEditorPlugin, EditorPlugin); |
| 218 |
|
| 219 |
public: |
| 220 |
virtual String get_plugin_name() const override { return "BoneMap"; } |
| 221 |
BoneMapEditorPlugin(); |
| 222 |
}; |