Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow post-import plugins to modify _subresources #100792

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/classes/EditorScenePostImportPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<param index="0" name="scene" type="Node" />
<description>
Pre Process the scene. This function is called right after the scene format loader loaded the scene and no changes have been made.
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].
</description>
</method>
<method name="add_import_option">
Expand Down
57 changes: 31 additions & 26 deletions editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2934,38 +2934,22 @@ Error ResourceImporterScene::import(ResourceUID::ID p_source_id, const String &p

Dictionary subresources = p_options["_subresources"];

Dictionary node_data;
if (subresources.has("nodes")) {
node_data = subresources["nodes"];
}

Dictionary material_data;
if (subresources.has("materials")) {
material_data = subresources["materials"];
}

Dictionary animation_data;
if (subresources.has("animations")) {
animation_data = subresources["animations"];
}

Dictionary mesh_data;
if (subresources.has("meshes")) {
mesh_data = subresources["meshes"];
}

Error err = OK;

// Check whether any of the meshes or animations have nonexistent save paths
// and if they do, fail the import immediately.
err = _check_resource_save_paths(mesh_data);
if (err != OK) {
return err;
if (subresources.has("meshes")) {
err = _check_resource_save_paths(subresources["meshes"]);
if (err != OK) {
return err;
}
}

err = _check_resource_save_paths(animation_data);
if (err != OK) {
return err;
if (subresources.has("animations")) {
err = _check_resource_save_paths(subresources["animations"]);
if (err != OK) {
return err;
}
}

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

// data in _subresources may be modified by pre_process(), so wait until now to check.
Dictionary node_data;
if (subresources.has("nodes")) {
node_data = subresources["nodes"];
}

Dictionary material_data;
if (subresources.has("materials")) {
material_data = subresources["materials"];
}

Dictionary animation_data;
if (subresources.has("animations")) {
animation_data = subresources["animations"];
}

Dictionary mesh_data;
if (subresources.has("meshes")) {
mesh_data = subresources["meshes"];
}

float fps = 30;
if (p_options.has(SNAME("animation/fps"))) {
fps = (float)p_options[SNAME("animation/fps")];
Expand Down