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