godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

EditorSceneFormatImporter does not provide a way to import sub-resources like EditorImportPlugin does #8316

Open Lunatix89 opened 1 year ago

Lunatix89 commented 1 year ago

Describe the project you are working on

A voxel based game which imports MagicaVoxel files as scenes.

Describe the problem or limitation you are having in your project

A MagicaVoxel file is basically a scene graph with nodes, transforms etc. with multiple voxel objects to render. Because my game is actually using a raymarching approach which works on 3D textures, the importer has to generate texture files during the import which must be stored in the import folder.

However, when we look at EditorSceneFormatImporter there is no way to tell the importer that additional files have been generated like one can do with the EditorImportPlugin (see gen_files parameter).

I've managed to develop a workaround where I am able to "fake" this behaviour and write those texture resources anyways but when I build the project, the standalone game does not find the files anymore (I'm assuming due to Godot not knowing about those as they're not writting to the .import file).

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The _import_scene method should just pass parameters save_path, platformVariants, missingDeps and genFiles as the _import method of the EditorImportPlugin does already to deal with this.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The signature of the import_scene method has to be changed to:

virtual Node *import_scene(const String &p_source_file, const String &p_save_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_missing_deps, List<String> *r_gen_files, Error *r_err = nullptr);

The definition of the _import_scene API function has to be changed to:

GDVIRTUAL7R(Object *, _import_scene, String, String, uint32_t, Dictionary, TypedArray<String>, TypedArray<String>, TypedArray<String>)

I've already implement this in my fork which has a few modifications to overcome another issue I encountered when starting to work with Godot and raymarching.

If this issue gets addressed. feel free to cherry-pick my changes from this commit: https://github.com/godotengine/godot/commit/7b7c7cc2d63031e0fa1a7e192d85c843f6f2c409

If this enhancement will not be used often, can it be worked around with a few lines of script?

As I described above, no workaround is possible.

Is there a reason why this should be core and not an add-on in the asset library?

EditorSceneFormatImporter is part of the core.

Lunatix89 commented 1 year ago

I just found out that is looks like only the "main" resource will ever be included in an export so I now put all generated files in a special directory which a custom EditorExportPlugin will add during the export phase.

However, I think it might still be necessary to be able to add entries to the gen_files list so the dependencies for a file are known.

See https://github.com/godotengine/godot/issues/84401 for reference