GLTFExporter: Push nodes parent-first instead of child-first #31125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #31112
Description
Currently, if you have a Three.js Object3D hierarchy like this:
Then it will get exported to glTF child-first: node A at index 2, node B at index 0, and node C at index 1. Node A will have the
"children"
array set to[0, 1]
and the glTF scene will have its root nodes set to[2]
.With this PR, it will instead export to the glTF parent-first: node A at index 0, node B at index 1, and node C at index 2. Node A will have the
"children"
array set to[1, 2]
and the glTF scene will have its root nodes set to[0]
.Any order is fine for the most part, since glTF itself does not explicitly require any order, and does not suggest a preferred order. glTF importers can import any order, and changing the order does not affect compatibility. Blender uses the same order, too. However, UnityGLTF and Godot both use parent-first order. I'd argue it's more human-readable this way, because the first node in the array tells you the start of the tree, and well, if you display it visually like I did above, you put the root at the top anyway. Most importantly,
GODOT_single_root
has a requirement that the root node is at index 0, since the goal is to make the"scene"
and"scenes"
properties fully redundant, as they are usually not useful for glTF files representing "one object". Changing the order Three.js exports nodes in matchesGODOT_single_root
and other game engines, with no downsides, so it should be done regardless of whether or not the exported file has theGODOT_single_root
flag in it.