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
9903 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
int button_id = -1;
82
StringName profile_bone_name;
83
84
Ref<BoneMap> bone_map;
85
86
EditorPropertyText *skeleton_bone_selector = nullptr;
87
Button *picker_button = nullptr;
88
89
void _update_property();
90
void _open_picker();
91
92
protected:
93
void _notification(int p_what);
94
static void _bind_methods();
95
virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);
96
virtual void create_editor();
97
98
public:
99
void assign_button_id(int p_button_id);
100
101
BoneMapperItem(Ref<BoneMap> &p_bone_map, const StringName &p_profile_bone_name = StringName());
102
};
103
104
class BonePicker : public AcceptDialog {
105
GDCLASS(BonePicker, AcceptDialog);
106
107
Skeleton3D *skeleton = nullptr;
108
Tree *bones = nullptr;
109
110
public:
111
void popup_bones_tree(const Size2i &p_minsize = Size2i());
112
bool has_selected_bone();
113
StringName get_selected_bone();
114
115
protected:
116
void _notification(int p_what);
117
void _confirm();
118
119
private:
120
void create_editors();
121
void create_bones_tree(Skeleton3D *p_skeleton);
122
123
public:
124
BonePicker(Skeleton3D *p_skeleton);
125
};
126
127
class BoneMapper : public VBoxContainer {
128
GDCLASS(BoneMapper, VBoxContainer);
129
130
Skeleton3D *skeleton = nullptr;
131
Ref<BoneMap> bone_map;
132
133
EditorPropertyResource *profile_selector = nullptr;
134
135
Vector<BoneMapperItem *> bone_mapper_items;
136
137
Button *clear_mapping_button = nullptr;
138
139
VBoxContainer *mapper_item_vbox = nullptr;
140
141
int current_group_idx = 0;
142
int current_bone_idx = -1;
143
144
AspectRatioContainer *bone_mapper_field = nullptr;
145
EditorPropertyEnum *profile_group_selector = nullptr;
146
ColorRect *profile_bg = nullptr;
147
TextureRect *profile_texture = nullptr;
148
Vector<BoneMapperButton *> bone_mapper_buttons;
149
150
void create_editor();
151
void recreate_editor();
152
void clear_items();
153
void recreate_items();
154
void update_group_idx();
155
void _update_state();
156
157
/* Bone picker */
158
BonePicker *picker = nullptr;
159
StringName picker_key_name;
160
void _pick_bone(const StringName &p_bone_name);
161
void _apply_picker_selection();
162
void _clear_mapping_current_group();
163
164
/* For auto mapping */
165
enum BoneSegregation {
166
BONE_SEGREGATION_NONE,
167
BONE_SEGREGATION_LEFT,
168
BONE_SEGREGATION_RIGHT
169
};
170
bool is_match_with_bone_name(const String &p_bone_name, const String &p_word);
171
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);
172
BoneSegregation guess_bone_segregation(const String &p_bone_name);
173
void auto_mapping_process(Ref<BoneMap> &p_bone_map);
174
void _run_auto_mapping();
175
176
protected:
177
void _notification(int p_what);
178
static void _bind_methods();
179
virtual void _value_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);
180
virtual void _profile_changed(const String &p_property, const Variant &p_value, const String &p_name, bool p_changing);
181
182
public:
183
void set_current_group_idx(int p_group_idx);
184
int get_current_group_idx() const;
185
void set_current_bone_idx(int p_bone_idx);
186
int get_current_bone_idx() const;
187
188
BoneMapper(Skeleton3D *p_skeleton, Ref<BoneMap> &p_bone_map);
189
};
190
191
class BoneMapEditor : public VBoxContainer {
192
GDCLASS(BoneMapEditor, VBoxContainer);
193
194
Skeleton3D *skeleton = nullptr;
195
Ref<BoneMap> bone_map;
196
BoneMapper *bone_mapper = nullptr;
197
198
void fetch_objects();
199
void create_editors();
200
201
protected:
202
void _notification(int p_what);
203
204
public:
205
BoneMapEditor(Ref<BoneMap> &p_bone_map);
206
};
207
208
class EditorInspectorPluginBoneMap : public EditorInspectorPlugin {
209
GDCLASS(EditorInspectorPluginBoneMap, EditorInspectorPlugin);
210
BoneMapEditor *editor = nullptr;
211
212
public:
213
virtual bool can_handle(Object *p_object) override;
214
virtual void parse_begin(Object *p_object) override;
215
};
216
217
class BoneMapEditorPlugin : public EditorPlugin {
218
GDCLASS(BoneMapEditorPlugin, EditorPlugin);
219
220
public:
221
virtual String get_plugin_name() const override { return "BoneMap"; }
222
BoneMapEditorPlugin();
223
};
224
225