Hours figuring out how animation systems work

This commit is contained in:
The 64th Gamer 2025-04-07 21:40:53 -06:00
parent 8359479243
commit 6488a0499e
4 changed files with 266 additions and 16 deletions

View file

@ -1,19 +1,9 @@
[gd_scene load_steps=5 format=3 uid="uid://cry2msqosqx0u"] [gd_scene load_steps=3 format=3 uid="uid://cry2msqosqx0u"]
[ext_resource type="PackedScene" uid="uid://m7s5j51nrkg1" path="res://Models/Animatronics/Chica/Chica.fbx" id="1_4j8or"] [ext_resource type="PackedScene" uid="uid://m7s5j51nrkg1" path="res://Models/Animatronics/Chica/Chica.fbx" id="1_4j8or"]
[ext_resource type="Script" uid="uid://iqrmm33dxvui" path="res://Scripts/GL_Animatronic.gd" id="1_vcqxk"] [ext_resource type="Script" uid="uid://iqrmm33dxvui" path="res://Scripts/GL_Animatronic.gd" id="1_vcqxk"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_vcqxk"]
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_aslrn"]
graph_offset = Vector2(-475.5, -2.24493)
nodes/Animation/node = SubResource("AnimationNodeAnimation_vcqxk")
nodes/Animation/position = Vector2(-180, 120)
[node name="Chica" type="Node3D" groups=["AA_CHICA"]] [node name="Chica" type="Node3D" groups=["AA_CHICA"]]
script = ExtResource("1_vcqxk") script = ExtResource("1_vcqxk")
[node name="Chica" parent="." instance=ExtResource("1_4j8or")] [node name="Chica" parent="." instance=ExtResource("1_4j8or")]
[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource("AnimationNodeBlendTree_aslrn")

View file

@ -10,10 +10,9 @@ mouse_filter = 1
[node name="Node" parent="." instance=ExtResource("1_6fnvm")] [node name="Node" parent="." instance=ExtResource("1_6fnvm")]
layout_mode = 0 layout_mode = 0
offset_bottom = 100.0
script = ExtResource("2_6fnvm") script = ExtResource("2_6fnvm")
identification = "AA_CHICA" identification = "AA_CHICA"
names = PackedStringArray("Jaw") names = PackedStringArray("Armature_001|Jaw")
types = PackedStringArray("float") types = PackedStringArray("float")
[connection signal="mouse_entered" from="Node" to="Node" method="mouse_enter"] [connection signal="mouse_entered" from="Node" to="Node" method="mouse_enter"]

View file

@ -10,13 +10,74 @@ func _ready():
# Initialize the AnimationTree and set up the blend tree # Initialize the AnimationTree and set up the blend tree
anim_tree = AnimationTree.new() anim_tree = AnimationTree.new()
anim_tree.anim_player = anim_player.get_path()
add_child(anim_tree) add_child(anim_tree)
# Create and assign the root node for the blend tree # Create and assign the root node for the blend tree
anim_tree.tree_root = AnimationNodeBlendTree.new() anim_tree.tree_root = AnimationNodeAnimation.new()
anim_tree.active = true anim_tree.active = true
var animations = anim_player.get_animation_list()
if animations.size() == 0:
return
blend_tree = AnimationNodeBlendTree.new()
anim_tree.tree_root = blend_tree
# Handle single animation case
if animations.size() == 1:
var node_name = "Anim_" + animations[0]
var anim_node := AnimationNodeAnimation.new()
anim_node.animation = animations[0]
blend_tree.add_node(node_name, anim_node, Vector2.ZERO)
var output := AnimationNodeOutput.new()
blend_tree.add_node("Output", output, Vector2(200, 0))
blend_tree.connect_node("Output", 0, node_name)
return
# Start with the first animation
var prev_name = "Anim_" + animations[0]
var prev_anim_node := AnimationNodeAnimation.new()
prev_anim_node.animation = animations[0]
blend_tree.add_node(prev_name, prev_anim_node, Vector2.ZERO)
# Iteratively add and connect animations through Add2 nodes
for i in range(1, animations.size()):
var anim_name = "Anim_" + animations[i]
var add_name = "Add_" + str(i)
var new_anim_node := AnimationNodeAnimation.new()
new_anim_node.animation = animations[i]
blend_tree.add_node(anim_name, new_anim_node, Vector2(i * 200, 0))
var add_node := AnimationNodeAdd2.new()
anim_tree.set("parameters/" + add_name + "/add_amount", 1.0)
blend_tree.add_node(add_name, add_node, Vector2(i * 200, 100))
blend_tree.connect_node(add_name, 0, prev_name)
blend_tree.connect_node(add_name, 1, anim_name)
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)
blend_tree = anim_tree.tree_root as AnimationNodeBlendTree
func _sent_signals(anim_name: String, value: float): func _sent_signals(anim_name: String, value: float):
pass if not anim_tree:
return
var anim_path = "parameters/Anim_" + anim_name + "/time"
var anim_player = get_child(0).get_node("AnimationPlayer") as AnimationPlayer
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
var time_value = clamp(value, 0.0, 1.0) * anim_length
anim_tree.set(anim_path, time_value)

200
test.tscn Normal file
View file

@ -0,0 +1,200 @@
[gd_scene load_steps=40 format=3 uid="uid://b34dmo17ul30r"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_mf4mk"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_37kl0"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_8uh7m"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_6uqi0"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ppyta"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ykrsh"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_g14j6"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_vbegm"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_ehkex"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_xersf"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_00tp4"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_77dp3"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_5tkv4"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_0m0f1"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_b0q6j"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_mhym6"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_a3se8"]
[sub_resource type="AnimationNodeAdd2" id="AnimationNodeAdd2_uty7l"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_45l4g"]
animation = &"Armature_001|Eyebrow L Down"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_4uo0j"]
animation = &"Armature_001|Eyebrow L Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_vxl6d"]
animation = &"Armature_001|Eyebrow R Down"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_eski5"]
animation = &"Armature_001|Eyebrow R Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_pdf00"]
animation = &"Armature_001|Eyelid L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_a6gra"]
animation = &"Armature_001|Eyelid R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dwqlq"]
animation = &"Armature_001|Eyes Down"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_15c7i"]
animation = &"Armature_001|Eyes Left"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_xpeyw"]
animation = &"Armature_001|Eyes Right"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dpmuy"]
animation = &"Armature_001|Eyes Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_j75vh"]
animation = &"Armature_001|Head L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_rrpoi"]
animation = &"Armature_001|Head R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_34fux"]
animation = &"Armature_001|Head Tilt L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_ppv7d"]
animation = &"Armature_001|Head Tilt R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_naet1"]
animation = &"Armature_001|Head Up"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_6qlrc"]
animation = &"Armature_001|Jaw"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_shobf"]
animation = &"Armature_001|Underlid L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_lb1cv"]
animation = &"Armature_001|Underlid R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yww54"]
animation = &"Armature_001|Head Down"
[sub_resource type="AnimationNodeOutput" id="AnimationNodeOutput_2h37t"]
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_adp8l"]
graph_offset = Vector2(1784.38, 49.2519)
nodes/Add_1/node = SubResource("AnimationNodeAdd2_mf4mk")
nodes/Add_1/position = Vector2(200, 100)
nodes/Add_10/node = SubResource("AnimationNodeAdd2_37kl0")
nodes/Add_10/position = Vector2(2000, 100)
nodes/Add_11/node = SubResource("AnimationNodeAdd2_8uh7m")
nodes/Add_11/position = Vector2(2200, 100)
nodes/Add_12/node = SubResource("AnimationNodeAdd2_6uqi0")
nodes/Add_12/position = Vector2(2400, 100)
nodes/Add_13/node = SubResource("AnimationNodeAdd2_ppyta")
nodes/Add_13/position = Vector2(2600, 100)
nodes/Add_14/node = SubResource("AnimationNodeAdd2_ykrsh")
nodes/Add_14/position = Vector2(2800, 100)
nodes/Add_15/node = SubResource("AnimationNodeAdd2_g14j6")
nodes/Add_15/position = Vector2(3000, 100)
nodes/Add_16/node = SubResource("AnimationNodeAdd2_vbegm")
nodes/Add_16/position = Vector2(3200, 100)
nodes/Add_17/node = SubResource("AnimationNodeAdd2_ehkex")
nodes/Add_17/position = Vector2(3400, 100)
nodes/Add_18/node = SubResource("AnimationNodeAdd2_xersf")
nodes/Add_18/position = Vector2(3600, 100)
nodes/Add_2/node = SubResource("AnimationNodeAdd2_00tp4")
nodes/Add_2/position = Vector2(400, 100)
nodes/Add_3/node = SubResource("AnimationNodeAdd2_77dp3")
nodes/Add_3/position = Vector2(600, 100)
nodes/Add_4/node = SubResource("AnimationNodeAdd2_5tkv4")
nodes/Add_4/position = Vector2(800, 100)
nodes/Add_5/node = SubResource("AnimationNodeAdd2_0m0f1")
nodes/Add_5/position = Vector2(1000, 100)
nodes/Add_6/node = SubResource("AnimationNodeAdd2_b0q6j")
nodes/Add_6/position = Vector2(1200, 100)
nodes/Add_7/node = SubResource("AnimationNodeAdd2_mhym6")
nodes/Add_7/position = Vector2(1400, 100)
nodes/Add_8/node = SubResource("AnimationNodeAdd2_a3se8")
nodes/Add_8/position = Vector2(1600, 100)
nodes/Add_9/node = SubResource("AnimationNodeAdd2_uty7l")
nodes/Add_9/position = Vector2(1800, 100)
"nodes/Anim_Armature_001|Eyebrow L Down/node" = SubResource("AnimationNodeAnimation_45l4g")
"nodes/Anim_Armature_001|Eyebrow L Down/position" = Vector2(-200, 120)
"nodes/Anim_Armature_001|Eyebrow L Up/node" = SubResource("AnimationNodeAnimation_4uo0j")
"nodes/Anim_Armature_001|Eyebrow L Up/position" = Vector2(-200, 340)
"nodes/Anim_Armature_001|Eyebrow R Down/node" = SubResource("AnimationNodeAnimation_vxl6d")
"nodes/Anim_Armature_001|Eyebrow R Down/position" = Vector2(400, 0)
"nodes/Anim_Armature_001|Eyebrow R Up/node" = SubResource("AnimationNodeAnimation_eski5")
"nodes/Anim_Armature_001|Eyebrow R Up/position" = Vector2(600, 0)
"nodes/Anim_Armature_001|Eyelid L/node" = SubResource("AnimationNodeAnimation_pdf00")
"nodes/Anim_Armature_001|Eyelid L/position" = Vector2(800, 0)
"nodes/Anim_Armature_001|Eyelid R/node" = SubResource("AnimationNodeAnimation_a6gra")
"nodes/Anim_Armature_001|Eyelid R/position" = Vector2(1000, 0)
"nodes/Anim_Armature_001|Eyes Down/node" = SubResource("AnimationNodeAnimation_dwqlq")
"nodes/Anim_Armature_001|Eyes Down/position" = Vector2(1200, 0)
"nodes/Anim_Armature_001|Eyes Left/node" = SubResource("AnimationNodeAnimation_15c7i")
"nodes/Anim_Armature_001|Eyes Left/position" = Vector2(1400, 0)
"nodes/Anim_Armature_001|Eyes Right/node" = SubResource("AnimationNodeAnimation_xpeyw")
"nodes/Anim_Armature_001|Eyes Right/position" = Vector2(1600, 0)
"nodes/Anim_Armature_001|Eyes Up/node" = SubResource("AnimationNodeAnimation_dpmuy")
"nodes/Anim_Armature_001|Eyes Up/position" = Vector2(980, -200)
"nodes/Anim_Armature_001|Head L/node" = SubResource("AnimationNodeAnimation_j75vh")
"nodes/Anim_Armature_001|Head L/position" = Vector2(1480, -220)
"nodes/Anim_Armature_001|Head R/node" = SubResource("AnimationNodeAnimation_rrpoi")
"nodes/Anim_Armature_001|Head R/position" = Vector2(1780, -220)
"nodes/Anim_Armature_001|Head Tilt L/node" = SubResource("AnimationNodeAnimation_34fux")
"nodes/Anim_Armature_001|Head Tilt L/position" = Vector2(2120, -240)
"nodes/Anim_Armature_001|Head Tilt R/node" = SubResource("AnimationNodeAnimation_ppv7d")
"nodes/Anim_Armature_001|Head Tilt R/position" = Vector2(2500, -260)
"nodes/Anim_Armature_001|Head Up/node" = SubResource("AnimationNodeAnimation_naet1")
"nodes/Anim_Armature_001|Head Up/position" = Vector2(2860, -180)
nodes/Anim_Armature_001|Jaw/node = SubResource("AnimationNodeAnimation_6qlrc")
nodes/Anim_Armature_001|Jaw/position = Vector2(3100, -140)
"nodes/Anim_Armature_001|Underlid L/node" = SubResource("AnimationNodeAnimation_shobf")
"nodes/Anim_Armature_001|Underlid L/position" = Vector2(3340, -120)
"nodes/Anim_Armature_001|Underlid R/node" = SubResource("AnimationNodeAnimation_lb1cv")
"nodes/Anim_Armature_001|Underlid R/position" = Vector2(3660, -80)
"nodes/Anim_Armature_new_add_name001|Head Down/node" = SubResource("AnimationNodeAnimation_yww54")
"nodes/Anim_Armature_new_add_name001|Head Down/position" = Vector2(1200, -460)
nodes/Output/node = SubResource("AnimationNodeOutput_2h37t")
nodes/Output/position = Vector2(4000, 100)
nodes/output/position = Vector2(4040, 280)
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_new_add_name001|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("../Chica")
tree_root = SubResource("AnimationNodeBlendTree_adp8l")
anim_player = NodePath("/root/Freddy\'s/Chica/Chica/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