Skip to content

Commit a7d84fa

Browse files
committed
Merge pull request godotengine#100792 from lyuma/post_import_plugin_subresources
Allow post-import plugins to modify `_subresources`
2 parents f7b9a6a + 637fe3c commit a7d84fa

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

doc/classes/EditorScenePostImportPlugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<param index="0" name="scene" type="Node" />
7272
<description>
7373
Pre Process the scene. This function is called right after the scene format loader loaded the scene and no changes have been made.
74+
Pre process may be used to adjust internal import options in the [code]"nodes"[/code], [code]"meshes"[/code], [code]"animations"[/code] or [code]"materials"[/code] keys inside [code]get_option_value("_subresources")[/code].
7475
</description>
7576
</method>
7677
<method name="add_import_option">

editor/import/3d/resource_importer_scene.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,38 +2934,22 @@ Error ResourceImporterScene::import(ResourceUID::ID p_source_id, const String &p
29342934

29352935
Dictionary subresources = p_options["_subresources"];
29362936

2937-
Dictionary node_data;
2938-
if (subresources.has("nodes")) {
2939-
node_data = subresources["nodes"];
2940-
}
2941-
2942-
Dictionary material_data;
2943-
if (subresources.has("materials")) {
2944-
material_data = subresources["materials"];
2945-
}
2946-
2947-
Dictionary animation_data;
2948-
if (subresources.has("animations")) {
2949-
animation_data = subresources["animations"];
2950-
}
2951-
2952-
Dictionary mesh_data;
2953-
if (subresources.has("meshes")) {
2954-
mesh_data = subresources["meshes"];
2955-
}
2956-
29572937
Error err = OK;
29582938

29592939
// Check whether any of the meshes or animations have nonexistent save paths
29602940
// and if they do, fail the import immediately.
2961-
err = _check_resource_save_paths(mesh_data);
2962-
if (err != OK) {
2963-
return err;
2941+
if (subresources.has("meshes")) {
2942+
err = _check_resource_save_paths(subresources["meshes"]);
2943+
if (err != OK) {
2944+
return err;
2945+
}
29642946
}
29652947

2966-
err = _check_resource_save_paths(animation_data);
2967-
if (err != OK) {
2968-
return err;
2948+
if (subresources.has("animations")) {
2949+
err = _check_resource_save_paths(subresources["animations"]);
2950+
if (err != OK) {
2951+
return err;
2952+
}
29692953
}
29702954

29712955
List<String> missing_deps; // for now, not much will be done with this
@@ -3005,6 +2989,27 @@ Error ResourceImporterScene::import(ResourceUID::ID p_source_id, const String &p
30052989
post_importer_plugins.write[i]->pre_process(scene, p_options);
30062990
}
30072991

2992+
// data in _subresources may be modified by pre_process(), so wait until now to check.
2993+
Dictionary node_data;
2994+
if (subresources.has("nodes")) {
2995+
node_data = subresources["nodes"];
2996+
}
2997+
2998+
Dictionary material_data;
2999+
if (subresources.has("materials")) {
3000+
material_data = subresources["materials"];
3001+
}
3002+
3003+
Dictionary animation_data;
3004+
if (subresources.has("animations")) {
3005+
animation_data = subresources["animations"];
3006+
}
3007+
3008+
Dictionary mesh_data;
3009+
if (subresources.has("meshes")) {
3010+
mesh_data = subresources["meshes"];
3011+
}
3012+
30083013
float fps = 30;
30093014
if (p_options.has(SNAME("animation/fps"))) {
30103015
fps = (float)p_options[SNAME("animation/fps")];

0 commit comments

Comments
 (0)