Skip to content

GLTFExporter: Push nodes parent-first instead of child-first #31125

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
May 18, 2025

Conversation

aaronfranke
Copy link
Contributor

@aaronfranke aaronfranke commented May 17, 2025

Related to #31112

Description

Currently, if you have a Three.js Object3D hierarchy like this:

A
  B
  C

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 matches GODOT_single_root and other game engines, with no downsides, so it should be done regardless of whether or not the exported file has the GODOT_single_root flag in it.

Copy link
Collaborator

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

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

Still thinking about the other PRs, but this one is a clear win/win in my opinion — let's do it, thanks!

@donmccurdy donmccurdy added this to the r177 milestone May 17, 2025
@Mugen87 Mugen87 merged commit 83bc654 into mrdoob:dev May 18, 2025
11 checks passed
@aaronfranke aaronfranke deleted the node-uno-reverse-card branch May 18, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants