135 lines
3.9 KiB
GDScript
135 lines
3.9 KiB
GDScript
extends Spatial
|
|
|
|
|
|
var animation_object = null
|
|
var orientation = 0.0
|
|
var blend_shapes = {}
|
|
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
|
|
|
|
|
|
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/raference.tscn" )
|
|
idle_animation = "_bip01_ca_female_idle"
|
|
search_animation(self)
|
|
#Config.msg_debug("Start Animation")
|
|
animation_object.play( idle_animation )
|
|
animation_object.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
|
|
update_blend_shapes($creature)
|
|
|
|
func _on_AnimationPlayer_animation_finished(anim_name):
|
|
Config.msg_debug("Animation finished:" + anim_name)
|
|
animation_object.play( anim_name )
|
|
|
|
func _process( delta ):
|
|
# _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 )
|
|
|
|
|
|
func _on_select_race( race_sex_selected ):
|
|
Config.msg_debug(race_sex_selected)
|
|
match race_sex_selected:
|
|
"arche":
|
|
idle_animation = "idle"
|
|
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
|
|
"isidor":
|
|
idle_animation = "idle"
|
|
self.change_creature( "res://scenes/creature_creation/isidor.tscn" )
|
|
"raference":
|
|
idle_animation = "_bip01_ca_female_idle"
|
|
self.change_creature( "res://scenes/creature_creation/raference.tscn" )
|
|
_:
|
|
idle_animation = ""
|
|
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
|
|
search_animation(self)
|
|
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 )
|