editor_scene_importer_blend.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*************************************************************************/
  2. /* editor_scene_importer_blend.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "editor_scene_importer_blend.h"
  31. #ifdef TOOLS_ENABLED
  32. #include "../gltf_document.h"
  33. #include "../gltf_state.h"
  34. #include "core/config/project_settings.h"
  35. #include "editor/editor_file_dialog.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_scale.h"
  38. #include "editor/editor_settings.h"
  39. #include "main/main.h"
  40. #include "scene/main/node.h"
  41. #include "scene/resources/animation.h"
  42. #ifdef WINDOWS_ENABLED
  43. // Code by Pedro Estebanez (https://github.com/godotengine/godot/pull/59766)
  44. #include <shlwapi.h>
  45. #endif
  46. uint32_t EditorSceneFormatImporterBlend::get_import_flags() const {
  47. return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION;
  48. }
  49. void EditorSceneFormatImporterBlend::get_extensions(List<String> *r_extensions) const {
  50. r_extensions->push_back("blend");
  51. }
  52. Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_t p_flags,
  53. const HashMap<StringName, Variant> &p_options, int p_bake_fps,
  54. List<String> *r_missing_deps, Error *r_err) {
  55. // Get global paths for source and sink.
  56. // Escape paths to be valid Python strings to embed in the script.
  57. const String source_global = ProjectSettings::get_singleton()->globalize_path(p_path).c_escape();
  58. const String sink = ProjectSettings::get_singleton()->get_imported_files_path().path_join(
  59. vformat("%s-%s.gltf", p_path.get_file().get_basename(), p_path.md5_text()));
  60. const String sink_global = ProjectSettings::get_singleton()->globalize_path(sink).c_escape();
  61. // Handle configuration options.
  62. String parameters_arg;
  63. if (p_options.has(SNAME("blender/nodes/custom_properties")) && p_options[SNAME("blender/nodes/custom_properties")]) {
  64. parameters_arg += "export_extras=True,";
  65. } else {
  66. parameters_arg += "export_extras=False,";
  67. }
  68. if (p_options.has(SNAME("blender/meshes/skins")) && p_options[SNAME("blender/meshes/skins")]) {
  69. int32_t skins = p_options["blender/meshes/skins"];
  70. if (skins == BLEND_BONE_INFLUENCES_NONE) {
  71. parameters_arg += "export_all_influences=False,";
  72. } else if (skins == BLEND_BONE_INFLUENCES_COMPATIBLE) {
  73. parameters_arg += "export_all_influences=False,";
  74. } else if (skins == BLEND_BONE_INFLUENCES_ALL) {
  75. parameters_arg += "export_all_influences=True,";
  76. }
  77. parameters_arg += "export_skins=True,";
  78. } else {
  79. parameters_arg += "export_skins=False,";
  80. }
  81. if (p_options.has(SNAME("blender/materials/export_materials")) && p_options[SNAME("blender/materials/export_materials")]) {
  82. int32_t exports = p_options["blender/materials/export_materials"];
  83. if (exports == BLEND_MATERIAL_EXPORT_PLACEHOLDER) {
  84. parameters_arg += "export_materials='PLACEHOLDER',";
  85. } else if (exports == BLEND_MATERIAL_EXPORT_EXPORT) {
  86. parameters_arg += "export_materials='EXPORT',";
  87. }
  88. } else {
  89. parameters_arg += "export_materials='PLACEHOLDER',";
  90. }
  91. if (p_options.has(SNAME("blender/nodes/cameras")) && p_options[SNAME("blender/nodes/cameras")]) {
  92. parameters_arg += "export_cameras=True,";
  93. } else {
  94. parameters_arg += "export_cameras=False,";
  95. }
  96. if (p_options.has(SNAME("blender/nodes/punctual_lights")) && p_options[SNAME("blender/nodes/punctual_lights")]) {
  97. parameters_arg += "export_lights=True,";
  98. } else {
  99. parameters_arg += "export_lights=False,";
  100. }
  101. if (p_options.has(SNAME("blender/meshes/colors")) && p_options[SNAME("blender/meshes/colors")]) {
  102. parameters_arg += "export_colors=True,";
  103. } else {
  104. parameters_arg += "export_colors=False,";
  105. }
  106. if (p_options.has(SNAME("blender/nodes/visible")) && p_options[SNAME("blender/nodes/visible")]) {
  107. int32_t visible = p_options["blender/nodes/visible"];
  108. if (visible == BLEND_VISIBLE_VISIBLE_ONLY) {
  109. parameters_arg += "use_visible=True,";
  110. } else if (visible == BLEND_VISIBLE_RENDERABLE) {
  111. parameters_arg += "use_renderable=True,";
  112. } else if (visible == BLEND_VISIBLE_ALL) {
  113. parameters_arg += "use_visible=False,use_renderable=False,";
  114. }
  115. } else {
  116. parameters_arg += "use_visible=False,use_renderable=False,";
  117. }
  118. if (p_options.has(SNAME("blender/meshes/uvs")) && p_options[SNAME("blender/meshes/uvs")]) {
  119. parameters_arg += "export_texcoords=True,";
  120. } else {
  121. parameters_arg += "export_texcoords=False,";
  122. }
  123. if (p_options.has(SNAME("blender/meshes/normals")) && p_options[SNAME("blender/meshes/normals")]) {
  124. parameters_arg += "export_normals=True,";
  125. } else {
  126. parameters_arg += "export_normals=False,";
  127. }
  128. if (p_options.has(SNAME("blender/meshes/tangents")) && p_options[SNAME("blender/meshes/tangents")]) {
  129. parameters_arg += "export_tangents=True,";
  130. } else {
  131. parameters_arg += "export_tangents=False,";
  132. }
  133. if (p_options.has(SNAME("blender/animation/group_tracks")) && p_options[SNAME("blender/animation/group_tracks")]) {
  134. parameters_arg += "export_nla_strips=True,";
  135. } else {
  136. parameters_arg += "export_nla_strips=False,";
  137. }
  138. if (p_options.has(SNAME("blender/animation/limit_playback")) && p_options[SNAME("blender/animation/limit_playback")]) {
  139. parameters_arg += "export_frame_range=True,";
  140. } else {
  141. parameters_arg += "export_frame_range=False,";
  142. }
  143. if (p_options.has(SNAME("blender/animation/always_sample")) && p_options[SNAME("blender/animation/always_sample")]) {
  144. parameters_arg += "export_force_sampling=True,";
  145. } else {
  146. parameters_arg += "export_force_sampling=False,";
  147. }
  148. if (p_options.has(SNAME("blender/meshes/export_bones_deforming_mesh_only")) && p_options[SNAME("blender/meshes/export_bones_deforming_mesh_only")]) {
  149. parameters_arg += "export_def_bones=True,";
  150. } else {
  151. parameters_arg += "export_def_bones=False,";
  152. }
  153. if (p_options.has(SNAME("blender/nodes/modifiers")) && p_options[SNAME("blender/nodes/modifiers")]) {
  154. parameters_arg += "export_apply=True";
  155. } else {
  156. parameters_arg += "export_apply=False";
  157. }
  158. String unpack_all;
  159. if (p_options.has(SNAME("blender/materials/unpack_enabled")) && p_options[SNAME("blender/materials/unpack_enabled")]) {
  160. unpack_all = "bpy.ops.file.unpack_all(method='USE_LOCAL');";
  161. }
  162. // Prepare Blender export script.
  163. String common_args = vformat("filepath='%s',", sink_global) +
  164. "export_format='GLTF_SEPARATE',"
  165. "export_yup=True," +
  166. parameters_arg;
  167. String script =
  168. String("import bpy, sys;") +
  169. "print('Blender 3.0 or higher is required.', file=sys.stderr) if bpy.app.version < (3, 0, 0) else None;" +
  170. vformat("bpy.ops.wm.open_mainfile(filepath='%s');", source_global) +
  171. unpack_all +
  172. vformat("bpy.ops.export_scene.gltf(export_keep_originals=True,%s);", common_args);
  173. print_verbose(script);
  174. // Run script with configured Blender binary.
  175. String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
  176. #ifdef WINDOWS_ENABLED
  177. blender_path = blender_path.path_join("blender.exe");
  178. #else
  179. blender_path = blender_path.path_join("blender");
  180. #endif
  181. List<String> args;
  182. args.push_back("--background");
  183. args.push_back("--python-expr");
  184. args.push_back(script);
  185. String standard_out;
  186. int ret;
  187. OS::get_singleton()->execute(blender_path, args, &standard_out, &ret, true);
  188. print_verbose(blender_path);
  189. print_verbose(standard_out);
  190. if (ret != 0) {
  191. if (r_err) {
  192. *r_err = ERR_SCRIPT_FAILED;
  193. }
  194. ERR_PRINT(vformat("Blend export to glTF failed with error: %d.", ret));
  195. return nullptr;
  196. }
  197. // Import the generated glTF.
  198. // Use GLTFDocument instead of glTF importer to keep image references.
  199. Ref<GLTFDocument> gltf;
  200. gltf.instantiate();
  201. Ref<GLTFState> state;
  202. state.instantiate();
  203. String base_dir;
  204. if (p_options.has(SNAME("blender/materials/unpack_enabled")) && p_options[SNAME("blender/materials/unpack_enabled")]) {
  205. base_dir = sink.get_base_dir();
  206. }
  207. Error err = gltf->append_from_file(sink.get_basename() + ".gltf", state, p_flags, p_bake_fps, base_dir);
  208. if (err != OK) {
  209. if (r_err) {
  210. *r_err = FAILED;
  211. }
  212. return nullptr;
  213. }
  214. return gltf->generate_scene(state, p_bake_fps);
  215. }
  216. Variant EditorSceneFormatImporterBlend::get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option,
  217. const HashMap<StringName, Variant> &p_options) {
  218. if (p_path.get_extension().to_lower() != "blend") {
  219. return true;
  220. }
  221. if (p_option.begins_with("animation/")) {
  222. if (p_option != "animation/import" && !bool(p_options["animation/import"])) {
  223. return false;
  224. }
  225. }
  226. return true;
  227. }
  228. void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options) {
  229. if (p_path.get_extension().to_lower() != "blend") {
  230. return;
  231. }
  232. #define ADD_OPTION_BOOL(PATH, VALUE) \
  233. r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, SNAME(PATH)), VALUE));
  234. #define ADD_OPTION_ENUM(PATH, ENUM_HINT, VALUE) \
  235. r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, SNAME(PATH), PROPERTY_HINT_ENUM, ENUM_HINT), VALUE));
  236. ADD_OPTION_ENUM("blender/nodes/visible", "Visible Only,Renderable,All", BLEND_VISIBLE_ALL);
  237. ADD_OPTION_BOOL("blender/nodes/punctual_lights", true);
  238. ADD_OPTION_BOOL("blender/nodes/cameras", true);
  239. ADD_OPTION_BOOL("blender/nodes/custom_properties", true);
  240. ADD_OPTION_ENUM("blender/nodes/modifiers", "No Modifiers,All Modifiers", BLEND_MODIFIERS_ALL);
  241. ADD_OPTION_BOOL("blender/meshes/colors", false);
  242. ADD_OPTION_BOOL("blender/meshes/uvs", true);
  243. ADD_OPTION_BOOL("blender/meshes/normals", true);
  244. ADD_OPTION_BOOL("blender/meshes/tangents", true);
  245. ADD_OPTION_ENUM("blender/meshes/skins", "None,4 Influences (Compatible),All Influences", BLEND_BONE_INFLUENCES_ALL);
  246. ADD_OPTION_BOOL("blender/meshes/export_bones_deforming_mesh_only", false);
  247. ADD_OPTION_BOOL("blender/materials/unpack_enabled", true);
  248. ADD_OPTION_ENUM("blender/materials/export_materials", "Placeholder,Export", BLEND_MATERIAL_EXPORT_EXPORT);
  249. ADD_OPTION_BOOL("blender/animation/limit_playback", true);
  250. ADD_OPTION_BOOL("blender/animation/always_sample", true);
  251. ADD_OPTION_BOOL("blender/animation/group_tracks", true);
  252. #undef ADD_OPTION_BOOL
  253. #undef ADD_OPTION_ENUM
  254. }
  255. ///////////////////////////
  256. static bool _test_blender_path(const String &p_path, String *r_err = nullptr) {
  257. String path = p_path;
  258. #ifdef WINDOWS_ENABLED
  259. path = path.path_join("blender.exe");
  260. #else
  261. path = path.path_join("blender");
  262. #endif
  263. #if defined(MACOS_ENABLED)
  264. if (!FileAccess::exists(path)) {
  265. path = path.path_join("Blender");
  266. }
  267. #endif
  268. if (!FileAccess::exists(path)) {
  269. if (r_err) {
  270. *r_err = TTR("Path does not contain a Blender installation.");
  271. }
  272. return false;
  273. }
  274. List<String> args;
  275. args.push_back("--version");
  276. String pipe;
  277. Error err = OS::get_singleton()->execute(path, args, &pipe);
  278. if (err != OK) {
  279. if (r_err) {
  280. *r_err = TTR("Can't execute Blender binary.");
  281. }
  282. return false;
  283. }
  284. if (pipe.find("Blender ") != 0) {
  285. if (r_err) {
  286. *r_err = vformat(TTR("Unexpected --version output from Blender binary at: %s"), path);
  287. }
  288. return false;
  289. }
  290. pipe = pipe.replace_first("Blender ", "");
  291. int pp = pipe.find(".");
  292. if (pp == -1) {
  293. if (r_err) {
  294. *r_err = TTR("Path supplied lacks a Blender binary.");
  295. }
  296. return false;
  297. }
  298. String v = pipe.substr(0, pp);
  299. int version = v.to_int();
  300. if (version < 3) {
  301. if (r_err) {
  302. *r_err = TTR("This Blender installation is too old for this importer (not 3.0+).");
  303. }
  304. return false;
  305. }
  306. if (version > 3) {
  307. if (r_err) {
  308. *r_err = TTR("This Blender installation is too new for this importer (not 3.x).");
  309. }
  310. return false;
  311. }
  312. return true;
  313. }
  314. bool EditorFileSystemImportFormatSupportQueryBlend::is_active() const {
  315. bool blend_enabled = GLOBAL_GET("filesystem/import/blender/enabled");
  316. String blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
  317. if (blend_enabled && !_test_blender_path(blender_path)) {
  318. // Intending to import Blender, but blend not configured.
  319. return true;
  320. }
  321. return false;
  322. }
  323. Vector<String> EditorFileSystemImportFormatSupportQueryBlend::get_file_extensions() const {
  324. Vector<String> ret;
  325. ret.push_back("blend");
  326. return ret;
  327. }
  328. void EditorFileSystemImportFormatSupportQueryBlend::_validate_path(String p_path) {
  329. String error;
  330. bool success = false;
  331. if (p_path == "") {
  332. error = TTR("Path is empty.");
  333. } else {
  334. if (_test_blender_path(p_path, &error)) {
  335. success = true;
  336. if (auto_detected_path == p_path) {
  337. error = TTR("Path to Blender installation is valid (Autodetected).");
  338. } else {
  339. error = TTR("Path to Blender installation is valid.");
  340. }
  341. }
  342. }
  343. path_status->set_text(error);
  344. if (success) {
  345. path_status->add_theme_color_override("font_color", path_status->get_theme_color(SNAME("success_color"), SNAME("Editor")));
  346. configure_blender_dialog->get_ok_button()->set_disabled(false);
  347. } else {
  348. path_status->add_theme_color_override("font_color", path_status->get_theme_color(SNAME("error_color"), SNAME("Editor")));
  349. configure_blender_dialog->get_ok_button()->set_disabled(true);
  350. }
  351. }
  352. bool EditorFileSystemImportFormatSupportQueryBlend::_autodetect_path(String p_path) {
  353. if (_test_blender_path(p_path)) {
  354. auto_detected_path = p_path;
  355. return true;
  356. }
  357. return false;
  358. }
  359. void EditorFileSystemImportFormatSupportQueryBlend::_path_confirmed() {
  360. confirmed = true;
  361. }
  362. void EditorFileSystemImportFormatSupportQueryBlend::_select_install(String p_path) {
  363. blender_path->set_text(p_path);
  364. _validate_path(p_path);
  365. }
  366. void EditorFileSystemImportFormatSupportQueryBlend::_browse_install() {
  367. if (blender_path->get_text() != String()) {
  368. browse_dialog->set_current_dir(blender_path->get_text());
  369. }
  370. browse_dialog->popup_centered_ratio();
  371. }
  372. bool EditorFileSystemImportFormatSupportQueryBlend::query() {
  373. if (!configure_blender_dialog) {
  374. configure_blender_dialog = memnew(ConfirmationDialog);
  375. configure_blender_dialog->set_title(TTR("Configure Blender Importer"));
  376. configure_blender_dialog->set_flag(Window::FLAG_BORDERLESS, true); // Avoid closing accidentally .
  377. configure_blender_dialog->set_close_on_escape(false);
  378. VBoxContainer *vb = memnew(VBoxContainer);
  379. vb->add_child(memnew(Label(TTR("Blender 3.0+ is required to import '.blend' files.\nPlease provide a valid path to a Blender installation:"))));
  380. HBoxContainer *hb = memnew(HBoxContainer);
  381. blender_path = memnew(LineEdit);
  382. blender_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  383. hb->add_child(blender_path);
  384. blender_path_browse = memnew(Button);
  385. hb->add_child(blender_path_browse);
  386. blender_path_browse->set_text(TTR("Browse"));
  387. blender_path_browse->connect("pressed", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_browse_install));
  388. hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  389. hb->set_custom_minimum_size(Size2(400 * EDSCALE, 0));
  390. vb->add_child(hb);
  391. path_status = memnew(Label);
  392. vb->add_child(path_status);
  393. configure_blender_dialog->add_child(vb);
  394. blender_path->connect("text_changed", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_validate_path));
  395. EditorNode::get_singleton()->get_gui_base()->add_child(configure_blender_dialog);
  396. configure_blender_dialog->set_ok_button_text(TTR("Confirm Path"));
  397. configure_blender_dialog->set_cancel_button_text(TTR("Disable '.blend' Import"));
  398. configure_blender_dialog->get_cancel_button()->set_tooltip_text(TTR("Disables Blender '.blend' files import for this project. Can be re-enabled in Project Settings."));
  399. configure_blender_dialog->connect("confirmed", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_path_confirmed));
  400. browse_dialog = memnew(EditorFileDialog);
  401. browse_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  402. browse_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
  403. browse_dialog->connect("dir_selected", callable_mp(this, &EditorFileSystemImportFormatSupportQueryBlend::_select_install));
  404. EditorNode::get_singleton()->get_gui_base()->add_child(browse_dialog);
  405. }
  406. String path = EDITOR_GET("filesystem/import/blender/blender3_path");
  407. if (path == "") {
  408. // Autodetect
  409. auto_detected_path = "";
  410. #if defined(MACOS_ENABLED)
  411. {
  412. Vector<String> mdfind_paths;
  413. {
  414. List<String> mdfind_args;
  415. mdfind_args.push_back("kMDItemCFBundleIdentifier=org.blenderfoundation.blender");
  416. String output;
  417. Error err = OS::get_singleton()->execute("mdfind", mdfind_args, &output);
  418. if (err == OK) {
  419. mdfind_paths = output.split("\n");
  420. }
  421. }
  422. bool found = false;
  423. for (const String &path : mdfind_paths) {
  424. found = _autodetect_path(path.path_join("Contents/MacOS"));
  425. if (found) {
  426. break;
  427. }
  428. }
  429. if (!found) {
  430. found = _autodetect_path("/opt/homebrew/bin");
  431. }
  432. if (!found) {
  433. found = _autodetect_path("/opt/local/bin");
  434. }
  435. if (!found) {
  436. found = _autodetect_path("/usr/local/bin");
  437. }
  438. if (!found) {
  439. found = _autodetect_path("/usr/local/opt");
  440. }
  441. if (!found) {
  442. found = _autodetect_path("/Applications/Blender.app/Contents/MacOS");
  443. }
  444. }
  445. #elif defined(WINDOWS_ENABLED)
  446. {
  447. char blender_opener_path[MAX_PATH];
  448. DWORD path_len = MAX_PATH;
  449. HRESULT res = AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".blend", "open", blender_opener_path, &path_len);
  450. if (res == S_OK && _autodetect_path(String(blender_opener_path).get_base_dir())) {
  451. // Good.
  452. } else if (_autodetect_path("C:\\Program Files\\Blender Foundation")) {
  453. // Good.
  454. } else {
  455. _autodetect_path("C:\\Program Files (x86)\\Blender Foundation");
  456. }
  457. }
  458. #elif defined(UNIX_ENABLED)
  459. if (_autodetect_path("/usr/bin")) {
  460. // Good.
  461. } else if (_autodetect_path("/usr/local/bin")) {
  462. // Good
  463. } else {
  464. _autodetect_path("/opt/blender/bin");
  465. }
  466. #endif
  467. if (auto_detected_path != "") {
  468. path = auto_detected_path;
  469. }
  470. }
  471. blender_path->set_text(path);
  472. _validate_path(path);
  473. configure_blender_dialog->popup_centered();
  474. confirmed = false;
  475. while (true) {
  476. OS::get_singleton()->delay_usec(1);
  477. DisplayServer::get_singleton()->process_events();
  478. Main::iteration();
  479. if (!configure_blender_dialog->is_visible() || confirmed) {
  480. break;
  481. }
  482. }
  483. if (confirmed) {
  484. // Can only confirm a valid path.
  485. EditorSettings::get_singleton()->set("filesystem/import/blender/blender3_path", blender_path->get_text());
  486. EditorSettings::get_singleton()->save();
  487. } else {
  488. // Disable Blender import
  489. ProjectSettings::get_singleton()->set("filesystem/import/blender/enabled", false);
  490. ProjectSettings::get_singleton()->save();
  491. if (EditorNode::immediate_confirmation_dialog(TTR("Disabling '.blend' file import requires restarting the editor."), TTR("Save & Restart"), TTR("Restart"))) {
  492. EditorNode::get_singleton()->save_all_scenes();
  493. }
  494. EditorNode::get_singleton()->restart_editor();
  495. return true;
  496. }
  497. return false;
  498. }
  499. EditorFileSystemImportFormatSupportQueryBlend::EditorFileSystemImportFormatSupportQueryBlend() {
  500. }
  501. #endif // TOOLS_ENABLED