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 customizing how the root node is handled in GLTF import/export #7791

Closed
3 of 4 tasks
aaronfranke opened this issue Sep 21, 2023 · 5 comments
Closed
3 of 4 tasks

Comments

@aaronfranke
Copy link
Member

aaronfranke commented Sep 21, 2023

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:

  1. 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.
  2. Support reading this extension when importing glTF files so that files can specify the scene's single root node.
  3. Add a setting to the glTF export code to control the root node behavior (single, keep, or multi root).
  4. Expose the export setting in point 3 to the editor's glTF export dialog, which will look like the below image.
  5. (Optional) Add a setting to the import dock to override point 2 on import.
Screenshot 2023-09-18 at 1 41 22 AM

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

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.

@and-rad
Copy link

and-rad commented Mar 21, 2024

My work would benefit immensely from this for importing scenes. I have hundreds of unnecessary Node3Ds in even small levels because of the extra scene root that's created when a GLTF scene is imported.

What is left to do to finish implementing this?

@aaronfranke
Copy link
Member Author

@and-rad Points 1 to 4 are done, exporting from Godot will save a flag that tells Godot about the root node. The last part of this proposal is the optional idea of overriding this for files without this flag, which I am not sure is needed (but from your comment it sounds like you would find that useful).

@Aman-Anas
Copy link

For the multi-root option, I wonder if it would be possible to export as multiple separate scene files for each node & child (maybe linked together in a full scene). This way you still maintain edit-ability and can derive the individual scenes while still having it update from file.

This would help a lot for things like rigid bodies and prop libraries, since it would import as multiple reusable scenes for each prop (and for rigid bodies, allow you to derive the sub-tree you need with collision shapes)

@aaronfranke
Copy link
Member Author

@Aman-Anas I just recently made something very similar: glTFX support for Godot. It allows you to export a scene containing multiple scenes as multiple glTF files linked together in a glTFX representing the full scene.

@aaronfranke
Copy link
Member Author

Closing as resolved and implemented.

@aaronfranke aaronfranke modified the milestones: 4.x, 4.3 Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants