Skip to content

Instantly share code, notes, and snippets.

@thayol
Created May 15, 2024 06:33
Show Gist options
  • Save thayol/9c9df81f85b776adc7246ca58971ddf7 to your computer and use it in GitHub Desktop.
Save thayol/9c9df81f85b776adc7246ca58971ddf7 to your computer and use it in GitHub Desktop.
Godot glTF import script: extra root node fix (reparent/remove)
@tool
extends EditorScenePostImport
func _post_import(scene):
var fake_root = scene.get_child(0) # glTF's root "scene" node
# Remove the wrongly imported fake root node
reparent_children(fake_root, scene)
fake_root.queue_free()
# Rename "Node" based on the file name
scene.name = basename().replace("-", "_").to_pascal_case()
return scene
func reparent_children(node, new_parent):
for child in node.get_children():
reparent(child, new_parent)
func reparent(node, new_parent):
var old_parent = node.get_parent()
node.owner = null
old_parent.remove_child(node)
new_parent.add_child(node)
node.owner = new_parent
func basename():
return get_source_file().get_file().get_basename()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment