godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Document new post-import plugin preprocessing stage to amend settings

Open fire opened this issue 1 year ago • 8 comments

Your Godot version:

https://github.com/godotengine/godot/commit/6dc78c8aa17ad46e701e0c4e7b7632c2f0e098f1

Issue description:

Update the documentation.

Allow post-import plugins to modify _subresources https://github.com/godotengine/godot/pull/100792

The use case is to write the .import manually. For example, take a glTF2 character and add HumanoidProfile remapping via script.

This was added as a last-minute advanced post-import plugin feature: post-import plugins can amend the ["_subresources"]["nodes"]["PATH:Armature/Skeleton3D"]["retarget/bone_map"] settings from the preprocessing phase of a post import plugin

We can do it by writing a custom .import file, or we can do it with a plugin.

URL to the documentation page (if already existing):

https://docs.godotengine.org/en/stable/tutorials/plugins/editor/import_plugins.html

fire avatar Jan 27 '25 21:01 fire

See also https://github.com/godotengine/godot/issues/95461

fire avatar Jan 27 '25 21:01 fire

The feature works great as a plugin, I agree updating the docs is needed. Here's what I've been using to edit animation import settings on pre import for posteriority:

void AnimationPostImportPlugin::_pre_process(Node* p_scene) {

    const String export_path = get_option_value("export/animation_export_path");

    if (export_path.is_empty()) {
        return;
    }

    Dictionary animations;
    _export_animations(p_scene, animations, export_path);

    Dictionary subresources = get_option_value("_subresources");
    subresources["animations"] = animations;
}

GuilhermeGSousa avatar Jan 28 '25 09:01 GuilhermeGSousa

See also https://github.com/GuilhermeGSousa/godot-motion-matching/pull/86/files

fire avatar Jan 30 '25 07:01 fire

We can do it by writing a custom .import file, or we can do it with a plugin.

We don't need to use a plugin? This can be achieved with just a custom import script? By this, I specifically mean changing the subresources, like changing the bonemap

SamDevelopsCode avatar Feb 07 '25 06:02 SamDevelopsCode

A custom import script is too late. You'll need to recode the bone map algorithm in gdscript.. which we've done in godot-vrm.

Edited:

The preprocessing stage is to modify the input parameters to the importer.

Changing the bone map is straightforward. The algorithm to turn the existing bones to the Humanoid Profile is what is wanted without reimplementing it.

fire avatar Feb 07 '25 08:02 fire

The feature works great as a plugin, I agree updating the docs is needed. Here's what I've been using to edit animation import settings on pre import for posteriority:

void AnimationPostImportPlugin::_pre_process(Node* p_scene) {

...

Dictionary subresources = get_option_value("_subresources");
subresources["animations"] = animations;

}

~~I don't believe this will work in GDScript since the subresources var will be a duplicate instead of a reference right?~~ I've been trying to fiddle with setting subresource vars in GDScript and not having any luck getting imports to change.

Edit: I was wrong. The dictionary works perfectly fine in GDScript.

Flynsarmy avatar Aug 27 '25 02:08 Flynsarmy

Dictionaries and Arrays in godot are shared by reference rather than copied are you sure?

fire avatar Aug 27 '25 15:08 fire

Ah, my mistake. I've updated my comment so as not to unintentionally spread misinformation.

I looked into how this works tonight and here is a GDScript example. Tested and confirmed working:

@tool
extends EditorScenePostImportPlugin

func _pre_process(scene: Node) -> void:
    var subresources: Dictionary = get_option_value("_subresources");
    subresources['meshes'] = {
        'TSP_Road_Crossing_1A_001_Mesh_0_032': {
            'save_to_file/enabled': true,
            'save_to_file/path': 'res://foo.res'
        }
    }

Flynsarmy avatar Aug 28 '25 10:08 Flynsarmy