Document new post-import plugin preprocessing stage to amend settings
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
See also https://github.com/godotengine/godot/issues/95461
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;
}
See also https://github.com/GuilhermeGSousa/godot-motion-matching/pull/86/files
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
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.
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.
Dictionaries and Arrays in godot are shared by reference rather than copied are you sure?
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'
}
}