@tool
extends EditorScenePostImport

var regular_outline_material : StandardMaterial3D
var character_outline_material : StandardMaterial3D
var outline_disable_flag : String = "-nooutline"

func _post_import(root : Node):
	regular_outline_material = ResourceLoader.load("res://assets/style/base_outline_material.tres") as StandardMaterial3D
	character_outline_material = ResourceLoader.load("res://assets/style/character_outline_material.tres") as StandardMaterial3D
	apply_outline_recursive(root)
	return root

func apply_outline_recursive(node : Node):
	if node != null:
		if node.name.contains(outline_disable_flag):
			node.name = node.name.erase(node.name.find(outline_disable_flag), outline_disable_flag.length())
		elif node is MeshInstance3D:
			var mesh : MeshInstance3D = (node as MeshInstance3D)
			if mesh.skeleton and character_outline_material:
				mesh.material_overlay = character_outline_material
			elif regular_outline_material:
				mesh.material_overlay = regular_outline_material
		for child in node.get_children():
			apply_outline_recursive(child)
