GLTF: Add append_gltf_node
to GLTFState
#96468
Merged
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.
This PR adds
append_gltf_node
to GLTFState, andappend_child_index
to GLTFNode.The
append_gltf_node
method is mostly the same as the previous internal_create_gltf_node
, but cleaned up. Here are some of the differences:append_gltf_node
is responsible for determining the index it's inserting into, and returns it. The API of_create_gltf_node
basically just trusted that the caller did not get it wrong, now it's always correct by design (to be clear the old code behaved correctly, but only because it was used correctly in the one place it was used).append_gltf_node
will handle setting the given node as a root node, if the parent was -1. This responsibility was previously handled byGLTFDocument::_convert_scene_node
.append_gltf_node
has detailed documentation explaining when it can be called and what input is valid.append_gltf_node
is used to append the current node duringconvert_scene_node
extension code, then it won't also be appended by GLTFDocument. This allows extensions to "move" a node to another parent on export.I am proposing to expose this method because I need it in a GLTFDocumentExtension class for export logic. Currently the glTF exporter code expects that one Godot node should become one glTF node, and there's no (easy) way to make multiple glTF nodes for one Godot node. With this method exposed, now it's easy. I need this to allow my GLTFDocumentExtension class to export multiple glTF nodes from one Godot node, and I have tested this PR with that project.
As for adding
append_child_index
to GLTFNode, this doesn't work:gltf_node.children.append(5)
. You would need to make a local variable, then append to it, then set it back. That's 3 lines for what could just be 1, so that's why I'm adding this method to allow doinggltf_node.append_child_index(5)
.