This commit is contained in:
The 64th Gamer 2025-04-07 22:38:00 -06:00
parent 74be4fe466
commit 973c560b9f
2 changed files with 216 additions and 13 deletions

View file

@ -10,21 +10,22 @@ func _ready():
# Initialize the AnimationTree and set up the blend tree
anim_tree = AnimationTree.new()
anim_tree.anim_player = anim_player.get_path()
anim_tree.anim_player = anim_player.get_path() # Set the path to the AnimationPlayer
add_child(anim_tree)
# Create and assign the root node for the blend tree
anim_tree.tree_root = AnimationNodeAnimation.new()
# Create the blend tree
anim_tree.tree_root = AnimationNodeBlendTree.new()
anim_tree.active = true
blend_tree = anim_tree.tree_root as AnimationNodeBlendTree
# Disable automatic playback of animations
anim_player.speed_scale = 0 # This will stop the animation from automatically playing
var animations = anim_player.get_animation_list()
if animations.size() == 0:
return
blend_tree = AnimationNodeBlendTree.new()
anim_tree.tree_root = blend_tree
anim_player.speed_scale = 0
# Handle single animation case
# Handle the case where there is only one animation
if animations.size() == 1:
var node_name = "Anim_" + animations[0]
var anim_node := AnimationNodeAnimation.new()
@ -36,7 +37,7 @@ func _ready():
blend_tree.connect_node("Output", 0, node_name)
return
# Start with the first animation
# Start with the first animation node
var prev_name = "Anim_" + animations[0]
var prev_anim_node := AnimationNodeAnimation.new()
prev_anim_node.animation = animations[0]
@ -58,13 +59,14 @@ func _ready():
prev_name = add_name
# Final output node connection
#var output := AnimationNodeOutput.new()
#blend_tree.add_node("Output", output, Vector2((animations.size() + 1) * 200, 100))
blend_tree.connect_node("output", 0, prev_name)
for i in range(0,animations.size()):
# Set the blend amount for each additive node
for i in range(0, animations.size()):
anim_tree.set("parameters/Add_" + str(i) + "/add_amount", 1.0)
# Function to set the time of the animation based on a normalized value (0.0 to 1.0)
func _sent_signals(anim_name: String, value: float):
if not anim_tree:
return
@ -74,7 +76,6 @@ func _sent_signals(anim_name: String, value: float):
if not anim_player.has_animation(anim_name):
print("Animation not found: ", anim_name)
print(anim_player.get_animation_list())
return
var anim_length = anim_player.get_animation(anim_name).length

202
test4.tscn Normal file
View file

@ -0,0 +1,202 @@
[gd_scene load_steps=40 format=3 uid="uid://b3tysebs8i7po"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_x54fa"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_d61hk"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_qxfyu"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_qru2l"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_qm8xs"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_u7hql"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ye4m3"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_o6gik"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ip4l6"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ckal1"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ibgny"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_dwc8p"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_cbqyw"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_1myad"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_f5iex"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_i3bg6"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_hx4q6"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ujn16"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_aipfx"]
animation = &"Armature_001|Eyebrow L Down"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_0ipva"]
animation = &"Armature_001|Eyebrow L Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_1465b"]
animation = &"Armature_001|Eyebrow R Down"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yemhi"]
animation = &"Armature_001|Eyebrow R Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_ehx5t"]
animation = &"Armature_001|Eyelid L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_mrlmf"]
animation = &"Armature_001|Eyelid R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dwkga"]
animation = &"Armature_001|Eyes Down"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_s8o4k"]
animation = &"Armature_001|Eyes Left"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_5bg5e"]
animation = &"Armature_001|Eyes Right"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_xd8h7"]
animation = &"Armature_001|Eyes Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_ywl6w"]
animation = &"Armature_001|Head Down"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_heluu"]
animation = &"Armature_001|Head L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_6fg05"]
animation = &"Armature_001|Head R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_fhno2"]
animation = &"Armature_001|Head Tilt L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_rxjjn"]
animation = &"Armature_001|Head Tilt R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_23h45"]
animation = &"Armature_001|Head Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_mb8rh"]
animation = &"Armature_001|Jaw"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_ack4d"]
animation = &"Armature_001|Underlid L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_24th1"]
animation = &"Armature_001|Underlid R"
[sub_resource type="AnimationNodeOutput" id="AnimationNodeOutput_1kfqo"]
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_mob0c"]
graph_offset = Vector2(-382.646, 32.9876)
nodes/Add_1/node = SubResource("AnimationNodeAdd2_x54fa")
nodes/Add_1/position = Vector2(400, -40)
nodes/Add_10/node = SubResource("AnimationNodeAdd2_d61hk")
nodes/Add_10/position = Vector2(2460, -340)
nodes/Add_11/node = SubResource("AnimationNodeAdd2_qxfyu")
nodes/Add_11/position = Vector2(2680, -380)
nodes/Add_12/node = SubResource("AnimationNodeAdd2_qru2l")
nodes/Add_12/position = Vector2(2920, -400)
nodes/Add_13/node = SubResource("AnimationNodeAdd2_qm8xs")
nodes/Add_13/position = Vector2(3140, -440)
nodes/Add_14/node = SubResource("AnimationNodeAdd2_u7hql")
nodes/Add_14/position = Vector2(3380, -480)
nodes/Add_15/node = SubResource("AnimationNodeAdd2_ye4m3")
nodes/Add_15/position = Vector2(3600, -520)
nodes/Add_16/node = SubResource("AnimationNodeAdd2_o6gik")
nodes/Add_16/position = Vector2(3820, -540)
nodes/Add_17/node = SubResource("AnimationNodeAdd2_ip4l6")
nodes/Add_17/position = Vector2(4060, -580)
nodes/Add_18/node = SubResource("AnimationNodeAdd2_ckal1")
nodes/Add_18/position = Vector2(4280, -620)
nodes/Add_2/node = SubResource("AnimationNodeAdd2_ibgny")
nodes/Add_2/position = Vector2(620, -60)
nodes/Add_3/node = SubResource("AnimationNodeAdd2_dwc8p")
nodes/Add_3/position = Vector2(860, -100)
nodes/Add_4/node = SubResource("AnimationNodeAdd2_cbqyw")
nodes/Add_4/position = Vector2(1080, -140)
nodes/Add_5/node = SubResource("AnimationNodeAdd2_1myad")
nodes/Add_5/position = Vector2(1300, -160)
nodes/Add_6/node = SubResource("AnimationNodeAdd2_f5iex")
nodes/Add_6/position = Vector2(1540, -200)
nodes/Add_7/node = SubResource("AnimationNodeAdd2_i3bg6")
nodes/Add_7/position = Vector2(1760, -240)
nodes/Add_8/node = SubResource("AnimationNodeAdd2_hx4q6")
nodes/Add_8/position = Vector2(2000, -280)
nodes/Add_9/node = SubResource("AnimationNodeAdd2_ujn16")
nodes/Add_9/position = Vector2(2220, -300)
"nodes/Anim_Armature_001|Eyebrow L Down/node" = SubResource("AnimationNodeAnimation_aipfx")
"nodes/Anim_Armature_001|Eyebrow L Down/position" = Vector2(0, 0)
"nodes/Anim_Armature_001|Eyebrow L Up/node" = SubResource("AnimationNodeAnimation_0ipva")
"nodes/Anim_Armature_001|Eyebrow L Up/position" = Vector2(0, 260)
"nodes/Anim_Armature_001|Eyebrow R Down/node" = SubResource("AnimationNodeAnimation_1465b")
"nodes/Anim_Armature_001|Eyebrow R Down/position" = Vector2(0, 520)
"nodes/Anim_Armature_001|Eyebrow R Up/node" = SubResource("AnimationNodeAnimation_yemhi")
"nodes/Anim_Armature_001|Eyebrow R Up/position" = Vector2(0, 780)
"nodes/Anim_Armature_001|Eyelid L/node" = SubResource("AnimationNodeAnimation_ehx5t")
"nodes/Anim_Armature_001|Eyelid L/position" = Vector2(0, 1040)
"nodes/Anim_Armature_001|Eyelid R/node" = SubResource("AnimationNodeAnimation_mrlmf")
"nodes/Anim_Armature_001|Eyelid R/position" = Vector2(0, 1300)
"nodes/Anim_Armature_001|Eyes Down/node" = SubResource("AnimationNodeAnimation_dwkga")
"nodes/Anim_Armature_001|Eyes Down/position" = Vector2(0, 1540)
"nodes/Anim_Armature_001|Eyes Left/node" = SubResource("AnimationNodeAnimation_s8o4k")
"nodes/Anim_Armature_001|Eyes Left/position" = Vector2(0, 1800)
"nodes/Anim_Armature_001|Eyes Right/node" = SubResource("AnimationNodeAnimation_5bg5e")
"nodes/Anim_Armature_001|Eyes Right/position" = Vector2(0, 2060)
"nodes/Anim_Armature_001|Eyes Up/node" = SubResource("AnimationNodeAnimation_xd8h7")
"nodes/Anim_Armature_001|Eyes Up/position" = Vector2(0, 2320)
"nodes/Anim_Armature_001|Head Down/node" = SubResource("AnimationNodeAnimation_ywl6w")
"nodes/Anim_Armature_001|Head Down/position" = Vector2(0, 2580)
"nodes/Anim_Armature_001|Head L/node" = SubResource("AnimationNodeAnimation_heluu")
"nodes/Anim_Armature_001|Head L/position" = Vector2(0, 2840)
"nodes/Anim_Armature_001|Head R/node" = SubResource("AnimationNodeAnimation_6fg05")
"nodes/Anim_Armature_001|Head R/position" = Vector2(0, 3100)
"nodes/Anim_Armature_001|Head Tilt L/node" = SubResource("AnimationNodeAnimation_fhno2")
"nodes/Anim_Armature_001|Head Tilt L/position" = Vector2(0, 3360)
"nodes/Anim_Armature_001|Head Tilt R/node" = SubResource("AnimationNodeAnimation_rxjjn")
"nodes/Anim_Armature_001|Head Tilt R/position" = Vector2(0, 3620)
"nodes/Anim_Armature_001|Head Up/node" = SubResource("AnimationNodeAnimation_23h45")
"nodes/Anim_Armature_001|Head Up/position" = Vector2(0, 3880)
nodes/Anim_Armature_001|Jaw/node = SubResource("AnimationNodeAnimation_mb8rh")
nodes/Anim_Armature_001|Jaw/position = Vector2(0, 4120)
"nodes/Anim_Armature_001|Underlid L/node" = SubResource("AnimationNodeAnimation_ack4d")
"nodes/Anim_Armature_001|Underlid L/position" = Vector2(0, 4380)
"nodes/Anim_Armature_001|Underlid R/node" = SubResource("AnimationNodeAnimation_24th1")
"nodes/Anim_Armature_001|Underlid R/position" = Vector2(0, 4640)
nodes/Output/node = SubResource("AnimationNodeOutput_1kfqo")
nodes/Output/position = Vector2(160, 4900)
nodes/output/position = Vector2(4520, -600)
node_connections = [&"Add_1", 0, &"Anim_Armature_001|Eyebrow L Down", &"Add_1", 1, &"Anim_Armature_001|Eyebrow L Up", &"Add_10", 0, &"Add_9", &"Add_10", 1, &"Anim_Armature_001|Head Down", &"Add_11", 0, &"Add_10", &"Add_11", 1, &"Anim_Armature_001|Head L", &"Add_12", 0, &"Add_11", &"Add_12", 1, &"Anim_Armature_001|Head R", &"Add_13", 0, &"Add_12", &"Add_13", 1, &"Anim_Armature_001|Head Tilt L", &"Add_14", 0, &"Add_13", &"Add_14", 1, &"Anim_Armature_001|Head Tilt R", &"Add_15", 0, &"Add_14", &"Add_15", 1, &"Anim_Armature_001|Head Up", &"Add_16", 0, &"Add_15", &"Add_16", 1, &"Anim_Armature_001|Jaw", &"Add_17", 0, &"Add_16", &"Add_17", 1, &"Anim_Armature_001|Underlid L", &"Add_18", 0, &"Add_17", &"Add_18", 1, &"Anim_Armature_001|Underlid R", &"Add_2", 0, &"Add_1", &"Add_2", 1, &"Anim_Armature_001|Eyebrow R Down", &"Add_3", 0, &"Add_2", &"Add_3", 1, &"Anim_Armature_001|Eyebrow R Up", &"Add_4", 0, &"Add_3", &"Add_4", 1, &"Anim_Armature_001|Eyelid L", &"Add_5", 0, &"Add_4", &"Add_5", 1, &"Anim_Armature_001|Eyelid R", &"Add_6", 0, &"Add_5", &"Add_6", 1, &"Anim_Armature_001|Eyes Down", &"Add_7", 0, &"Add_6", &"Add_7", 1, &"Anim_Armature_001|Eyes Left", &"Add_8", 0, &"Add_7", &"Add_8", 1, &"Anim_Armature_001|Eyes Right", &"Add_9", 0, &"Add_8", &"Add_9", 1, &"Anim_Armature_001|Eyes Up", &"output", 0, &"Add_18"]
[node name="_AnimationTree_3" type="AnimationTree"]
root_node = NodePath(".")
tree_root = SubResource("AnimationNodeBlendTree_mob0c")
anim_player = NodePath("AnimationPlayer")
parameters/Add_1/add_amount = 1.0
parameters/Add_10/add_amount = 1.0
parameters/Add_11/add_amount = 1.0
parameters/Add_12/add_amount = 1.0
parameters/Add_13/add_amount = 1.0
parameters/Add_14/add_amount = 1.0
parameters/Add_15/add_amount = 1.0
parameters/Add_16/add_amount = 1.0
parameters/Add_17/add_amount = 1.0
parameters/Add_18/add_amount = 1.0
parameters/Add_2/add_amount = 1.0
parameters/Add_3/add_amount = 1.0
parameters/Add_4/add_amount = 1.0
parameters/Add_5/add_amount = 1.0
parameters/Add_6/add_amount = 1.0
parameters/Add_7/add_amount = 1.0
parameters/Add_8/add_amount = 1.0
parameters/Add_9/add_amount = 1.0
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]