khanat-client/scenes/creature_creation/creature_creation.gd
2021-06-29 21:40:38 +02:00

116 lines
3.1 KiB
GDScript

extends Spatial
var animation_object = null
var orientation = 0.0
var blend_shapes = {}
func search_animation( obj ) -> bool:
var ret:bool = false
for i in obj.get_children():
if i.get_name() == "AnimationPlayer":
animation_object = i
return true
else:
ret = search_animation(i)
if ret == true:
return ret
return false
func list_child( obj, father = "" ):
for i in obj.get_children():
var root = father + "." + str(i.name)
Config.msg_debug(root)
if i is MeshInstance:
Config.msg_debug(root + " -> MeshInstance")
for key in i.get_property_list():
Config.msg_debug( "property:" + str(key))
list_child( i, root)
func list_blend_shapes( obj, father = "" ) -> Array:
var ret:Array
for i in obj.get_children():
var root = father + "." + str(i.name)
if i is MeshInstance:
for key in i.get_property_list():
if key.name.substr(0, 13) == "blend_shapes/":
# Config.msg_debug( father + "." + i.name + " - " + key.name.substr(13) )
ret.append(key.name.substr(13))
list_blend_shapes( i, root)
return ret
func update_blend_shapes_step( obj, father = "" ):
for i in obj.get_children():
var root = father + str(i.name) + "."
if i is MeshInstance:
for key in i.get_property_list():
if key.name.substr(0, 13) == "blend_shapes/":
var blend = key.name.substr(13)
# Config.msg_debug( father + i.name + " - " + key.name.substr(13) )
if not blend_shapes.has(blend):
blend_shapes[blend] = []
blend_shapes[blend].append(i)
update_blend_shapes_step( i, root)
func update_blend_shapes( obj ):
blend_shapes = {}
update_blend_shapes_step(obj, "")
# for key in blend_shapes:
# Config.msg_debug("key:" + key + " = " + str(blend_shapes[key]))
$control.update_property(blend_shapes)
func _ready():
$control.connect("update_blend" , self, "_on_update_property")
$control.connect( "select_race", self, "_on_select_race" )
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
search_animation(self)
update_blend_shapes($creature)
func _process( delta ):
animation_object.play( "idle" )
func _input( event ):
# Config.msg_debug(str(event))
if event is InputEventMouseMotion and Input.is_mouse_button_pressed( 2 ):
if $creature:
$creature.rotate_y( event.relative.x *0.01 )
func change_creature( new_model_path ):
if $creature:
var old_model = $creature
self.remove_child( old_model )
old_model.queue_free()
var new_model = load( new_model_path )
if new_model:
new_model = new_model.instance()
new_model.name = "creature"
self.add_child( new_model )
func _on_select_race( race_sex_selected ):
Config.msg_debug(race_sex_selected)
match race_sex_selected:
"arche":
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
"isidor":
self.change_creature( "res://scenes/creature_creation/isidor.tscn" )
_:
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
search_animation(self)
update_blend_shapes($creature)
func _on_update_property(name_property, value):
Config.msg_debug( name_property + ": " + str(value) )
for i in blend_shapes[name_property]:
i.set( "blend_shapes/"+name_property, value )