register_types.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 "extensions/gltf_document_extension_convert_importer_mesh.h"
  32. #include "extensions/gltf_document_extension_texture_ktx.h"
  33. #include "extensions/gltf_document_extension_texture_webp.h"
  34. #include "extensions/gltf_spec_gloss.h"
  35. #include "gltf_document.h"
  36. #include "gltf_state.h"
  37. #include "structures/gltf_object_model_property.h"
  38. #ifndef PHYSICS_3D_DISABLED
  39. #include "extensions/physics/gltf_document_extension_physics.h"
  40. #endif // PHYSICS_3D_DISABLED
  41. #ifdef TOOLS_ENABLED
  42. #include "editor/editor_import_blend_runner.h"
  43. #include "editor/editor_scene_exporter_gltf_plugin.h"
  44. #include "editor/editor_scene_importer_blend.h"
  45. #include "editor/editor_scene_importer_gltf.h"
  46. #include "core/config/project_settings.h"
  47. #include "editor/editor_node.h"
  48. #include "editor/editor_settings.h"
  49. static void _editor_init() {
  50. Ref<EditorSceneFormatImporterGLTF> import_gltf;
  51. import_gltf.instantiate();
  52. ResourceImporterScene::add_scene_importer(import_gltf);
  53. // Blend to glTF importer.
  54. String blender_path = EDITOR_GET("filesystem/import/blender/blender_path");
  55. if (blender_path.is_empty() && EditorSettings::get_singleton()->has_setting("filesystem/import/blender/blender3_path")) {
  56. blender_path = EDITOR_GET("filesystem/import/blender/blender3_path");
  57. if (!blender_path.is_empty()) {
  58. #if defined(MACOS_ENABLED)
  59. if (blender_path.contains(".app")) {
  60. blender_path += "/Contents/MacOS/Blender";
  61. } else {
  62. blender_path += "/blender";
  63. }
  64. #elif defined(WINDOWS_ENABLED)
  65. blender_path += "\\blender.exe";
  66. #elif defined(UNIX_ENABLED)
  67. blender_path += "/blender";
  68. #endif
  69. EditorSettings::get_singleton()->set("filesystem/import/blender/blender_path", blender_path);
  70. }
  71. EditorSettings::get_singleton()->erase("filesystem/import/blender/blender3_path");
  72. EditorSettings::get_singleton()->save();
  73. }
  74. bool blend_enabled = GLOBAL_GET("filesystem/import/blender/enabled");
  75. if (blend_enabled) {
  76. Ref<EditorSceneFormatImporterBlend> importer;
  77. importer.instantiate();
  78. ResourceImporterScene::add_scene_importer(importer);
  79. Ref<EditorFileSystemImportFormatSupportQueryBlend> blend_import_query;
  80. blend_import_query.instantiate();
  81. EditorFileSystem::get_singleton()->add_import_format_support_query(blend_import_query);
  82. }
  83. memnew(EditorImportBlendRunner);
  84. EditorNode::get_singleton()->add_child(EditorImportBlendRunner::get_singleton());
  85. }
  86. #endif // TOOLS_ENABLED
  87. #define GLTF_REGISTER_DOCUMENT_EXTENSION(m_doc_ext_class) \
  88. Ref<m_doc_ext_class> extension_##m_doc_ext_class; \
  89. extension_##m_doc_ext_class.instantiate(); \
  90. GLTFDocument::register_gltf_document_extension(extension_##m_doc_ext_class);
  91. void initialize_gltf_module(ModuleInitializationLevel p_level) {
  92. if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
  93. // glTF API available at runtime.
  94. GDREGISTER_CLASS(GLTFAccessor);
  95. GDREGISTER_CLASS(GLTFAnimation);
  96. GDREGISTER_CLASS(GLTFBufferView);
  97. GDREGISTER_CLASS(GLTFCamera);
  98. GDREGISTER_CLASS(GLTFDocument);
  99. GDREGISTER_CLASS(GLTFDocumentExtension);
  100. GDREGISTER_CLASS(GLTFDocumentExtensionConvertImporterMesh);
  101. GDREGISTER_CLASS(GLTFLight);
  102. GDREGISTER_CLASS(GLTFMesh);
  103. GDREGISTER_CLASS(GLTFNode);
  104. GDREGISTER_CLASS(GLTFObjectModelProperty);
  105. #ifndef PHYSICS_3D_DISABLED
  106. GDREGISTER_CLASS(GLTFPhysicsBody);
  107. GDREGISTER_CLASS(GLTFPhysicsShape);
  108. #endif // PHYSICS_3D_DISABLED
  109. GDREGISTER_CLASS(GLTFSkeleton);
  110. GDREGISTER_CLASS(GLTFSkin);
  111. GDREGISTER_CLASS(GLTFSpecGloss);
  112. GDREGISTER_CLASS(GLTFState);
  113. GDREGISTER_CLASS(GLTFTexture);
  114. GDREGISTER_CLASS(GLTFTextureSampler);
  115. // Register GLTFDocumentExtension classes with GLTFDocument.
  116. #ifndef PHYSICS_3D_DISABLED
  117. // Ensure physics is first in this list so that physics nodes are created before other nodes.
  118. GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionPhysics);
  119. #endif // PHYSICS_3D_DISABLED
  120. GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionTextureKTX);
  121. GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionTextureWebP);
  122. bool is_editor = Engine::get_singleton()->is_editor_hint();
  123. if (!is_editor) {
  124. GLTF_REGISTER_DOCUMENT_EXTENSION(GLTFDocumentExtensionConvertImporterMesh);
  125. }
  126. }
  127. #ifdef TOOLS_ENABLED
  128. if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
  129. GDREGISTER_CLASS(EditorSceneFormatImporterGLTF);
  130. EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
  131. // Project settings defined here so doctool finds them.
  132. GLOBAL_DEF_RST_BASIC("filesystem/import/blender/enabled", true);
  133. GDREGISTER_CLASS(EditorSceneFormatImporterBlend);
  134. // Can't (a priori) run external app on these platforms.
  135. GLOBAL_DEF_RST("filesystem/import/blender/enabled.android", false);
  136. GLOBAL_DEF_RST("filesystem/import/blender/enabled.web", false);
  137. EditorNode::add_init_callback(_editor_init);
  138. }
  139. #endif // TOOLS_ENABLED
  140. }
  141. void uninitialize_gltf_module(ModuleInitializationLevel p_level) {
  142. if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
  143. return;
  144. }
  145. GLTFDocument::unregister_all_gltf_document_extensions();
  146. }