Merge pull request #94058 from Hilderin/fix-scene-project-importation-settings

Fix missing options in Project Import Defaults
This commit is contained in:
Rémi Verschelde 2024-07-17 11:42:59 +02:00
commit 2380ed5e1b
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 43 additions and 38 deletions

View File

@ -291,14 +291,18 @@ bool ResourceImporterScene::get_option_visibility(const String &p_path, const St
for (int i = 0; i < post_importer_plugins.size(); i++) { for (int i = 0; i < post_importer_plugins.size(); i++) {
Variant ret = post_importer_plugins.write[i]->get_option_visibility(p_path, animation_importer, p_option, p_options); Variant ret = post_importer_plugins.write[i]->get_option_visibility(p_path, animation_importer, p_option, p_options);
if (ret.get_type() == Variant::BOOL) { if (ret.get_type() == Variant::BOOL) {
return ret; if (!ret) {
return false;
}
} }
} }
for (Ref<EditorSceneFormatImporter> importer : scene_importers) { for (Ref<EditorSceneFormatImporter> importer : scene_importers) {
Variant ret = importer->get_option_visibility(p_path, animation_importer, p_option, p_options); Variant ret = importer->get_option_visibility(p_path, animation_importer, p_option, p_options);
if (ret.get_type() == Variant::BOOL) { if (ret.get_type() == Variant::BOOL) {
return ret; if (!ret) {
return false;
}
} }
} }

View File

@ -431,31 +431,39 @@ void ImportDock::_importer_selected(int i_idx) {
void ImportDock::_preset_selected(int p_idx) { void ImportDock::_preset_selected(int p_idx) {
int item_id = preset->get_popup()->get_item_id(p_idx); int item_id = preset->get_popup()->get_item_id(p_idx);
String setting_name = "importer_defaults/" + params->importer->get_importer_name();
switch (item_id) { switch (item_id) {
case ITEM_SET_AS_DEFAULT: { case ITEM_SET_AS_DEFAULT: {
Dictionary d; Dictionary import_settings;
// When import settings already exist, we will update these settings
for (const PropertyInfo &E : params->properties) { // to ensure that the dictionary retains settings that are not displayed in the
d[E.name] = params->values[E.name]; // editor. For Scene, the dictionary is the same for FBX, GLTF, and Blender, but each
// file type has some different settings.
if (ProjectSettings::get_singleton()->has_setting(setting_name)) {
import_settings = GLOBAL_GET(setting_name);
} }
ProjectSettings::get_singleton()->set("importer_defaults/" + params->importer->get_importer_name(), d); for (const PropertyInfo &E : params->properties) {
import_settings[E.name] = params->values[E.name];
}
ProjectSettings::get_singleton()->set(setting_name, import_settings);
ProjectSettings::get_singleton()->save(); ProjectSettings::get_singleton()->save();
_update_preset_menu(); _update_preset_menu();
} break; } break;
case ITEM_LOAD_DEFAULT: { case ITEM_LOAD_DEFAULT: {
ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name())); ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting(setting_name));
Dictionary d = GLOBAL_GET("importer_defaults/" + params->importer->get_importer_name()); Dictionary import_settings = GLOBAL_GET(setting_name);
List<Variant> v; List<Variant> keys;
d.get_key_list(&v); import_settings.get_key_list(&keys);
if (params->checking) { if (params->checking) {
params->checked.clear(); params->checked.clear();
} }
for (const Variant &E : v) { for (const Variant &E : keys) {
params->values[E] = d[E]; params->values[E] = import_settings[E];
if (params->checking) { if (params->checking) {
params->checked.insert(E); params->checked.insert(E);
} }
@ -463,7 +471,7 @@ void ImportDock::_preset_selected(int p_idx) {
params->update(); params->update();
} break; } break;
case ITEM_CLEAR_DEFAULT: { case ITEM_CLEAR_DEFAULT: {
ProjectSettings::get_singleton()->set("importer_defaults/" + params->importer->get_importer_name(), Variant()); ProjectSettings::get_singleton()->set(setting_name, Variant());
ProjectSettings::get_singleton()->save(); ProjectSettings::get_singleton()->save();
_update_preset_menu(); _update_preset_menu();
} break; } break;

View File

@ -126,10 +126,9 @@ Node *EditorSceneFormatImporterFBX2GLTF::import_scene(const String &p_path, uint
Variant EditorSceneFormatImporterFBX2GLTF::get_option_visibility(const String &p_path, bool p_for_animation, Variant EditorSceneFormatImporterFBX2GLTF::get_option_visibility(const String &p_path, bool p_for_animation,
const String &p_option, const HashMap<StringName, Variant> &p_options) { const String &p_option, const HashMap<StringName, Variant> &p_options) {
if (p_option == "fbx/embedded_image_handling") { // Remove all the FBX options except for 'fbx/importer' if the importer is fbx2gltf.
return false; // These options are available only for ufbx.
} if (p_option.begins_with("fbx/") && p_option != "fbx/importer" && p_options.has("fbx/importer") && int(p_options["fbx/importer"]) == EditorSceneFormatImporterUFBX::FBX_IMPORTER_FBX2GLTF) {
if (p_options.has("fbx/importer") && int(p_options["fbx/importer"]) == EditorSceneFormatImporterUFBX::FBX_IMPORTER_FBX2GLTF && p_option == "fbx/embedded_image_handling") {
return false; return false;
} }
return true; return true;

View File

@ -76,9 +76,6 @@ Node *EditorSceneFormatImporterUFBX::import_scene(const String &p_path, uint32_t
if (p_options.has(SNAME("nodes/import_as_skeleton_bones")) ? (bool)p_options[SNAME("nodes/import_as_skeleton_bones")] : false) { if (p_options.has(SNAME("nodes/import_as_skeleton_bones")) ? (bool)p_options[SNAME("nodes/import_as_skeleton_bones")] : false) {
state->set_import_as_skeleton_bones(true); state->set_import_as_skeleton_bones(true);
} }
if (p_options.has(SNAME("nodes/import_as_skeleton_bones")) ? (bool)p_options[SNAME("nodes/import_as_skeleton_bones")] : false) {
state->set_import_as_skeleton_bones(true);
}
p_flags |= EditorSceneFormatImporter::IMPORT_USE_NAMED_SKIN_BINDS; p_flags |= EditorSceneFormatImporter::IMPORT_USE_NAMED_SKIN_BINDS;
state->set_bake_fps(p_options["animation/fps"]); state->set_bake_fps(p_options["animation/fps"]);
Error err = fbx->append_from_file(path, state, p_flags, p_path.get_base_dir()); Error err = fbx->append_from_file(path, state, p_flags, p_path.get_base_dir());
@ -93,21 +90,17 @@ Node *EditorSceneFormatImporterUFBX::import_scene(const String &p_path, uint32_t
Variant EditorSceneFormatImporterUFBX::get_option_visibility(const String &p_path, bool p_for_animation, Variant EditorSceneFormatImporterUFBX::get_option_visibility(const String &p_path, bool p_for_animation,
const String &p_option, const HashMap<StringName, Variant> &p_options) { const String &p_option, const HashMap<StringName, Variant> &p_options) {
String file_extension = p_path.get_extension().to_lower();
if (file_extension != "fbx" && p_option.begins_with("fbx/")) {
return false;
}
if ((file_extension != "gltf" && file_extension != "glb") && p_option.begins_with("gltf/")) {
return false;
}
return true; return true;
} }
void EditorSceneFormatImporterUFBX::get_import_options(const String &p_path, void EditorSceneFormatImporterUFBX::get_import_options(const String &p_path,
List<ResourceImporter::ImportOption> *r_options) { List<ResourceImporter::ImportOption> *r_options) {
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/importer", PROPERTY_HINT_ENUM, "ufbx,FBX2glTF"), FBX_IMPORTER_UFBX)); // Returns all the options when path is empty because that means it's for the Project Settings.
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::BOOL, "fbx/allow_geometry_helper_nodes"), false)); if (p_path.is_empty() || p_path.get_extension().to_lower() == "fbx") {
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_EXTRACT_TEXTURES)); r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/importer", PROPERTY_HINT_ENUM, "ufbx,FBX2glTF"), FBX_IMPORTER_UFBX));
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::BOOL, "fbx/allow_geometry_helper_nodes"), false));
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_EXTRACT_TEXTURES));
}
} }
void EditorSceneFormatImporterUFBX::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const { void EditorSceneFormatImporterUFBX::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {

View File

@ -332,7 +332,8 @@ Variant EditorSceneFormatImporterBlend::get_option_visibility(const String &p_pa
} }
void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options) { void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options) {
if (p_path.get_extension().to_lower() != "blend") { // Returns all the options when path is empty because that means it's for the Project Settings.
if (!p_path.is_empty() && p_path.get_extension().to_lower() != "blend") {
return; return;
} }
#define ADD_OPTION_BOOL(PATH, VALUE) \ #define ADD_OPTION_BOOL(PATH, VALUE) \

View File

@ -84,8 +84,12 @@ Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t
void EditorSceneFormatImporterGLTF::get_import_options(const String &p_path, void EditorSceneFormatImporterGLTF::get_import_options(const String &p_path,
List<ResourceImporter::ImportOption> *r_options) { List<ResourceImporter::ImportOption> *r_options) {
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "gltf/naming_version", PROPERTY_HINT_ENUM, "Godot 4.1 or 4.0,Godot 4.2 or later"), 1)); String file_extension = p_path.get_extension().to_lower();
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)); // Returns all the options when path is empty because that means it's for the Project Settings.
if (p_path.is_empty() || file_extension == "gltf" || file_extension == "glb") {
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "gltf/naming_version", PROPERTY_HINT_ENUM, "Godot 4.1 or 4.0,Godot 4.2 or later"), 1));
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));
}
} }
void EditorSceneFormatImporterGLTF::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const { void EditorSceneFormatImporterGLTF::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {
@ -98,10 +102,6 @@ void EditorSceneFormatImporterGLTF::handle_compatibility_options(HashMap<StringN
Variant EditorSceneFormatImporterGLTF::get_option_visibility(const String &p_path, bool p_for_animation, Variant EditorSceneFormatImporterGLTF::get_option_visibility(const String &p_path, bool p_for_animation,
const String &p_option, const HashMap<StringName, Variant> &p_options) { const String &p_option, const HashMap<StringName, Variant> &p_options) {
String file_extension = p_path.get_extension().to_lower();
if ((file_extension != "gltf" && file_extension != "glb") && p_option.begins_with("gltf/")) {
return false;
}
return true; return true;
} }