Allow customizing how the root node is handled in GLTF import/export #7791
Description
Describe the project you are working on
I am working on glTF support in Godot.
Describe the problem or limitation you are having in your project
Currently, when you import a glTF file in Godot, the glTF root nodes will be added as a child of the "real" root node. This is done because glTF supports multiple root nodes in a scene, but Godot only has one root node per scene. This means that on import an extra root node will be created, and there is no way for the glTF file to customize this extra "real" root node. One possible solution would be to treat the glTF root as the Godot scene root if there is just one, but due to the possibility of there being multiple root nodes, this is not sensible to do automatically.
Currently, when you export a glTF file in Godot, the root node of the Godot scene will always be placed as the root node of the glTF scene. This means that if you round-trip a scene out of Godot and back in, there will be an extra root node. There is no way to export a glTF file in a way that indicates an extra root node should not be created, and there is no way to export a glTF file from Godot in a way that has multiple root nodes.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The proposal is to do the following things:
- Create a new glTF extension called
GODOT_single_root
which specifies that a glTF file's root node is expected to be treated as the real single root node of the scene and imposes restrictions to ensure this works without issues. - Support reading this extension when importing glTF files so that files can specify the scene's single root node.
- Add a setting to the glTF export code to control the root node behavior (single, keep, or multi root).
- Expose the export setting in point 3 to the editor's glTF export dialog, which will look like the below image.
- (Optional) Add a setting to the import dock to override point 2 on import.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
-
Point 1 is about writing a spec, which is done, and does not directly need any engine changes.
-
Points 2 and 3 are implemented in this PR: GLTF: Add root node export options and
GODOT_single_root
extension godot#81851 -
Point 4 will have to wait until we have export settings in the export dialog, see Add export settings to the export dialog for GLTF godot#79316
-
Point 5 is about overriding, so it's not as important as the rest of the points which deal with the file contents and ensuring Godot reads/writes this as best as possible, and if desired it should be done after the rest is merged.
If this enhancement will not be used often, can it be worked around with a few lines of script?
This will be used often. It is possible to work around in script, but only in a hacky way.
Is there a reason why this should be core and not an add-on in the asset library?
Root nodes are a part of Godot, and glTF support is core.
Activity