Debian Codegraph @

modules/gltf/register_types.cpp

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