register_types.cpp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**************************************************************************/
  2. /* register_types.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 "register_types.h"
  31. #include "../gltf/extensions/gltf_document_extension_convert_importer_mesh.h"
  32. #include "fbx_document.h"
  33. #ifdef TOOLS_ENABLED
  34. #include "editor/editor_scene_importer_fbx2gltf.h"
  35. #include "editor/editor_scene_importer_ufbx.h"
  36. #include "core/config/project_settings.h"
  37. #include "editor/editor_node.h"
  38. static void _editor_init() {
  39. Ref<EditorSceneFormatImporterUFBX> import_fbx;
  40. import_fbx.instantiate();
  41. ResourceImporterScene::add_scene_importer(import_fbx);
  42. bool fbx2gltf_enabled = GLOBAL_GET("filesystem/import/fbx2gltf/enabled");
  43. if (fbx2gltf_enabled) {
  44. Ref<EditorSceneFormatImporterFBX2GLTF> importer;
  45. importer.instantiate();
  46. ResourceImporterScene::add_scene_importer(importer);
  47. }
  48. }
  49. #endif // TOOLS_ENABLED
  50. #define FBX_REGISTER_DOCUMENT_EXTENSION(m_doc_ext_class) \
  51. Ref<m_doc_ext_class> extension_##m_doc_ext_class; \
  52. extension_##m_doc_ext_class.instantiate(); \
  53. FBXDocument::register_gltf_document_extension(extension_##m_doc_ext_class);
  54. void initialize_fbx_module(ModuleInitializationLevel p_level) {
  55. if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
  56. GDREGISTER_CLASS(FBXDocument);
  57. GDREGISTER_CLASS(FBXState);
  58. bool is_editor = Engine::get_singleton()->is_editor_hint();
  59. if (!is_editor) {
  60. FBX_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionConvertImporterMesh);
  61. }
  62. }
  63. #ifdef TOOLS_ENABLED
  64. if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
  65. GDREGISTER_CLASS(EditorSceneFormatImporterUFBX);
  66. GLOBAL_DEF_RST_BASIC("filesystem/import/fbx2gltf/enabled", true);
  67. GDREGISTER_CLASS(EditorSceneFormatImporterFBX2GLTF);
  68. GLOBAL_DEF_RST("filesystem/import/fbx2gltf/enabled.android", false);
  69. GLOBAL_DEF_RST("filesystem/import/fbx2gltf/enabled.web", false);
  70. EditorNode::add_init_callback(_editor_init);
  71. }
  72. #endif // TOOLS_ENABLED
  73. }
  74. void uninitialize_fbx_module(ModuleInitializationLevel p_level) {
  75. if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
  76. return;
  77. }
  78. FBXDocument::unregister_all_gltf_document_extensions();
  79. }