Debian Codegraph @

modules/fbx/editor/editor_scene_importer_ufbx.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_scene_importer_ufbx.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 "editor_scene_importer_ufbx.h"
32
33 #include "../fbx_document.h"
34 #include "editor_scene_importer_fbx2gltf.h"
35
36 #include "core/config/project_settings.h"
37
38 void EditorSceneFormatImporterUFBX::get_extensions(List<String> *r_extensions) const {
39 r_extensions->push_back("fbx");
40 }
41
42 Node *EditorSceneFormatImporterUFBX::import_scene(const String &p_path, uint32_t p_flags,
43 const HashMap<StringName, Variant> &p_options,
44 List<String> *r_missing_deps, Error *r_err) {
45 // FIXME: Hack to work around GH-86309.
46 if (p_options.has("fbx/importer") && int(p_options["fbx/importer"]) == FBX_IMPORTER_FBX2GLTF && GLOBAL_GET_CACHED(bool, "filesystem/import/fbx2gltf/enabled")) {
47 Ref<EditorSceneFormatImporterFBX2GLTF> fbx2gltf_importer;
48 fbx2gltf_importer.instantiate();
49 Node *scene = fbx2gltf_importer->import_scene(p_path, p_flags, p_options, r_missing_deps, r_err);
50 if (r_err && *r_err == OK) {
51 return scene;
52 } else {
53 return nullptr;
54 }
55 }
56 Ref<FBXDocument> fbx;
57 fbx.instantiate();
58 Ref<FBXState> state;
59 state.instantiate();
60 print_verbose(vformat("FBX path: %s", p_path));
61 String path = ProjectSettings::get_singleton()->globalize_path(p_path);
62 if (p_options.has("fbx/naming_version")) {
63 int naming_version = p_options["fbx/naming_version"];
64 fbx->set_naming_version(naming_version);
65 }
66 bool allow_geometry_helper_nodes = p_options.has("fbx/allow_geometry_helper_nodes") ? (bool)p_options["fbx/allow_geometry_helper_nodes"] : false;
67 if (allow_geometry_helper_nodes) {
68 state->set_allow_geometry_helper_nodes(allow_geometry_helper_nodes);
69 }
70 if (p_options.has("fbx/embedded_image_handling")) {
71 const int32_t enum_option = p_options["fbx/embedded_image_handling"];
72 state->set_handle_binary_image_mode((GLTFState::HandleBinaryImageMode)enum_option);
73 }
74 if (p_options.has(SNAME("nodes/import_as_skeleton_bones")) ? (bool)p_options[SNAME("nodes/import_as_skeleton_bones")] : false) {
75 state->set_import_as_skeleton_bones(true);
76 }
77 p_flags |= EditorSceneFormatImporter::IMPORT_USE_NAMED_SKIN_BINDS;
78 state->set_bake_fps(p_options["animation/fps"]);
79 Error err = fbx->append_from_file(path, state, p_flags, p_path.get_base_dir());
80 if (err != OK) {
81 if (r_err) {
82 *r_err = FAILED;
83 }
84 return nullptr;
85 }
86 return fbx->generate_scene(state, state->get_bake_fps(), (bool)p_options["animation/trimming"], false);
87 }
88
89 Variant EditorSceneFormatImporterUFBX::get_option_visibility(const String &p_path, const String &p_scene_import_type,
90 const String &p_option, const HashMap<StringName, Variant> &p_options) {
91 return true;
92 }
93
94 void EditorSceneFormatImporterUFBX::get_import_options(const String &p_path,
95 List<ResourceImporter::ImportOption> *r_options) {
96 // Returns all the options when path is empty because that means it's for the Project Settings.
97 if (p_path.is_empty() || p_path.has_extension("fbx")) {
98 r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/importer", PROPERTY_HINT_ENUM, "ufbx,FBX2glTF"), FBX_IMPORTER_UFBX));
99 r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::BOOL, "fbx/allow_geometry_helper_nodes"), false));
100 r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/embedded_image_handling", PROPERTY_HINT_ENUM, "Discard All Textures,Extract Textures,Embed as Basis Universal,Embed as Uncompressed", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), FBXState::HANDLE_BINARY_IMAGE_MODE_EXTRACT_TEXTURES));
101 r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/naming_version", PROPERTY_HINT_ENUM, "Godot 4.0 or 4.1,Godot 4.2 to 4.4,Godot 4.5 or later"), 2));
102 }
103 }
104
105 void EditorSceneFormatImporterUFBX::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {
106 if (!p_import_params.has("fbx/importer")) {
107 p_import_params["fbx/importer"] = EditorSceneFormatImporterUFBX::FBX_IMPORTER_FBX2GLTF;
108 }
109 }