Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/3d/bone_map_editor_plugin.h
21138 views
1
/**************************************************************************/
2
/* bone_map_editor_plugin.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 "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
/* Bone picker */
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
/* For auto mapping */
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
};
223
224