khanat-client/scenes/creature_creation/creature_creation.gd

136 lines
3.9 KiB
GDScript3
Raw Normal View History

extends Spatial
var animation_object = null
var orientation = 0.0
var blend_shapes = {}
2021-09-03 21:27:28 +00:00
var idle_animation = "idle"
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
2021-06-29 19:40:38 +00:00
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" )
2021-09-03 21:27:28 +00:00
self.change_creature( "res://scenes/creature_creation/raference.tscn" )
idle_animation = "_bip01_ca_female_idle"
search_animation(self)
2021-09-03 21:27:28 +00:00
#Config.msg_debug("Start Animation")
animation_object.play( idle_animation )
animation_object.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
update_blend_shapes($creature)
2021-09-03 21:27:28 +00:00
func _on_AnimationPlayer_animation_finished(anim_name):
Config.msg_debug("Animation finished:" + anim_name)
animation_object.play( anim_name )
func _process( delta ):
2021-09-03 21:27:28 +00:00
# _bip01_ca_female_idle
#if idle_animation:
# animation_object.play( idle_animation )
# animation_object.play( "idle" )
pass
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 )
2021-06-29 19:40:38 +00:00
func _on_select_race( race_sex_selected ):
Config.msg_debug(race_sex_selected)
match race_sex_selected:
"arche":
2021-09-03 21:27:28 +00:00
idle_animation = "idle"
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
"isidor":
2021-09-03 21:27:28 +00:00
idle_animation = "idle"
self.change_creature( "res://scenes/creature_creation/isidor.tscn" )
2021-09-03 21:27:28 +00:00
"raference":
idle_animation = "_bip01_ca_female_idle"
self.change_creature( "res://scenes/creature_creation/raference.tscn" )
_:
2021-09-03 21:27:28 +00:00
idle_animation = ""
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
search_animation(self)
2021-09-03 21:27:28 +00:00
animation_object.play( idle_animation )
animation_object.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
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 )