Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/import/3d/scene_import_settings.h
21679 views
1
/**************************************************************************/
2
/* scene_import_settings.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/import/3d/resource_importer_scene.h"
34
#include "scene/3d/camera_3d.h"
35
#include "scene/3d/light_3d.h"
36
#include "scene/3d/mesh_instance_3d.h"
37
#include "scene/3d/skeleton_3d.h"
38
#include "scene/gui/dialogs.h"
39
#include "scene/gui/menu_button.h"
40
#include "scene/gui/option_button.h"
41
#include "scene/gui/panel_container.h"
42
#include "scene/gui/slider.h"
43
#include "scene/gui/split_container.h"
44
#include "scene/gui/tab_container.h"
45
#include "scene/gui/tree.h"
46
#include "scene/resources/3d/primitive_meshes.h"
47
#include "scene/resources/3d/sky_material.h"
48
49
class EditorFileDialog;
50
class EditorInspector;
51
class SceneImportSettingsData;
52
class Timer;
53
54
class SceneImportSettingsDialog : public ConfirmationDialog {
55
GDCLASS(SceneImportSettingsDialog, ConfirmationDialog)
56
57
static SceneImportSettingsDialog *singleton;
58
59
enum Actions {
60
ACTION_EXTRACT_MATERIALS,
61
ACTION_CHOOSE_MESH_SAVE_PATHS,
62
ACTION_CHOOSE_ANIMATION_SAVE_PATHS,
63
};
64
65
Node *scene = nullptr;
66
67
HSplitContainer *tree_split = nullptr;
68
HSplitContainer *property_split = nullptr;
69
TabContainer *data_mode = nullptr;
70
Tree *scene_tree = nullptr;
71
Tree *mesh_tree = nullptr;
72
Tree *material_tree = nullptr;
73
74
EditorInspector *inspector = nullptr;
75
76
SubViewport *base_viewport = nullptr;
77
78
Camera3D *camera = nullptr;
79
Ref<CameraAttributesPractical> camera_attributes;
80
Ref<Environment> environment;
81
Ref<Sky> sky;
82
Ref<ProceduralSkyMaterial> procedural_sky_material;
83
bool first_aabb = false;
84
AABB contents_aabb;
85
86
Button *light_1_switch = nullptr;
87
Button *light_2_switch = nullptr;
88
Button *light_rotate_switch = nullptr;
89
90
struct ThemeCache {
91
Ref<Texture2D> light_1_icon;
92
Ref<Texture2D> light_2_icon;
93
Ref<Texture2D> rotate_icon;
94
} theme_cache;
95
96
DirectionalLight3D *light1 = nullptr;
97
DirectionalLight3D *light2 = nullptr;
98
Ref<ArrayMesh> selection_mesh;
99
MeshInstance3D *node_selected = nullptr;
100
101
MeshInstance3D *mesh_preview = nullptr;
102
Ref<SphereMesh> material_preview;
103
104
AnimationPlayer *animation_player = nullptr;
105
List<Skeleton3D *> skeletons;
106
PanelContainer *animation_preview = nullptr;
107
HSlider *animation_slider = nullptr;
108
Button *animation_play_button = nullptr;
109
Button *animation_stop_button = nullptr;
110
Button *animation_toggle_skeleton_visibility = nullptr;
111
Animation::LoopMode animation_loop_mode = Animation::LOOP_NONE;
112
bool animation_pingpong = false;
113
bool previous_import_as_skeleton = false;
114
bool previous_rest_as_reset = false;
115
MeshInstance3D *bones_mesh_preview = nullptr;
116
117
Ref<StandardMaterial3D> collider_mat;
118
119
float cam_rot_x = 0.0f;
120
float cam_rot_y = 0.0f;
121
float cam_zoom = 0.0f;
122
123
void _update_scene();
124
125
struct MaterialData {
126
bool has_import_id;
127
Ref<Material> material;
128
TreeItem *scene_node = nullptr;
129
TreeItem *mesh_node = nullptr;
130
TreeItem *material_node = nullptr;
131
132
float cam_rot_x = -Math::PI / 4;
133
float cam_rot_y = -Math::PI / 4;
134
float cam_zoom = 1;
135
136
HashMap<StringName, Variant> settings;
137
};
138
HashMap<String, MaterialData> material_map;
139
HashMap<Ref<Material>, String> unnamed_material_name_map;
140
141
struct MeshData {
142
bool has_import_id;
143
Ref<Mesh> mesh;
144
TreeItem *scene_node = nullptr;
145
TreeItem *mesh_node = nullptr;
146
147
float cam_rot_x = -Math::PI / 4;
148
float cam_rot_y = -Math::PI / 4;
149
float cam_zoom = 1;
150
HashMap<StringName, Variant> settings;
151
};
152
HashMap<String, MeshData> mesh_map;
153
154
struct AnimationData {
155
Ref<Animation> animation;
156
TreeItem *scene_node = nullptr;
157
HashMap<StringName, Variant> settings;
158
};
159
HashMap<String, AnimationData> animation_map;
160
161
struct NodeData {
162
Node *node = nullptr;
163
TreeItem *scene_node = nullptr;
164
HashMap<StringName, Variant> settings;
165
};
166
HashMap<String, NodeData> node_map;
167
168
bool _get_current(const StringName &p_name, Variant &r_ret) const;
169
void _set_default(const StringName &p_name, const Variant &p_value);
170
void _fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent);
171
void _fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent);
172
void _fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent);
173
void _fill_scene(Node *p_node, TreeItem *p_parent_item);
174
175
HashSet<Ref<Mesh>> mesh_set;
176
177
String selected_type;
178
String selected_id;
179
180
bool selecting = false;
181
182
void _update_view_gizmos();
183
void _update_camera();
184
void _select(Tree *p_from, const String &p_type, const String &p_id);
185
void _inspector_property_edited(const String &p_name);
186
void _reset_bone_transforms();
187
void _play_animation();
188
void _stop_current_animation();
189
void _reset_animation(const String &p_animation_name = "");
190
void _animation_slider_value_changed(double p_value);
191
void _animation_finished(const StringName &p_name);
192
void _animation_update_skeleton_visibility();
193
void _material_tree_selected();
194
void _mesh_tree_selected();
195
void _scene_tree_selected();
196
void _skeleton_tree_entered(Skeleton3D *p_skeleton);
197
void _cleanup();
198
void _on_light_1_switch_pressed();
199
void _on_light_2_switch_pressed();
200
void _on_light_rotate_switch_pressed();
201
202
void _viewport_input(const Ref<InputEvent> &p_input);
203
204
HashMap<StringName, Variant> defaults;
205
206
SceneImportSettingsData *scene_import_settings_data = nullptr;
207
ResourceImporterScene *_resource_importer_scene = nullptr;
208
209
void _re_import();
210
void _project_settings_changed();
211
212
String base_path;
213
214
MenuButton *action_menu = nullptr;
215
216
ConfirmationDialog *external_paths = nullptr;
217
Tree *external_path_tree = nullptr;
218
EditorFileDialog *save_path = nullptr;
219
OptionButton *external_extension_type = nullptr;
220
221
EditorFileDialog *item_save_path = nullptr;
222
223
void _menu_callback(int p_id);
224
void _save_dir_callback(const String &p_path);
225
226
int current_action = 0;
227
228
Vector<TreeItem *> save_path_items;
229
230
TreeItem *save_path_item = nullptr;
231
void _save_path_changed(const String &p_path);
232
void _browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button);
233
void _save_dir_confirm();
234
235
Dictionary base_subresource_settings;
236
237
void _load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category);
238
239
bool generate_collider = false;
240
241
Timer *update_view_timer = nullptr;
242
243
protected:
244
virtual void _update_theme_item_cache() override;
245
void _notification(int p_what);
246
247
public:
248
ResourceImporterScene *get_resource_importer_scene() const { return _resource_importer_scene; }
249
void request_generate_collider();
250
void update_view();
251
void open_settings(const String &p_path, const String &p_scene_import_type = "PackedScene");
252
static SceneImportSettingsDialog *get_singleton();
253
Node *get_selected_node();
254
SceneImportSettingsDialog();
255
~SceneImportSettingsDialog();
256
};
257
258