Skip to content

GLTF: Use scene root nodes for root nodes, don't include orphan nodes #103332

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

Merged
merged 1 commit into from
Jun 10, 2025

Conversation

aaronfranke
Copy link
Member

This fixes a bug noticed by the Blender Project DogWalk team where Godot was including orphan nodes as root nodes. This is incorrect, only the nodes actually indicated as scene root nodes should be used as root nodes. https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#scenes

Luckily the fix was pretty simple, just remove the code that re-assigns top orphan nodes as root nodes. Test file:

{
	"asset": {
		"version": "2.0"
	},
	"nodes": [
		{ "name": "A" },
		{ "name": "B" }
	],
	"scenes": [
		{ "nodes": [0] },
		{ "nodes": [1] }
	],
	"scene": 0
}

In master: Imports both A and B as glTF root nodes as children of the Godot root node (incorrect).
With this PR: Imports only A as the glTF root node as a child of the Godot root node as indicated by the scene (correct).

I also looked into the general root node handling logic. Currently Godot does not correctly handle the case of a file not specifying scenes or scene root nodes, and will error when trying to parse anything that doesn't look like a scene. This will need to be improved for godotengine/godot-proposals#7494, but for this PR I kept things limited to just this bug fix.

@fire
Copy link
Member

fire commented Feb 26, 2025

Did you link any sample wrong and correct gltf files?

@akien-mga akien-mga added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Feb 26, 2025
@aaronfranke
Copy link
Member Author

@fire The PR contains an example file already. Did you want me to also include a file that is unaffected by this PR?

@fire fire moved this to Ready for review in Asset Pipeline Issue Triage Mar 1, 2025
fire
fire previously approved these changes Mar 1, 2025
@fire fire dismissed their stale review March 1, 2025 04:35

I’ll check with the creator of this par.

@yankscally
Copy link

yankscally commented Mar 31, 2025

in blender, you can have multiple scenes, and it is respected in the gltf file:

image

here is the export:

{
	"asset":{
		"generator":"Khronos glTF Blender I/O v4.3.47",
		"version":"2.0"
	},
	"scene":0,
	"scenes":[
		{
			"name":"Scene",
			"nodes":[
				0
			]
		},
		{
			"name":"Scene.2",
			"nodes":[
				1
			]
		}
	],
	"nodes":[
		{
			"mesh":0,
			"name":"Cube"
		},
		{
			"mesh":1,
			"name":"Sphere"
		}
	],
	"meshes":[
		{
			"name":"Cube",

		},
		{
			"name":"Sphere",

                }

with blender being able to export to multiple scenes, it seems like a shame to not be using this in godot, and discarding extra scenes for the "selected" one. The selected scene from blender is the one you are currently looking at in that drop down, and still exports the other scenes data. Discarding it in godot feels like a waste of a possibly useful feature.

I experimented with using scenes in a blender project to section reusable mesh objects into a space I don't have to look at.

I thought about this:
image

But that doesn't feel like a particularly great solution when we are adding KHR_node_visibility soon, but in some ways thats what blender is doing under the hood. wish I had a better idea for importing multiple scenes.

Here is blender "hiding" objects that are not in the scene:
image
image

Edit*
I read over this again and actually think hiding the not selected "scene root" nodes under the godot root if there are multiple scenes might work well and is not a terrible idea, a godot scene does not equate to a glTF scene, we can easily use a node in godot for this purpose and hide it.

It's just a lot of work exposing all of this to godot users for no anticipated benefits.

@fire fire requested a review from a team April 24, 2025 16:57
@fire
Copy link
Member

fire commented Apr 24, 2025

Needs discussion in a Godot Engine pipeline meeting

@lyuma
Copy link
Contributor

lyuma commented Jun 8, 2025

I like this...
What do you think about adding this to the Godot 4.5 or later compatibility mode from #104184? (So older compatibility setting will still include all the orphan nodes)

@aaronfranke
Copy link
Member Author

@lyuma Sure, we can do that.

@lyuma
Copy link
Contributor

lyuma commented Jun 9, 2025

Approved contingent upon adding the compatibility mode check merged in this pr

Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Nice fix

In the future, we may want to figure out how to expose the other scenes, perhaps as sub-resources, but this fix is necessary to allow us to further develop gltf scene functionality in the future.

@lyuma lyuma moved this from Ready for review to Approved, Waiting for Production in Asset Pipeline Issue Triage Jun 9, 2025
@TokageItLab TokageItLab requested review from akien-mga and Repiteo June 9, 2025 23:46
@akien-mga akien-mga merged commit aa0eb50 into godotengine:master Jun 10, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from Approved, Waiting for Production to Done in Asset Pipeline Issue Triage Jun 10, 2025
@akien-mga
Copy link
Member

Thanks!

@aaronfranke aaronfranke deleted the gltf-no-orphans branch June 10, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:import topic:3d
Projects
Development

Successfully merging this pull request may close these issues.

5 participants