/**************************************************************************/ /* editor_scene_exporter_gltf_settings.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "editor_scene_exporter_gltf_settings.h" #include "core/object/callable_mp.h" #include "core/object/class_db.h" #include "core/object/script_language.h" const uint32_t PROP_EDITOR_SCRIPT_VAR = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE; bool EditorSceneExporterGLTFSettings::_set(const StringName &p_name, const Variant &p_value) { String name_str = String(p_name); if (name_str.contains_char('/')) { return _set_extension_setting(name_str, p_value); } if (p_name == StringName("image_format")) { _document->set_image_format(p_value); emit_signal(CoreStringName(property_list_changed)); return true; } if (p_name == StringName("lossy_quality")) { _document->set_lossy_quality(p_value); return true; } if (p_name == StringName("fallback_image_format")) { _document->set_fallback_image_format(p_value); emit_signal(CoreStringName(property_list_changed)); return true; } if (p_name == StringName("fallback_image_quality")) { _document->set_fallback_image_quality(p_value); return true; } if (p_name == StringName("root_node_mode")) { _document->set_root_node_mode((GLTFDocument::RootNodeMode)(int64_t)p_value); return true; } if (p_name == StringName("visibility_mode")) { _document->set_visibility_mode((GLTFDocument::VisibilityMode)(int64_t)p_value); return true; } return false; } bool EditorSceneExporterGLTFSettings::_get(const StringName &p_name, Variant &r_ret) const { String name_str = String(p_name); if (name_str.contains_char('/')) { return _get_extension_setting(name_str, r_ret); } if (p_name == StringName("image_format")) { r_ret = _document->get_image_format(); return true; } if (p_name == StringName("lossy_quality")) { r_ret = _document->get_lossy_quality(); return true; } if (p_name == StringName("fallback_image_format")) { r_ret = _document->get_fallback_image_format(); return true; } if (p_name == StringName("fallback_image_quality")) { r_ret = _document->get_fallback_image_quality(); return true; } if (p_name == StringName("root_node_mode")) { r_ret = _document->get_root_node_mode(); return true; } if (p_name == StringName("visibility_mode")) { r_ret = _document->get_visibility_mode(); return true; } return false; } void EditorSceneExporterGLTFSettings::_get_property_list(List *p_list) const { for (PropertyInfo prop : _property_list) { if (prop.name == "lossy_quality") { const String image_format = get("image_format"); const bool is_image_format_lossy = image_format == "JPEG" || image_format.containsn("Lossy"); prop.usage = is_image_format_lossy ? PROPERTY_USAGE_DEFAULT : PROPERTY_USAGE_STORAGE; } if (prop.name == "fallback_image_format") { const String image_format = get("image_format"); const bool is_image_format_extension = image_format != "None" && image_format != "PNG" && image_format != "JPEG"; prop.usage = is_image_format_extension ? PROPERTY_USAGE_DEFAULT : PROPERTY_USAGE_STORAGE; } if (prop.name == "fallback_image_quality") { const String image_format = get("image_format"); const bool is_image_format_extension = image_format != "None" && image_format != "PNG" && image_format != "JPEG"; const String fallback_format = get("fallback_image_format"); prop.usage = (is_image_format_extension && fallback_format != "None") ? PROPERTY_USAGE_DEFAULT : PROPERTY_USAGE_STORAGE; } p_list->push_back(prop); } } void EditorSceneExporterGLTFSettings::_on_extension_property_list_changed() { generate_property_list(_document); emit_signal(CoreStringName(property_list_changed)); } bool EditorSceneExporterGLTFSettings::_set_extension_setting(const String &p_name_str, const Variant &p_value) { PackedStringArray split = String(p_name_str).split("/", true, 1); if (!_config_name_to_extension_map.has(split[0])) { return false; } Ref extension = _config_name_to_extension_map[split[0]]; bool valid; extension->set(split[1], p_value, &valid); return valid; } bool EditorSceneExporterGLTFSettings::_get_extension_setting(const String &p_name_str, Variant &r_ret) const { PackedStringArray split = String(p_name_str).split("/", true, 1); if (!_config_name_to_extension_map.has(split[0])) { return false; } Ref extension = _config_name_to_extension_map[split[0]]; bool valid; r_ret = extension->get(split[1], &valid); return valid; } String get_friendly_config_prefix(Ref p_extension) { String config_prefix = p_extension->get_name(); if (!config_prefix.is_empty()) { return config_prefix; } const Ref