| 1 | /**************************************************************************/ |
| 2 | /* editor_scene_importer_gltf.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_gltf.h" |
| 32 | |
| 33 | #ifdef TOOLS_ENABLED |
| 34 | |
| 35 | #include "../gltf_defines.h" |
| 36 | #include "../gltf_document.h" |
| 37 | |
| 38 | uint32_t EditorSceneFormatImporterGLTF::get_import_flags() const { |
| 39 | return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION; |
| 40 | } |
| 41 | |
| 42 | void EditorSceneFormatImporterGLTF::get_extensions(List<String> *r_extensions) const { |
| 43 | r_extensions->push_back("gltf" ); |
| 44 | r_extensions->push_back("glb" ); |
| 45 | } |
| 46 | |
| 47 | Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t p_flags, |
| 48 | const HashMap<StringName, Variant> &p_options, |
| 49 | List<String> *r_missing_deps, Error *r_err) { |
| 50 | Ref<GLTFDocument> gltf; |
| 51 | gltf.instantiate(); |
| 52 | Ref<GLTFState> state; |
| 53 | state.instantiate(); |
| 54 | if (p_options.has("gltf/embedded_image_handling" )) { |
| 55 | int32_t enum_option = p_options["gltf/embedded_image_handling" ]; |
| 56 | state->set_handle_binary_image(enum_option); |
| 57 | } |
| 58 | Error err = gltf->append_from_file(p_path, state, p_flags); |
| 59 | if (err != OK) { |
| 60 | if (r_err) { |
| 61 | *r_err = err; |
| 62 | } |
| 63 | return nullptr; |
| 64 | } |
| 65 | if (p_options.has("animation/import" )) { |
| 66 | state->set_create_animations(bool(p_options["animation/import" ])); |
| 67 | } |
| 68 | |
| 69 | #ifndef DISABLE_DEPRECATED |
| 70 | bool trimming = p_options.has("animation/trimming" ) ? (bool)p_options["animation/trimming" ] : false; |
| 71 | bool remove_immutable = p_options.has("animation/remove_immutable_tracks" ) ? (bool)p_options["animation/remove_immutable_tracks" ] : true; |
| 72 | return gltf->generate_scene(state, (float)p_options["animation/fps" ], trimming, remove_immutable); |
| 73 | #else |
| 74 | return gltf->generate_scene(state, (float)p_options["animation/fps" ], (bool)p_options["animation/trimming" ], (bool)p_options["animation/remove_immutable_tracks" ]); |
| 75 | #endif |
| 76 | } |
| 77 | |
| 78 | void EditorSceneFormatImporterGLTF::get_import_options(const String &p_path, |
| 79 | List<ResourceImporter::ImportOption> *r_options) { |
| 80 | r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "gltf/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), GLTFState::HANDLE_BINARY_EXTRACT_TEXTURES)); |
| 81 | } |
| 82 | |
| 83 | #endif // TOOLS_ENABLED |
| 84 | |