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