Skip to content

Commit 4a2e20d

Browse files
committed
Merge pull request godotengine#100782 from lyuma/add_import_option
Make `EditorSceneFormatImporter::_get_import_options` match EditorScenePostImportPlugin API
2 parents bee5de6 + e4de1f4 commit 4a2e20d

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

doc/classes/EditorSceneFormatImporter.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
<method name="_get_extensions" qualifiers="virtual const">
1414
<return type="PackedStringArray" />
1515
<description>
16+
Return supported file extensions for this scene importer.
1617
</description>
1718
</method>
18-
<method name="_get_import_flags" qualifiers="virtual const">
19+
<method name="_get_import_flags" qualifiers="virtual const" deprecated="Unused by the engine, and will be removed in a future version. Implementing this has no effect.">
1920
<return type="int" />
2021
<description>
2122
</description>
@@ -24,6 +25,9 @@
2425
<return type="void" />
2526
<param index="0" name="path" type="String" />
2627
<description>
28+
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].
29+
[b]Note:[/b] All [EditorSceneFormatImporter] and [EditorScenePostImportPlugin] instances will add options for all files. It is good practice to check the file extension when [param path] is non-empty.
30+
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.
2731
</description>
2832
</method>
2933
<method name="_get_option_visibility" qualifiers="virtual const">
@@ -32,6 +36,7 @@
3236
<param index="1" name="for_animation" type="bool" />
3337
<param index="2" name="option" type="String" />
3438
<description>
39+
Should return [code]true[/code] to show the given option, [code]false[/code] to hide the given option, or [code]null[/code] to ignore.
3540
</description>
3641
</method>
3742
<method name="_import_scene" qualifiers="virtual">
@@ -40,6 +45,27 @@
4045
<param index="1" name="flags" type="int" />
4146
<param index="2" name="options" type="Dictionary" />
4247
<description>
48+
Perform the bulk of the scene import logic here, for example using [GLTFDocument] or [FBXDocument].
49+
</description>
50+
</method>
51+
<method name="add_import_option">
52+
<return type="void" />
53+
<param index="0" name="name" type="String" />
54+
<param index="1" name="value" type="Variant" />
55+
<description>
56+
Add a specific import option (name and default value only). This function can only be called from [method _get_import_options].
57+
</description>
58+
</method>
59+
<method name="add_import_option_advanced">
60+
<return type="void" />
61+
<param index="0" name="type" type="int" enum="Variant.Type" />
62+
<param index="1" name="name" type="String" />
63+
<param index="2" name="default_value" type="Variant" />
64+
<param index="3" name="hint" type="int" enum="PropertyHint" default="0" />
65+
<param index="4" name="hint_string" type="String" default="&quot;&quot;" />
66+
<param index="5" name="usage_flags" type="int" default="6" />
67+
<description>
68+
Add a specific import option. This function can only be called from [method _get_import_options].
4369
</description>
4470
</method>
4571
</methods>

editor/import/3d/resource_importer_scene.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,20 @@ Node *EditorSceneFormatImporter::import_scene(const String &p_path, uint32_t p_f
9191
ERR_FAIL_V(nullptr);
9292
}
9393

94+
void EditorSceneFormatImporter::add_import_option(const String &p_name, const Variant &p_default_value) {
95+
ERR_FAIL_NULL_MSG(current_option_list, "add_import_option() can only be called from get_import_options().");
96+
add_import_option_advanced(p_default_value.get_type(), p_name, p_default_value);
97+
}
98+
99+
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) {
100+
ERR_FAIL_NULL_MSG(current_option_list, "add_import_option_advanced() can only be called from get_import_options().");
101+
current_option_list->push_back(ResourceImporter::ImportOption(PropertyInfo(p_type, p_name, p_hint, p_hint_string, p_usage_flags), p_default_value));
102+
}
103+
94104
void EditorSceneFormatImporter::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options) {
105+
current_option_list = r_options;
95106
GDVIRTUAL_CALL(_get_import_options, p_path);
107+
current_option_list = nullptr;
96108
}
97109

98110
Variant EditorSceneFormatImporter::get_option_visibility(const String &p_path, const String &p_scene_import_type, const String &p_option, const HashMap<StringName, Variant> &p_options) {
@@ -103,6 +115,9 @@ Variant EditorSceneFormatImporter::get_option_visibility(const String &p_path, c
103115
}
104116

105117
void EditorSceneFormatImporter::_bind_methods() {
118+
ClassDB::bind_method(D_METHOD("add_import_option", "name", "value"), &EditorSceneFormatImporter::add_import_option);
119+
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));
120+
106121
GDVIRTUAL_BIND(_get_import_flags);
107122
GDVIRTUAL_BIND(_get_extensions);
108123
GDVIRTUAL_BIND(_import_scene, "path", "flags", "options");

editor/import/3d/resource_importer_scene.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class Material;
5050
class EditorSceneFormatImporter : public RefCounted {
5151
GDCLASS(EditorSceneFormatImporter, RefCounted);
5252

53+
List<ResourceImporter::ImportOption> *current_option_list = nullptr;
54+
5355
protected:
5456
static void _bind_methods();
5557

@@ -73,6 +75,8 @@ class EditorSceneFormatImporter : public RefCounted {
7375
IMPORT_FORCE_DISABLE_MESH_COMPRESSION = 64,
7476
};
7577

78+
void add_import_option(const String &p_name, const Variant &p_default_value);
79+
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);
7680
virtual uint32_t get_import_flags() const;
7781
virtual void get_extensions(List<String> *r_extensions) const;
7882
virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, List<String> *r_missing_deps, Error *r_err = nullptr);

0 commit comments

Comments
 (0)