root/3d/nyoron/fix_head_import.gd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
tool
extends EditorScenePostImport

func post_import(scene):
	var body = scene.get_node("body")
	var head = scene.get_node("head")
	
	head.owner = scene
	
	scene.remove_child(head)
	body.add_child(head)
	head.owner = scene
	for c in head.get_children():
		c.owner = scene
	
	for c in scene.get_children():
		if c.name.begins_with("body_"):
			scene.remove_child(c)
			body.add_child(c)
			c.owner = scene
			for c2 in c.get_children():
				c2.owner = scene
	body.owner = scene
	

	for c in scene.get_children():
		print(c.name)
	return scene


func reparent(child, new_parent):
	print(child.name, " to ", new_parent.name)
	if new_parent and child:
		var old_transform = child.transform
		var old = child.get_parent()
		if old:
			old.remove_child(child)
		child.transform = old_transform
		new_parent.add_child(child.duplicate())