diff --git a/doc/classes/EditorSceneFormatImporter.xml b/doc/classes/EditorSceneFormatImporter.xml
index b14810133e79..d68f07e295e8 100644
--- a/doc/classes/EditorSceneFormatImporter.xml
+++ b/doc/classes/EditorSceneFormatImporter.xml
@@ -13,9 +13,10 @@
+ Return supported file extensions for this scene importer.
-
+
@@ -24,6 +25,11 @@
+ Override to add general import options. These will appear in the main import dock on the editor. Add options via [method add_import_option] and [method add_import_option_advanced].
+
+ Note: All [class EditorSceneFormatImporter] and [class EditorScenePostImportPlugin] instances will add options for all files. It is good practice to check the file extension when [param path] is non-empty.
+
+ When the user is editing project settings, [param path] will be empty. It is recommended to add all options when [param path] is empty to allow the user to customize Import Defaults.
@@ -32,6 +38,7 @@
+ Should return [code]true[/code] to show the given option, [code]false[/code] to hide the given option, or [code]null[/code] to ignore.
@@ -40,6 +47,34 @@
+ Perform the bulk of the scene import logic here, for example using [class GLTFDocument] or [class FBXDocument].
+
+
+
+
+
+
+
+ Add a specific import option (name and default value only). This function can only be called from [method _get_import_options].
+
+
+
+
+
+
+
+
+
+
+
+ Add a specific import option. This function can only be called from [method _get_import_options].
+
+
+
+
+
+
+ Query the value of an option. This function can only be called from those querying visibility, or processing.
diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp
index 695c12150df3..ca130dee2d23 100644
--- a/editor/import/3d/resource_importer_scene.cpp
+++ b/editor/import/3d/resource_importer_scene.cpp
@@ -91,8 +91,20 @@ Node *EditorSceneFormatImporter::import_scene(const String &p_path, uint32_t p_f
ERR_FAIL_V(nullptr);
}
+void EditorSceneFormatImporter::add_import_option(const String &p_name, const Variant &p_default_value) {
+ ERR_FAIL_NULL_MSG(current_option_list, "add_import_option() can only be called from get_import_options().");
+ add_import_option_advanced(p_default_value.get_type(), p_name, p_default_value);
+}
+
+void EditorSceneFormatImporter::add_import_option_advanced(Variant::Type p_type, const String &p_name, const Variant &p_default_value, PropertyHint p_hint, const String &p_hint_string, int p_usage_flags) {
+ ERR_FAIL_NULL_MSG(current_option_list, "add_import_option_advanced() can only be called from get_import_options().");
+ current_option_list->push_back(ResourceImporter::ImportOption(PropertyInfo(p_type, p_name, p_hint, p_hint_string, p_usage_flags), p_default_value));
+}
+
void EditorSceneFormatImporter::get_import_options(const String &p_path, List *r_options) {
+ current_option_list = r_options;
GDVIRTUAL_CALL(_get_import_options, p_path);
+ current_option_list = nullptr;
}
Variant EditorSceneFormatImporter::get_option_visibility(const String &p_path, const String &p_scene_import_type, const String &p_option, const HashMap &p_options) {
@@ -103,6 +115,9 @@ Variant EditorSceneFormatImporter::get_option_visibility(const String &p_path, c
}
void EditorSceneFormatImporter::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("add_import_option", "name", "value"), &EditorSceneFormatImporter::add_import_option);
+ ClassDB::bind_method(D_METHOD("add_import_option_advanced", "type", "name", "default_value", "hint", "hint_string", "usage_flags"), &EditorSceneFormatImporter::add_import_option_advanced, DEFVAL(PROPERTY_HINT_NONE), DEFVAL(""), DEFVAL(PROPERTY_USAGE_DEFAULT));
+
GDVIRTUAL_BIND(_get_import_flags);
GDVIRTUAL_BIND(_get_extensions);
GDVIRTUAL_BIND(_import_scene, "path", "flags", "options");
diff --git a/editor/import/3d/resource_importer_scene.h b/editor/import/3d/resource_importer_scene.h
index 03102f9a3114..df2fe3d4827c 100644
--- a/editor/import/3d/resource_importer_scene.h
+++ b/editor/import/3d/resource_importer_scene.h
@@ -50,6 +50,8 @@ class Material;
class EditorSceneFormatImporter : public RefCounted {
GDCLASS(EditorSceneFormatImporter, RefCounted);
+ List *current_option_list = nullptr;
+
protected:
static void _bind_methods();
@@ -73,6 +75,8 @@ class EditorSceneFormatImporter : public RefCounted {
IMPORT_FORCE_DISABLE_MESH_COMPRESSION = 64,
};
+ void add_import_option(const String &p_name, const Variant &p_default_value);
+ void add_import_option_advanced(Variant::Type p_type, const String &p_name, const Variant &p_default_value, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = String(), int p_usage_flags = PROPERTY_USAGE_DEFAULT);
virtual uint32_t get_import_flags() const;
virtual void get_extensions(List *r_extensions) const;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap &p_options, List *r_missing_deps, Error *r_err = nullptr);