scene_import_settings.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  1. /*************************************************************************/
  2. /* scene_import_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "scene_import_settings.h"
  31. #include "editor/editor_node.h"
  32. #include "editor/editor_scale.h"
  33. #include "editor/import/scene_importer_mesh_node_3d.h"
  34. #include "scene/resources/surface_tool.h"
  35. class SceneImportSettingsData : public Object {
  36. GDCLASS(SceneImportSettingsData, Object)
  37. friend class SceneImportSettings;
  38. Map<StringName, Variant> *settings = nullptr;
  39. Map<StringName, Variant> current;
  40. Map<StringName, Variant> defaults;
  41. List<ResourceImporter::ImportOption> options;
  42. ResourceImporterScene::InternalImportCategory category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX;
  43. bool _set(const StringName &p_name, const Variant &p_value) {
  44. if (settings) {
  45. if (defaults.has(p_name) && defaults[p_name] == p_value) {
  46. settings->erase(p_name);
  47. } else {
  48. (*settings)[p_name] = p_value;
  49. }
  50. current[p_name] = p_value;
  51. return true;
  52. }
  53. return false;
  54. }
  55. bool _get(const StringName &p_name, Variant &r_ret) const {
  56. if (settings) {
  57. if (settings->has(p_name)) {
  58. r_ret = (*settings)[p_name];
  59. return true;
  60. }
  61. }
  62. if (defaults.has(p_name)) {
  63. r_ret = defaults[p_name];
  64. return true;
  65. }
  66. return false;
  67. }
  68. void _get_property_list(List<PropertyInfo> *p_list) const {
  69. for (const ResourceImporter::ImportOption &E : options) {
  70. if (ResourceImporterScene::get_singleton()->get_internal_option_visibility(category, E.option.name, current)) {
  71. p_list->push_back(E.option);
  72. }
  73. }
  74. }
  75. };
  76. void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent) {
  77. String import_id;
  78. bool has_import_id = false;
  79. if (p_material->has_meta("import_id")) {
  80. import_id = p_material->get_meta("import_id");
  81. has_import_id = true;
  82. } else if (p_material->get_name() != "") {
  83. import_id = p_material->get_name();
  84. has_import_id = true;
  85. } else {
  86. import_id = "@MATERIAL:" + itos(material_set.size());
  87. }
  88. if (!material_map.has(import_id)) {
  89. MaterialData md;
  90. md.has_import_id = has_import_id;
  91. md.material = p_material;
  92. _load_default_subresource_settings(md.settings, "materials", import_id, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MATERIAL);
  93. material_map[import_id] = md;
  94. }
  95. MaterialData &material_data = material_map[import_id];
  96. Ref<Texture2D> icon = get_theme_icon(SNAME("StandardMaterial3D"), SNAME("EditorIcons"));
  97. TreeItem *item = p_tree->create_item(p_parent);
  98. item->set_text(0, p_material->get_name());
  99. item->set_icon(0, icon);
  100. bool created = false;
  101. if (!material_set.has(p_material)) {
  102. material_set.insert(p_material);
  103. created = true;
  104. }
  105. item->set_meta("type", "Material");
  106. item->set_meta("import_id", import_id);
  107. item->set_tooltip(0, vformat(TTR("Import ID: %s"), import_id));
  108. item->set_selectable(0, true);
  109. if (p_tree == scene_tree) {
  110. material_data.scene_node = item;
  111. } else if (p_tree == mesh_tree) {
  112. material_data.mesh_node = item;
  113. } else {
  114. material_data.material_node = item;
  115. }
  116. if (created) {
  117. _fill_material(material_tree, p_material, material_tree->get_root());
  118. }
  119. }
  120. void SceneImportSettings::_fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent) {
  121. String import_id;
  122. bool has_import_id = false;
  123. if (p_mesh->has_meta("import_id")) {
  124. import_id = p_mesh->get_meta("import_id");
  125. has_import_id = true;
  126. } else if (p_mesh->get_name() != String()) {
  127. import_id = p_mesh->get_name();
  128. has_import_id = true;
  129. } else {
  130. import_id = "@MESH:" + itos(mesh_set.size());
  131. }
  132. if (!mesh_map.has(import_id)) {
  133. MeshData md;
  134. md.has_import_id = has_import_id;
  135. md.mesh = p_mesh;
  136. _load_default_subresource_settings(md.settings, "meshes", import_id, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH);
  137. mesh_map[import_id] = md;
  138. }
  139. MeshData &mesh_data = mesh_map[import_id];
  140. Ref<Texture2D> icon = get_theme_icon(SNAME("Mesh"), SNAME("EditorIcons"));
  141. TreeItem *item = p_tree->create_item(p_parent);
  142. item->set_text(0, p_mesh->get_name());
  143. item->set_icon(0, icon);
  144. bool created = false;
  145. if (!mesh_set.has(p_mesh)) {
  146. mesh_set.insert(p_mesh);
  147. created = true;
  148. }
  149. item->set_meta("type", "Mesh");
  150. item->set_meta("import_id", import_id);
  151. item->set_tooltip(0, vformat(TTR("Import ID: %s"), import_id));
  152. item->set_selectable(0, true);
  153. if (p_tree == scene_tree) {
  154. mesh_data.scene_node = item;
  155. } else {
  156. mesh_data.mesh_node = item;
  157. }
  158. item->set_collapsed(true);
  159. for (int i = 0; i < p_mesh->get_surface_count(); i++) {
  160. Ref<Material> mat = p_mesh->surface_get_material(i);
  161. if (mat.is_valid()) {
  162. _fill_material(p_tree, mat, item);
  163. }
  164. }
  165. if (created) {
  166. _fill_mesh(mesh_tree, p_mesh, mesh_tree->get_root());
  167. }
  168. }
  169. void SceneImportSettings::_fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent) {
  170. if (!animation_map.has(p_name)) {
  171. AnimationData ad;
  172. ad.animation = p_anim;
  173. _load_default_subresource_settings(ad.settings, "animations", p_name, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION);
  174. animation_map[p_name] = ad;
  175. }
  176. AnimationData &animation_data = animation_map[p_name];
  177. Ref<Texture2D> icon = get_theme_icon(SNAME("Animation"), SNAME("EditorIcons"));
  178. TreeItem *item = p_tree->create_item(p_parent);
  179. item->set_text(0, p_name);
  180. item->set_icon(0, icon);
  181. item->set_meta("type", "Animation");
  182. item->set_meta("import_id", p_name);
  183. item->set_selectable(0, true);
  184. animation_data.scene_node = item;
  185. }
  186. void SceneImportSettings::_fill_scene(Node *p_node, TreeItem *p_parent_item) {
  187. String import_id;
  188. if (p_node->has_meta("import_id")) {
  189. import_id = p_node->get_meta("import_id");
  190. } else {
  191. import_id = "PATH:" + String(scene->get_path_to(p_node));
  192. p_node->set_meta("import_id", import_id);
  193. }
  194. EditorSceneImporterMeshNode3D *src_mesh_node = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
  195. if (src_mesh_node) {
  196. MeshInstance3D *mesh_node = memnew(MeshInstance3D);
  197. mesh_node->set_name(src_mesh_node->get_name());
  198. mesh_node->set_transform(src_mesh_node->get_transform());
  199. mesh_node->set_skin(src_mesh_node->get_skin());
  200. mesh_node->set_skeleton_path(src_mesh_node->get_skeleton_path());
  201. if (src_mesh_node->get_mesh().is_valid()) {
  202. Ref<EditorSceneImporterMesh> editor_mesh = src_mesh_node->get_mesh();
  203. mesh_node->set_mesh(editor_mesh->get_mesh());
  204. }
  205. p_node->replace_by(mesh_node);
  206. memdelete(p_node);
  207. p_node = mesh_node;
  208. }
  209. String type = p_node->get_class();
  210. if (!has_theme_icon(type, SNAME("EditorIcons"))) {
  211. type = "Node3D";
  212. }
  213. Ref<Texture2D> icon = get_theme_icon(type, SNAME("EditorIcons"));
  214. TreeItem *item = scene_tree->create_item(p_parent_item);
  215. item->set_text(0, p_node->get_name());
  216. if (p_node == scene) {
  217. icon = get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons"));
  218. item->set_text(0, "Scene");
  219. }
  220. item->set_icon(0, icon);
  221. item->set_meta("type", "Node");
  222. item->set_meta("class", type);
  223. item->set_meta("import_id", import_id);
  224. item->set_tooltip(0, vformat(TTR("Type: %s\nImport ID: %s"), type, import_id));
  225. item->set_selectable(0, true);
  226. if (!node_map.has(import_id)) {
  227. NodeData nd;
  228. if (p_node != scene) {
  229. ResourceImporterScene::InternalImportCategory category;
  230. if (src_mesh_node) {
  231. category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;
  232. } else if (Object::cast_to<AnimationPlayer>(p_node)) {
  233. category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;
  234. } else {
  235. category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;
  236. }
  237. _load_default_subresource_settings(nd.settings, "nodes", import_id, category);
  238. }
  239. node_map[import_id] = nd;
  240. }
  241. NodeData &node_data = node_map[import_id];
  242. node_data.node = p_node;
  243. node_data.scene_node = item;
  244. AnimationPlayer *anim_node = Object::cast_to<AnimationPlayer>(p_node);
  245. if (anim_node) {
  246. List<StringName> animations;
  247. anim_node->get_animation_list(&animations);
  248. for (const StringName &E : animations) {
  249. _fill_animation(scene_tree, anim_node->get_animation(E), E, item);
  250. }
  251. }
  252. for (int i = 0; i < p_node->get_child_count(); i++) {
  253. _fill_scene(p_node->get_child(i), item);
  254. }
  255. MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(p_node);
  256. if (mesh_node && mesh_node->get_mesh().is_valid()) {
  257. _fill_mesh(scene_tree, mesh_node->get_mesh(), item);
  258. Transform3D accum_xform;
  259. Node3D *base = mesh_node;
  260. while (base) {
  261. accum_xform = base->get_transform() * accum_xform;
  262. base = Object::cast_to<Node3D>(base->get_parent());
  263. }
  264. AABB aabb = accum_xform.xform(mesh_node->get_mesh()->get_aabb());
  265. if (first_aabb) {
  266. contents_aabb = aabb;
  267. first_aabb = false;
  268. } else {
  269. contents_aabb.merge_with(aabb);
  270. }
  271. }
  272. }
  273. void SceneImportSettings::_update_scene() {
  274. scene_tree->clear();
  275. material_tree->clear();
  276. mesh_tree->clear();
  277. //hidden roots
  278. material_tree->create_item();
  279. mesh_tree->create_item();
  280. _fill_scene(scene, nullptr);
  281. }
  282. void SceneImportSettings::_update_camera() {
  283. AABB camera_aabb;
  284. float rot_x = cam_rot_x;
  285. float rot_y = cam_rot_y;
  286. float zoom = cam_zoom;
  287. if (selected_type == "Node" || selected_type == "") {
  288. camera_aabb = contents_aabb;
  289. } else {
  290. if (mesh_preview->get_mesh().is_valid()) {
  291. camera_aabb = mesh_preview->get_transform().xform(mesh_preview->get_mesh()->get_aabb());
  292. } else {
  293. camera_aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
  294. }
  295. if (selected_type == "Mesh" && mesh_map.has(selected_id)) {
  296. const MeshData &md = mesh_map[selected_id];
  297. rot_x = md.cam_rot_x;
  298. rot_y = md.cam_rot_y;
  299. zoom = md.cam_zoom;
  300. } else if (selected_type == "Material" && material_map.has(selected_id)) {
  301. const MaterialData &md = material_map[selected_id];
  302. rot_x = md.cam_rot_x;
  303. rot_y = md.cam_rot_y;
  304. zoom = md.cam_zoom;
  305. }
  306. }
  307. Vector3 center = camera_aabb.position + camera_aabb.size * 0.5;
  308. float camera_size = camera_aabb.get_longest_axis_size();
  309. camera->set_orthogonal(camera_size * zoom, 0.0001, camera_size * 2);
  310. Transform3D xf;
  311. xf.basis = Basis(Vector3(0, 1, 0), rot_y) * Basis(Vector3(1, 0, 0), rot_x);
  312. xf.origin = center;
  313. xf.translate(0, 0, camera_size);
  314. camera->set_transform(xf);
  315. }
  316. void SceneImportSettings::_load_default_subresource_settings(Map<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category) {
  317. if (base_subresource_settings.has(p_type)) {
  318. Dictionary d = base_subresource_settings[p_type];
  319. if (d.has(p_import_id)) {
  320. d = d[p_import_id];
  321. List<ResourceImporterScene::ImportOption> options;
  322. ResourceImporterScene::get_singleton()->get_internal_import_options(p_category, &options);
  323. for (const ResourceImporterScene::ImportOption &E : options) {
  324. String key = E.option.name;
  325. if (d.has(key)) {
  326. settings[key] = d[key];
  327. }
  328. }
  329. }
  330. }
  331. }
  332. void SceneImportSettings::open_settings(const String &p_path) {
  333. if (scene) {
  334. memdelete(scene);
  335. scene = nullptr;
  336. }
  337. scene = ResourceImporterScene::get_singleton()->pre_import(p_path);
  338. if (scene == nullptr) {
  339. EditorNode::get_singleton()->show_warning(TTR("Error opening scene"));
  340. return;
  341. }
  342. base_path = p_path;
  343. material_set.clear();
  344. mesh_set.clear();
  345. material_map.clear();
  346. mesh_map.clear();
  347. node_map.clear();
  348. defaults.clear();
  349. selected_id = "";
  350. selected_type = "";
  351. cam_rot_x = -Math_PI / 4;
  352. cam_rot_y = -Math_PI / 4;
  353. cam_zoom = 1;
  354. {
  355. base_subresource_settings.clear();
  356. Ref<ConfigFile> config;
  357. config.instantiate();
  358. Error err = config->load(p_path + ".import");
  359. if (err == OK) {
  360. List<String> keys;
  361. config->get_section_keys("params", &keys);
  362. for (const String &E : keys) {
  363. Variant value = config->get_value("params", E);
  364. if (E == "_subresources") {
  365. base_subresource_settings = value;
  366. } else {
  367. defaults[E] = value;
  368. }
  369. }
  370. }
  371. }
  372. first_aabb = true;
  373. _update_scene();
  374. base_viewport->add_child(scene);
  375. if (first_aabb) {
  376. contents_aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
  377. first_aabb = false;
  378. }
  379. popup_centered_ratio();
  380. _update_camera();
  381. set_title(vformat(TTR("Advanced Import Settings for '%s'"), base_path.get_file()));
  382. }
  383. SceneImportSettings *SceneImportSettings::singleton = nullptr;
  384. SceneImportSettings *SceneImportSettings::get_singleton() {
  385. return singleton;
  386. }
  387. void SceneImportSettings::_select(Tree *p_from, String p_type, String p_id) {
  388. selecting = true;
  389. if (p_type == "Node") {
  390. node_selected->hide(); //always hide just in case
  391. mesh_preview->hide();
  392. if (Object::cast_to<Node3D>(scene)) {
  393. Object::cast_to<Node3D>(scene)->show();
  394. }
  395. //NodeData &nd=node_map[p_id];
  396. material_tree->deselect_all();
  397. mesh_tree->deselect_all();
  398. NodeData &nd = node_map[p_id];
  399. MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(nd.node);
  400. if (mi) {
  401. Ref<Mesh> base_mesh = mi->get_mesh();
  402. if (base_mesh.is_valid()) {
  403. AABB aabb = base_mesh->get_aabb();
  404. Transform3D aabb_xf;
  405. aabb_xf.basis.scale(aabb.size);
  406. aabb_xf.origin = aabb.position;
  407. aabb_xf = mi->get_global_transform() * aabb_xf;
  408. node_selected->set_transform(aabb_xf);
  409. node_selected->show();
  410. }
  411. }
  412. if (nd.node == scene) {
  413. scene_import_settings_data->settings = &defaults;
  414. scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX;
  415. } else {
  416. scene_import_settings_data->settings = &nd.settings;
  417. if (mi) {
  418. scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;
  419. } else if (Object::cast_to<AnimationPlayer>(nd.node)) {
  420. scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;
  421. } else {
  422. scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;
  423. }
  424. }
  425. } else if (p_type == "Animation") {
  426. node_selected->hide(); //always hide just in case
  427. mesh_preview->hide();
  428. if (Object::cast_to<Node3D>(scene)) {
  429. Object::cast_to<Node3D>(scene)->show();
  430. }
  431. //NodeData &nd=node_map[p_id];
  432. material_tree->deselect_all();
  433. mesh_tree->deselect_all();
  434. AnimationData &ad = animation_map[p_id];
  435. scene_import_settings_data->settings = &ad.settings;
  436. scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION;
  437. } else if (p_type == "Mesh") {
  438. node_selected->hide();
  439. if (Object::cast_to<Node3D>(scene)) {
  440. Object::cast_to<Node3D>(scene)->hide();
  441. }
  442. MeshData &md = mesh_map[p_id];
  443. if (p_from != mesh_tree) {
  444. md.mesh_node->uncollapse_tree();
  445. md.mesh_node->select(0);
  446. mesh_tree->ensure_cursor_is_visible();
  447. }
  448. if (p_from != scene_tree) {
  449. md.scene_node->uncollapse_tree();
  450. md.scene_node->select(0);
  451. scene_tree->ensure_cursor_is_visible();
  452. }
  453. mesh_preview->set_mesh(md.mesh);
  454. mesh_preview->show();
  455. material_tree->deselect_all();
  456. scene_import_settings_data->settings = &md.settings;
  457. scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH;
  458. } else if (p_type == "Material") {
  459. node_selected->hide();
  460. if (Object::cast_to<Node3D>(scene)) {
  461. Object::cast_to<Node3D>(scene)->hide();
  462. }
  463. mesh_preview->show();
  464. MaterialData &md = material_map[p_id];
  465. material_preview->set_material(md.material);
  466. mesh_preview->set_mesh(material_preview);
  467. if (p_from != mesh_tree) {
  468. md.mesh_node->uncollapse_tree();
  469. md.mesh_node->select(0);
  470. mesh_tree->ensure_cursor_is_visible();
  471. }
  472. if (p_from != scene_tree) {
  473. md.scene_node->uncollapse_tree();
  474. md.scene_node->select(0);
  475. scene_tree->ensure_cursor_is_visible();
  476. }
  477. if (p_from != material_tree) {
  478. md.material_node->uncollapse_tree();
  479. md.material_node->select(0);
  480. material_tree->ensure_cursor_is_visible();
  481. }
  482. scene_import_settings_data->settings = &md.settings;
  483. scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MATERIAL;
  484. }
  485. selected_type = p_type;
  486. selected_id = p_id;
  487. selecting = false;
  488. _update_camera();
  489. List<ResourceImporter::ImportOption> options;
  490. if (scene_import_settings_data->category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
  491. ResourceImporterScene::get_singleton()->get_import_options(&options);
  492. } else {
  493. ResourceImporterScene::get_singleton()->get_internal_import_options(scene_import_settings_data->category, &options);
  494. }
  495. scene_import_settings_data->defaults.clear();
  496. scene_import_settings_data->current.clear();
  497. for (const ResourceImporter::ImportOption &E : options) {
  498. scene_import_settings_data->defaults[E.option.name] = E.default_value;
  499. //needed for visibility toggling (fails if something is missing)
  500. if (scene_import_settings_data->settings->has(E.option.name)) {
  501. scene_import_settings_data->current[E.option.name] = (*scene_import_settings_data->settings)[E.option.name];
  502. } else {
  503. scene_import_settings_data->current[E.option.name] = E.default_value;
  504. }
  505. }
  506. scene_import_settings_data->options = options;
  507. inspector->edit(scene_import_settings_data);
  508. scene_import_settings_data->notify_property_list_changed();
  509. }
  510. void SceneImportSettings::_material_tree_selected() {
  511. if (selecting) {
  512. return;
  513. }
  514. TreeItem *item = material_tree->get_selected();
  515. String type = item->get_meta("type");
  516. String import_id = item->get_meta("import_id");
  517. _select(material_tree, type, import_id);
  518. }
  519. void SceneImportSettings::_mesh_tree_selected() {
  520. if (selecting) {
  521. return;
  522. }
  523. TreeItem *item = mesh_tree->get_selected();
  524. String type = item->get_meta("type");
  525. String import_id = item->get_meta("import_id");
  526. _select(mesh_tree, type, import_id);
  527. }
  528. void SceneImportSettings::_scene_tree_selected() {
  529. if (selecting) {
  530. return;
  531. }
  532. TreeItem *item = scene_tree->get_selected();
  533. String type = item->get_meta("type");
  534. String import_id = item->get_meta("import_id");
  535. _select(scene_tree, type, import_id);
  536. }
  537. void SceneImportSettings::_viewport_input(const Ref<InputEvent> &p_input) {
  538. float *rot_x = &cam_rot_x;
  539. float *rot_y = &cam_rot_y;
  540. float *zoom = &cam_zoom;
  541. if (selected_type == "Mesh" && mesh_map.has(selected_id)) {
  542. MeshData &md = mesh_map[selected_id];
  543. rot_x = &md.cam_rot_x;
  544. rot_y = &md.cam_rot_y;
  545. zoom = &md.cam_zoom;
  546. } else if (selected_type == "Material" && material_map.has(selected_id)) {
  547. MaterialData &md = material_map[selected_id];
  548. rot_x = &md.cam_rot_x;
  549. rot_y = &md.cam_rot_y;
  550. zoom = &md.cam_zoom;
  551. }
  552. Ref<InputEventMouseMotion> mm = p_input;
  553. if (mm.is_valid() && mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT) {
  554. (*rot_x) -= mm->get_relative().y * 0.01 * EDSCALE;
  555. (*rot_y) -= mm->get_relative().x * 0.01 * EDSCALE;
  556. (*rot_x) = CLAMP((*rot_x), -Math_PI / 2, Math_PI / 2);
  557. _update_camera();
  558. }
  559. Ref<InputEventMouseButton> mb = p_input;
  560. if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) {
  561. (*zoom) *= 1.1;
  562. if ((*zoom) > 10.0) {
  563. (*zoom) = 10.0;
  564. }
  565. _update_camera();
  566. }
  567. if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) {
  568. (*zoom) /= 1.1;
  569. if ((*zoom) < 0.1) {
  570. (*zoom) = 0.1;
  571. }
  572. _update_camera();
  573. }
  574. }
  575. void SceneImportSettings::_re_import() {
  576. Map<StringName, Variant> main_settings;
  577. main_settings = defaults;
  578. main_settings.erase("_subresources");
  579. Dictionary nodes;
  580. Dictionary materials;
  581. Dictionary meshes;
  582. Dictionary animations;
  583. Dictionary subresources;
  584. for (Map<String, NodeData>::Element *E = node_map.front(); E; E = E->next()) {
  585. if (E->get().settings.size()) {
  586. Dictionary d;
  587. for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
  588. d[String(F->key())] = F->get();
  589. }
  590. nodes[E->key()] = d;
  591. }
  592. }
  593. if (nodes.size()) {
  594. subresources["nodes"] = nodes;
  595. }
  596. for (Map<String, MaterialData>::Element *E = material_map.front(); E; E = E->next()) {
  597. if (E->get().settings.size()) {
  598. Dictionary d;
  599. for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
  600. d[String(F->key())] = F->get();
  601. }
  602. materials[E->key()] = d;
  603. }
  604. }
  605. if (materials.size()) {
  606. subresources["materials"] = materials;
  607. }
  608. for (Map<String, MeshData>::Element *E = mesh_map.front(); E; E = E->next()) {
  609. if (E->get().settings.size()) {
  610. Dictionary d;
  611. for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
  612. d[String(F->key())] = F->get();
  613. }
  614. meshes[E->key()] = d;
  615. }
  616. }
  617. if (meshes.size()) {
  618. subresources["meshes"] = meshes;
  619. }
  620. for (Map<String, AnimationData>::Element *E = animation_map.front(); E; E = E->next()) {
  621. if (E->get().settings.size()) {
  622. Dictionary d;
  623. for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
  624. d[String(F->key())] = F->get();
  625. }
  626. animations[E->key()] = d;
  627. }
  628. }
  629. if (animations.size()) {
  630. subresources["animations"] = animations;
  631. }
  632. if (subresources.size()) {
  633. main_settings["_subresources"] = subresources;
  634. }
  635. EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, "scene", main_settings);
  636. }
  637. void SceneImportSettings::_notification(int p_what) {
  638. if (p_what == NOTIFICATION_READY) {
  639. connect("confirmed", callable_mp(this, &SceneImportSettings::_re_import));
  640. }
  641. }
  642. void SceneImportSettings::_menu_callback(int p_id) {
  643. switch (p_id) {
  644. case ACTION_EXTRACT_MATERIALS: {
  645. save_path->set_text(TTR("Select folder to extract material resources"));
  646. external_extension_type->select(0);
  647. } break;
  648. case ACTION_CHOOSE_MESH_SAVE_PATHS: {
  649. save_path->set_text(TTR("Select folder where mesh resources will save on import"));
  650. external_extension_type->select(1);
  651. } break;
  652. case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {
  653. save_path->set_text(TTR("Select folder where animations will save on import"));
  654. external_extension_type->select(1);
  655. } break;
  656. }
  657. save_path->set_current_dir(base_path.get_base_dir());
  658. current_action = p_id;
  659. save_path->popup_centered_ratio();
  660. }
  661. void SceneImportSettings::_save_path_changed(const String &p_path) {
  662. save_path_item->set_text(1, p_path);
  663. if (FileAccess::exists(p_path)) {
  664. save_path_item->set_text(2, "Warning: File exists");
  665. save_path_item->set_tooltip(2, TTR("Existing file with the same name will be replaced."));
  666. save_path_item->set_icon(2, get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
  667. } else {
  668. save_path_item->set_text(2, "Will create new File");
  669. save_path_item->set_icon(2, get_theme_icon(SNAME("StatusSuccess"), SNAME("EditorIcons")));
  670. }
  671. }
  672. void SceneImportSettings::_browse_save_callback(Object *p_item, int p_column, int p_id) {
  673. TreeItem *item = Object::cast_to<TreeItem>(p_item);
  674. String path = item->get_text(1);
  675. item_save_path->set_current_file(path);
  676. save_path_item = item;
  677. item_save_path->popup_centered_ratio();
  678. }
  679. void SceneImportSettings::_save_dir_callback(const String &p_path) {
  680. external_path_tree->clear();
  681. TreeItem *root = external_path_tree->create_item();
  682. save_path_items.clear();
  683. switch (current_action) {
  684. case ACTION_EXTRACT_MATERIALS: {
  685. for (Map<String, MaterialData>::Element *E = material_map.front(); E; E = E->next()) {
  686. MaterialData &md = material_map[E->key()];
  687. TreeItem *item = external_path_tree->create_item(root);
  688. String name = md.material_node->get_text(0);
  689. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  690. item->set_icon(0, get_theme_icon(SNAME("StandardMaterial3D"), SNAME("EditorIcons")));
  691. item->set_text(0, name);
  692. if (md.has_import_id) {
  693. if (md.settings.has("use_external/enabled") && bool(md.settings["use_external/enabled"])) {
  694. item->set_text(2, "Already External");
  695. item->set_tooltip(2, TTR("This material already references an external file, no action will be taken.\nDisable the external property for it to be extracted again."));
  696. } else {
  697. item->set_metadata(0, E->key());
  698. item->set_editable(0, true);
  699. item->set_checked(0, true);
  700. String path = p_path.plus_file(name);
  701. if (external_extension_type->get_selected() == 0) {
  702. path += ".tres";
  703. } else {
  704. path += ".res";
  705. }
  706. item->set_text(1, path);
  707. if (FileAccess::exists(path)) {
  708. item->set_text(2, "Warning: File exists");
  709. item->set_tooltip(2, TTR("Existing file with the same name will be replaced."));
  710. item->set_icon(2, get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
  711. } else {
  712. item->set_text(2, "Will create new File");
  713. item->set_icon(2, get_theme_icon(SNAME("StatusSuccess"), SNAME("EditorIcons")));
  714. }
  715. item->add_button(1, get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
  716. }
  717. } else {
  718. item->set_text(2, "No import ID");
  719. item->set_tooltip(2, TTR("Material has no name nor any other way to identify on re-import.\nPlease name it or ensure it is exported with an unique ID."));
  720. item->set_icon(2, get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons")));
  721. }
  722. save_path_items.push_back(item);
  723. }
  724. external_paths->set_title(TTR("Extract Materials to Resource Files"));
  725. external_paths->get_ok_button()->set_text(TTR("Extract"));
  726. } break;
  727. case ACTION_CHOOSE_MESH_SAVE_PATHS: {
  728. for (Map<String, MeshData>::Element *E = mesh_map.front(); E; E = E->next()) {
  729. MeshData &md = mesh_map[E->key()];
  730. TreeItem *item = external_path_tree->create_item(root);
  731. String name = md.mesh_node->get_text(0);
  732. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  733. item->set_icon(0, get_theme_icon(SNAME("Mesh"), SNAME("EditorIcons")));
  734. item->set_text(0, name);
  735. if (md.has_import_id) {
  736. if (md.settings.has("save_to_file/enabled") && bool(md.settings["save_to_file/enabled"])) {
  737. item->set_text(2, "Already Saving");
  738. item->set_tooltip(2, TTR("This mesh already saves to an external resource, no action will be taken."));
  739. } else {
  740. item->set_metadata(0, E->key());
  741. item->set_editable(0, true);
  742. item->set_checked(0, true);
  743. String path = p_path.plus_file(name);
  744. if (external_extension_type->get_selected() == 0) {
  745. path += ".tres";
  746. } else {
  747. path += ".res";
  748. }
  749. item->set_text(1, path);
  750. if (FileAccess::exists(path)) {
  751. item->set_text(2, "Warning: File exists");
  752. item->set_tooltip(2, TTR("Existing file with the same name will be replaced on import."));
  753. item->set_icon(2, get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
  754. } else {
  755. item->set_text(2, "Will save to new File");
  756. item->set_icon(2, get_theme_icon(SNAME("StatusSuccess"), SNAME("EditorIcons")));
  757. }
  758. item->add_button(1, get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
  759. }
  760. } else {
  761. item->set_text(2, "No import ID");
  762. item->set_tooltip(2, TTR("Mesh has no name nor any other way to identify on re-import.\nPlease name it or ensure it is exported with an unique ID."));
  763. item->set_icon(2, get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons")));
  764. }
  765. save_path_items.push_back(item);
  766. }
  767. external_paths->set_title(TTR("Set paths to save meshes as resource files on Reimport"));
  768. external_paths->get_ok_button()->set_text(TTR("Set Paths"));
  769. } break;
  770. case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {
  771. for (Map<String, AnimationData>::Element *E = animation_map.front(); E; E = E->next()) {
  772. AnimationData &ad = animation_map[E->key()];
  773. TreeItem *item = external_path_tree->create_item(root);
  774. String name = ad.scene_node->get_text(0);
  775. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  776. item->set_icon(0, get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")));
  777. item->set_text(0, name);
  778. if (ad.settings.has("save_to_file/enabled") && bool(ad.settings["save_to_file/enabled"])) {
  779. item->set_text(2, "Already Saving");
  780. item->set_tooltip(2, TTR("This animation already saves to an external resource, no action will be taken."));
  781. } else {
  782. item->set_metadata(0, E->key());
  783. item->set_editable(0, true);
  784. item->set_checked(0, true);
  785. String path = p_path.plus_file(name);
  786. if (external_extension_type->get_selected() == 0) {
  787. path += ".tres";
  788. } else {
  789. path += ".res";
  790. }
  791. item->set_text(1, path);
  792. if (FileAccess::exists(path)) {
  793. item->set_text(2, "Warning: File exists");
  794. item->set_tooltip(2, TTR("Existing file with the same name will be replaced on import."));
  795. item->set_icon(2, get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")));
  796. } else {
  797. item->set_text(2, "Will save to new File");
  798. item->set_icon(2, get_theme_icon(SNAME("StatusSuccess"), SNAME("EditorIcons")));
  799. }
  800. item->add_button(1, get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
  801. }
  802. save_path_items.push_back(item);
  803. }
  804. external_paths->set_title(TTR("Set paths to save animations as resource files on Reimport"));
  805. external_paths->get_ok_button()->set_text(TTR("Set Paths"));
  806. } break;
  807. }
  808. external_paths->popup_centered_ratio();
  809. }
  810. void SceneImportSettings::_save_dir_confirm() {
  811. for (int i = 0; i < save_path_items.size(); i++) {
  812. TreeItem *item = save_path_items[i];
  813. if (!item->is_checked(0)) {
  814. continue; //ignore
  815. }
  816. String path = item->get_text(1);
  817. if (!path.is_resource_file()) {
  818. continue;
  819. }
  820. String id = item->get_metadata(0);
  821. switch (current_action) {
  822. case ACTION_EXTRACT_MATERIALS: {
  823. ERR_CONTINUE(!material_map.has(id));
  824. MaterialData &md = material_map[id];
  825. Error err = ResourceSaver::save(path, md.material);
  826. if (err != OK) {
  827. EditorNode::get_singleton()->add_io_error(TTR("Can't make material external to file, write error:") + "\n\t" + path);
  828. continue;
  829. }
  830. md.settings["use_external/enabled"] = true;
  831. md.settings["use_external/path"] = path;
  832. } break;
  833. case ACTION_CHOOSE_MESH_SAVE_PATHS: {
  834. ERR_CONTINUE(!mesh_map.has(id));
  835. MeshData &md = mesh_map[id];
  836. md.settings["save_to_file/enabled"] = true;
  837. md.settings["save_to_file/path"] = path;
  838. } break;
  839. case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {
  840. ERR_CONTINUE(!animation_map.has(id));
  841. AnimationData &ad = animation_map[id];
  842. ad.settings["save_to_file/enabled"] = true;
  843. ad.settings["save_to_file/path"] = path;
  844. } break;
  845. }
  846. }
  847. if (current_action == ACTION_EXTRACT_MATERIALS) {
  848. //as this happens right now, the scene needs to be saved and reimported.
  849. _re_import();
  850. open_settings(base_path);
  851. } else {
  852. scene_import_settings_data->notify_property_list_changed();
  853. }
  854. }
  855. SceneImportSettings::SceneImportSettings() {
  856. singleton = this;
  857. VBoxContainer *main_vb = memnew(VBoxContainer);
  858. add_child(main_vb);
  859. HBoxContainer *menu_hb = memnew(HBoxContainer);
  860. main_vb->add_child(menu_hb);
  861. action_menu = memnew(MenuButton);
  862. action_menu->set_text(TTR("Actions..."));
  863. menu_hb->add_child(action_menu);
  864. action_menu->get_popup()->add_item(TTR("Extract Materials"), ACTION_EXTRACT_MATERIALS);
  865. action_menu->get_popup()->add_separator();
  866. action_menu->get_popup()->add_item(TTR("Set Animation Save Paths"), ACTION_CHOOSE_ANIMATION_SAVE_PATHS);
  867. action_menu->get_popup()->add_item(TTR("Set Mesh Save Paths"), ACTION_CHOOSE_MESH_SAVE_PATHS);
  868. action_menu->get_popup()->connect("id_pressed", callable_mp(this, &SceneImportSettings::_menu_callback));
  869. tree_split = memnew(HSplitContainer);
  870. main_vb->add_child(tree_split);
  871. tree_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  872. data_mode = memnew(TabContainer);
  873. tree_split->add_child(data_mode);
  874. data_mode->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
  875. property_split = memnew(HSplitContainer);
  876. tree_split->add_child(property_split);
  877. property_split->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  878. scene_tree = memnew(Tree);
  879. scene_tree->set_name(TTR("Scene"));
  880. data_mode->add_child(scene_tree);
  881. scene_tree->connect("cell_selected", callable_mp(this, &SceneImportSettings::_scene_tree_selected));
  882. mesh_tree = memnew(Tree);
  883. mesh_tree->set_name(TTR("Meshes"));
  884. data_mode->add_child(mesh_tree);
  885. mesh_tree->set_hide_root(true);
  886. mesh_tree->connect("cell_selected", callable_mp(this, &SceneImportSettings::_mesh_tree_selected));
  887. material_tree = memnew(Tree);
  888. material_tree->set_name(TTR("Materials"));
  889. data_mode->add_child(material_tree);
  890. material_tree->connect("cell_selected", callable_mp(this, &SceneImportSettings::_material_tree_selected));
  891. material_tree->set_hide_root(true);
  892. SubViewportContainer *vp_container = memnew(SubViewportContainer);
  893. vp_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  894. vp_container->set_custom_minimum_size(Size2(10, 10));
  895. vp_container->set_stretch(true);
  896. vp_container->connect("gui_input", callable_mp(this, &SceneImportSettings::_viewport_input));
  897. property_split->add_child(vp_container);
  898. base_viewport = memnew(SubViewport);
  899. vp_container->add_child(base_viewport);
  900. base_viewport->set_use_own_world_3d(true);
  901. camera = memnew(Camera3D);
  902. base_viewport->add_child(camera);
  903. camera->make_current();
  904. light = memnew(DirectionalLight3D);
  905. light->set_transform(Transform3D().looking_at(Vector3(-1, -2, -0.6), Vector3(0, 1, 0)));
  906. base_viewport->add_child(light);
  907. light->set_shadow(true);
  908. {
  909. Ref<StandardMaterial3D> selection_mat;
  910. selection_mat.instantiate();
  911. selection_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  912. selection_mat->set_albedo(Color(1, 0.8, 1.0));
  913. Ref<SurfaceTool> st;
  914. st.instantiate();
  915. st->begin(Mesh::PRIMITIVE_LINES);
  916. AABB base_aabb;
  917. base_aabb.size = Vector3(1, 1, 1);
  918. for (int i = 0; i < 12; i++) {
  919. Vector3 a, b;
  920. base_aabb.get_edge(i, a, b);
  921. st->add_vertex(a);
  922. st->add_vertex(a.lerp(b, 0.2));
  923. st->add_vertex(b);
  924. st->add_vertex(b.lerp(a, 0.2));
  925. }
  926. selection_mesh.instantiate();
  927. st->commit(selection_mesh);
  928. selection_mesh->surface_set_material(0, selection_mat);
  929. node_selected = memnew(MeshInstance3D);
  930. node_selected->set_mesh(selection_mesh);
  931. base_viewport->add_child(node_selected);
  932. node_selected->hide();
  933. }
  934. {
  935. mesh_preview = memnew(MeshInstance3D);
  936. base_viewport->add_child(mesh_preview);
  937. mesh_preview->hide();
  938. material_preview.instantiate();
  939. }
  940. inspector = memnew(EditorInspector);
  941. inspector->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
  942. property_split->add_child(inspector);
  943. scene_import_settings_data = memnew(SceneImportSettingsData);
  944. get_ok_button()->set_text(TTR("Reimport"));
  945. get_cancel_button()->set_text(TTR("Close"));
  946. external_paths = memnew(ConfirmationDialog);
  947. add_child(external_paths);
  948. external_path_tree = memnew(Tree);
  949. external_paths->add_child(external_path_tree);
  950. external_path_tree->connect("button_pressed", callable_mp(this, &SceneImportSettings::_browse_save_callback));
  951. external_paths->connect("confirmed", callable_mp(this, &SceneImportSettings::_save_dir_confirm));
  952. external_path_tree->set_columns(3);
  953. external_path_tree->set_column_titles_visible(true);
  954. external_path_tree->set_column_expand(0, true);
  955. external_path_tree->set_column_custom_minimum_width(0, 100 * EDSCALE);
  956. external_path_tree->set_column_title(0, TTR("Resource"));
  957. external_path_tree->set_column_expand(1, true);
  958. external_path_tree->set_column_custom_minimum_width(1, 100 * EDSCALE);
  959. external_path_tree->set_column_title(1, TTR("Path"));
  960. external_path_tree->set_column_expand(2, false);
  961. external_path_tree->set_column_custom_minimum_width(2, 200 * EDSCALE);
  962. external_path_tree->set_column_title(2, TTR("Status"));
  963. save_path = memnew(EditorFileDialog);
  964. save_path->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
  965. HBoxContainer *extension_hb = memnew(HBoxContainer);
  966. save_path->get_vbox()->add_child(extension_hb);
  967. extension_hb->add_spacer();
  968. extension_hb->add_child(memnew(Label(TTR("Save Extension: "))));
  969. external_extension_type = memnew(OptionButton);
  970. extension_hb->add_child(external_extension_type);
  971. external_extension_type->add_item(TTR("Text: *.tres"));
  972. external_extension_type->add_item(TTR("Binary: *.res"));
  973. external_path_tree->set_hide_root(true);
  974. add_child(save_path);
  975. item_save_path = memnew(EditorFileDialog);
  976. item_save_path->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  977. item_save_path->add_filter("*.tres;Text Resource");
  978. item_save_path->add_filter("*.res;Binary Resource");
  979. add_child(item_save_path);
  980. item_save_path->connect("file_selected", callable_mp(this, &SceneImportSettings::_save_path_changed));
  981. save_path->connect("dir_selected", callable_mp(this, &SceneImportSettings::_save_dir_callback));
  982. }
  983. SceneImportSettings::~SceneImportSettings() {
  984. memdelete(scene_import_settings_data);
  985. }