2
0

fbx_importer_manager.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**************************************************************************/
  2. /* fbx_importer_manager.cpp */
  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. #include "fbx_importer_manager.h"
  31. #include "editor/editor_scale.h"
  32. #include "editor/editor_settings.h"
  33. #include "scene/gui/link_button.h"
  34. void FBXImporterManager::_notification(int p_what) {
  35. switch (p_what) {
  36. case NOTIFICATION_READY: {
  37. connect("confirmed", callable_mp(this, &FBXImporterManager::_path_confirmed));
  38. } break;
  39. }
  40. }
  41. void FBXImporterManager::show_dialog(bool p_exclusive) {
  42. String fbx2gltf_path = EDITOR_GET("filesystem/import/fbx/fbx2gltf_path");
  43. fbx_path->set_text(fbx2gltf_path);
  44. _validate_path(fbx2gltf_path);
  45. set_flag(Window::FLAG_BORDERLESS, p_exclusive); // Avoid closing accidentally .
  46. set_close_on_escape(!p_exclusive);
  47. popup_centered();
  48. }
  49. void FBXImporterManager::_validate_path(const String &p_path) {
  50. String error;
  51. bool success = false;
  52. if (p_path == "") {
  53. error = TTR("Path to FBX2glTF executable is empty.");
  54. } else if (!FileAccess::exists(p_path)) {
  55. error = TTR("Path to FBX2glTF executable is invalid.");
  56. } else {
  57. List<String> args;
  58. args.push_back("--version");
  59. int exitcode;
  60. Error err = OS::get_singleton()->execute(p_path, args, nullptr, &exitcode);
  61. if (err == OK && exitcode == 0) {
  62. success = true;
  63. } else {
  64. error = TTR("Error executing this file (wrong version or architecture).");
  65. }
  66. }
  67. if (success) {
  68. path_status->set_text(TTR("FBX2glTF executable is valid."));
  69. path_status->add_theme_color_override("font_color", path_status->get_theme_color(SNAME("success_color"), SNAME("Editor")));
  70. get_ok_button()->set_disabled(false);
  71. } else {
  72. path_status->set_text(error);
  73. path_status->add_theme_color_override("font_color", path_status->get_theme_color(SNAME("error_color"), SNAME("Editor")));
  74. get_ok_button()->set_disabled(true);
  75. }
  76. }
  77. void FBXImporterManager::_select_file(const String &p_path) {
  78. fbx_path->set_text(p_path);
  79. _validate_path(p_path);
  80. }
  81. void FBXImporterManager::_path_confirmed() {
  82. String path = fbx_path->get_text();
  83. EditorSettings::get_singleton()->set("filesystem/import/fbx/fbx2gltf_path", path);
  84. EditorSettings::get_singleton()->save();
  85. }
  86. void FBXImporterManager::_browse_install() {
  87. if (fbx_path->get_text() != String()) {
  88. browse_dialog->set_current_file(fbx_path->get_text());
  89. }
  90. browse_dialog->popup_centered_ratio();
  91. }
  92. FBXImporterManager *FBXImporterManager::singleton = nullptr;
  93. FBXImporterManager::FBXImporterManager() {
  94. singleton = this;
  95. set_title(TTR("Configure FBX Importer"));
  96. VBoxContainer *vb = memnew(VBoxContainer);
  97. vb->add_child(memnew(Label(TTR("FBX2glTF is required for importing FBX files.\nPlease download it and provide a valid path to the binary:"))));
  98. LinkButton *lb = memnew(LinkButton);
  99. lb->set_text(TTR("Click this link to download FBX2glTF"));
  100. lb->set_uri("https://godotengine.org/fbx-import");
  101. vb->add_child(lb);
  102. HBoxContainer *hb = memnew(HBoxContainer);
  103. fbx_path = memnew(LineEdit);
  104. fbx_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  105. hb->add_child(fbx_path);
  106. fbx_path_browse = memnew(Button);
  107. hb->add_child(fbx_path_browse);
  108. fbx_path_browse->set_text(TTR("Browse"));
  109. fbx_path_browse->connect("pressed", callable_mp(this, &FBXImporterManager::_browse_install));
  110. hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  111. hb->set_custom_minimum_size(Size2(400 * EDSCALE, 0));
  112. vb->add_child(hb);
  113. path_status = memnew(Label);
  114. vb->add_child(path_status);
  115. add_child(vb);
  116. fbx_path->connect("text_changed", callable_mp(this, &FBXImporterManager::_validate_path));
  117. get_ok_button()->set_text(TTR("Confirm Path"));
  118. browse_dialog = memnew(EditorFileDialog);
  119. browse_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  120. browse_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  121. #ifdef WINDOWS_ENABLED
  122. browse_dialog->add_filter("*.exe");
  123. #endif
  124. browse_dialog->connect("file_selected", callable_mp(this, &FBXImporterManager::_select_file));
  125. add_child(browse_dialog);
  126. }