Skip to content

GLTF: Allow parsing glTF files without nodes #107836

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Jun 22, 2025

This PR allows parsing glTF files that contain no nodes. Such files, well, have no nodes, so the best we can do is import an empty scene. However, this adds flexibility, allowing for us to support non-scene glTF files in the engine in the future, and allows users to handle such files in their own code if they wish.

I think this is best explained with a diagram:

GLTF_with_no_Nodes drawio

glTF files without nodes are explicitly supported by the glTF specification:

... so this allows Godot to parse such files, even if they have no nodes so result in an empty Godot scene.

Trivial example. This imports correctly with this PR, but errors too early in the current master, which makes it fail to import, even though the file is spec-compliant. gltf_file_without_nodes_imported_as_a_mesh_instance.zip

Another trivial example. This file can now be imported:

{
    "asset": {
        "version": "2.0"
    }
}

I also renamed some variables in GLTFDocument::generate_scene for clarity, including a duplicated state vs p_state.

@lyuma
Copy link
Contributor

lyuma commented Jun 22, 2025

Why does a scene with no nodes generate an error? It should be able to import as just the root node. I understand that such a scene would not have GODOT_single_root, but without that extension, there should be no need to fail the import

@aaronfranke
Copy link
Member Author

@lyuma That's true, we could do that, taking this PR even farther. Somehow, that did not occur to me. PR updated.

Now even this glTF file can be imported:

{
    "asset": {
        "version": "2.0"
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

2 participants