register_types.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*************************************************************************/
  2. /* register_types.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 "register_types.h"
  31. #ifndef _3D_DISABLED
  32. #include "gltf_accessor.h"
  33. #include "gltf_animation.h"
  34. #include "gltf_buffer_view.h"
  35. #include "gltf_camera.h"
  36. #include "gltf_document.h"
  37. #include "gltf_document_extension.h"
  38. #include "gltf_document_extension_convert_importer_mesh.h"
  39. #include "gltf_light.h"
  40. #include "gltf_mesh.h"
  41. #include "gltf_node.h"
  42. #include "gltf_skeleton.h"
  43. #include "gltf_skin.h"
  44. #include "gltf_spec_gloss.h"
  45. #include "gltf_state.h"
  46. #include "gltf_texture.h"
  47. #ifdef TOOLS_ENABLED
  48. #include "core/config/project_settings.h"
  49. #include "editor/editor_node.h"
  50. #include "editor/editor_scene_exporter_gltf_plugin.h"
  51. #include "editor/editor_scene_importer_blend.h"
  52. #include "editor/editor_scene_importer_fbx.h"
  53. #include "editor/editor_scene_importer_gltf.h"
  54. #include "editor/editor_settings.h"
  55. static void _editor_init() {
  56. Ref<EditorSceneFormatImporterGLTF> import_gltf;
  57. import_gltf.instantiate();
  58. ResourceImporterScene::add_importer(import_gltf);
  59. // Blend to glTF importer.
  60. bool blend_enabled = GLOBAL_GET("filesystem/import/blender/enabled");
  61. // Defined here because EditorSettings doesn't exist in `register_gltf_types` yet.
  62. EDITOR_DEF_RST("filesystem/import/blender/blender3_path", "");
  63. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,
  64. "filesystem/import/blender/blender3_path", PROPERTY_HINT_GLOBAL_DIR));
  65. if (blend_enabled) {
  66. Ref<EditorSceneFormatImporterBlend> importer;
  67. importer.instantiate();
  68. ResourceImporterScene::add_importer(importer);
  69. Ref<EditorFileSystemImportFormatSupportQueryBlend> blend_import_query;
  70. blend_import_query.instantiate();
  71. EditorFileSystem::get_singleton()->add_import_format_support_query(blend_import_query);
  72. }
  73. // FBX to glTF importer.
  74. bool fbx_enabled = GLOBAL_GET("filesystem/import/fbx/enabled");
  75. // Defined here because EditorSettings doesn't exist in `register_gltf_types` yet.
  76. String fbx2gltf_path = EDITOR_DEF_RST("filesystem/import/fbx/fbx2gltf_path", "");
  77. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,
  78. "filesystem/import/fbx/fbx2gltf_path", PROPERTY_HINT_GLOBAL_FILE));
  79. if (fbx_enabled) {
  80. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  81. if (fbx2gltf_path.is_empty()) {
  82. WARN_PRINT("FBX file import is enabled, but no FBX2glTF path is configured. FBX files will not be imported.");
  83. } else if (!da->file_exists(fbx2gltf_path)) {
  84. WARN_PRINT("FBX file import is enabled, but the FBX2glTF path doesn't point to a valid FBX2glTF executable. FBX files will not be imported.");
  85. } else {
  86. Ref<EditorSceneFormatImporterFBX> importer;
  87. importer.instantiate();
  88. ResourceImporterScene::add_importer(importer);
  89. }
  90. }
  91. }
  92. #endif // TOOLS_ENABLED
  93. void register_gltf_types() {
  94. // glTF API available at runtime.
  95. GDREGISTER_CLASS(GLTFAccessor);
  96. GDREGISTER_CLASS(GLTFAnimation);
  97. GDREGISTER_CLASS(GLTFBufferView);
  98. GDREGISTER_CLASS(GLTFCamera);
  99. GDREGISTER_CLASS(GLTFDocument);
  100. GDREGISTER_CLASS(GLTFDocumentExtension);
  101. GDREGISTER_CLASS(GLTFDocumentExtensionConvertImporterMesh);
  102. GDREGISTER_CLASS(GLTFLight);
  103. GDREGISTER_CLASS(GLTFMesh);
  104. GDREGISTER_CLASS(GLTFNode);
  105. GDREGISTER_CLASS(GLTFSkeleton);
  106. GDREGISTER_CLASS(GLTFSkin);
  107. GDREGISTER_CLASS(GLTFSpecGloss);
  108. GDREGISTER_CLASS(GLTFState);
  109. GDREGISTER_CLASS(GLTFTexture);
  110. #ifdef TOOLS_ENABLED
  111. // Editor-specific API.
  112. ClassDB::APIType prev_api = ClassDB::get_current_api();
  113. ClassDB::set_current_api(ClassDB::API_EDITOR);
  114. GDREGISTER_CLASS(EditorSceneFormatImporterGLTF);
  115. EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
  116. // Project settings defined here so doctool finds them.
  117. GLOBAL_DEF_RST("filesystem/import/blender/enabled", true);
  118. GLOBAL_DEF_RST("filesystem/import/fbx/enabled", true);
  119. GDREGISTER_CLASS(EditorSceneFormatImporterBlend);
  120. GDREGISTER_CLASS(EditorSceneFormatImporterFBX);
  121. ClassDB::set_current_api(prev_api);
  122. EditorNode::add_init_callback(_editor_init);
  123. #endif // TOOLS_ENABLED
  124. }
  125. void unregister_gltf_types() {
  126. }
  127. #endif // _3D_DISABLED