Minor additional work on the BlendTreeEditor.
This commit is contained in:
parent
4c428a865a
commit
50243eafba
@ -1,4 +1,5 @@
|
|||||||
@tool
|
@tool
|
||||||
|
class_name BlendalotMainPanel
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
@onready var blend_tree_graph_edit: GraphEdit = %BlendTreeGraphEdit
|
@onready var blend_tree_graph_edit: GraphEdit = %BlendTreeGraphEdit
|
||||||
@ -20,6 +21,8 @@ var registered_nodes = [
|
|||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
add_node_popup_menu.clear(true)
|
||||||
|
|
||||||
for node_name in registered_nodes:
|
for node_name in registered_nodes:
|
||||||
add_node_popup_menu.add_item(node_name)
|
add_node_popup_menu.add_item(node_name)
|
||||||
|
|
||||||
@ -62,6 +65,9 @@ func _on_reset_graph_button_pressed() -> void:
|
|||||||
_reset_editor()
|
_reset_editor()
|
||||||
_update_editor_from_blend_tree()
|
_update_editor_from_blend_tree()
|
||||||
|
|
||||||
|
var graph_rect:Rect2 = blend_tree_graph_edit.get_rect()
|
||||||
|
blend_tree_graph_edit.scroll_offset = graph_rect.size * -0.5 - Vector2(200,0)
|
||||||
|
|
||||||
|
|
||||||
func _reset_editor():
|
func _reset_editor():
|
||||||
for child in blend_tree_graph_edit.get_children():
|
for child in blend_tree_graph_edit.get_children():
|
||||||
@ -79,6 +85,15 @@ func _reset_editor():
|
|||||||
selected_nodes = {}
|
selected_nodes = {}
|
||||||
|
|
||||||
|
|
||||||
|
func edit_blend_tree(blend_tree_animation_node:BLTAnimationNode):
|
||||||
|
print("Starting to edit blend_tree_animation_node " + str(blend_tree_animation_node))
|
||||||
|
print("Owner: %s" % blend_tree_animation_node)
|
||||||
|
_reset_editor()
|
||||||
|
blend_tree = blend_tree_animation_node
|
||||||
|
|
||||||
|
_update_editor_nodes_from_blend_tree()
|
||||||
|
_update_editor_connections_from_blend_tree()
|
||||||
|
|
||||||
func _update_editor_nodes_from_blend_tree():
|
func _update_editor_nodes_from_blend_tree():
|
||||||
for node_name in blend_tree.get_node_names():
|
for node_name in blend_tree.get_node_names():
|
||||||
var blend_tree_node:BLTAnimationNode = blend_tree.get_node(node_name)
|
var blend_tree_node:BLTAnimationNode = blend_tree.get_node(node_name)
|
||||||
@ -190,8 +205,9 @@ func _on_blend_tree_graph_edit_begin_node_move() -> void:
|
|||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
func _on_blend_tree_graph_edit_node_selected(node: Node) -> void:
|
func _on_blend_tree_graph_edit_node_selected(graph_node: Node) -> void:
|
||||||
selected_nodes[node] = node
|
selected_nodes[graph_node] = graph_node
|
||||||
|
EditorInterface.get_inspector().edit(graph_node_to_blend_tree_node[graph_node])
|
||||||
|
|
||||||
|
|
||||||
func _on_blend_tree_graph_edit_node_deselected(node: Node) -> void:
|
func _on_blend_tree_graph_edit_node_deselected(node: Node) -> void:
|
||||||
@ -203,7 +219,7 @@ func _on_blend_tree_graph_edit_popup_request(at_position: Vector2) -> void:
|
|||||||
add_node_popup_menu.position = get_screen_position() + get_local_mouse_position()
|
add_node_popup_menu.position = get_screen_position() + get_local_mouse_position()
|
||||||
add_node_popup_menu.reset_size()
|
add_node_popup_menu.reset_size()
|
||||||
add_node_popup_menu.popup()
|
add_node_popup_menu.popup()
|
||||||
new_node_position = at_position
|
new_node_position = blend_tree_graph_edit.scroll_offset + at_position
|
||||||
|
|
||||||
|
|
||||||
func _on_add_node_popup_menu_index_pressed(index: int) -> void:
|
func _on_add_node_popup_menu_index_pressed(index: int) -> void:
|
||||||
@ -220,3 +236,36 @@ func _on_add_node_popup_menu_index_pressed(index: int) -> void:
|
|||||||
graph_node.position_offset = new_node_position
|
graph_node.position_offset = new_node_position
|
||||||
|
|
||||||
new_node_position = Vector2.INF
|
new_node_position = Vector2.INF
|
||||||
|
|
||||||
|
|
||||||
|
func _on_blend_tree_graph_edit_delete_nodes_request(nodes: Array[StringName]) -> void:
|
||||||
|
for node_name:StringName in nodes:
|
||||||
|
print("remove node '%s'" % node_name)
|
||||||
|
var blend_tree_node:BLTAnimationNode = blend_tree.get_node(node_name)
|
||||||
|
if blend_tree_node == null:
|
||||||
|
push_error("Cannot delete node '%s': node not found." % node_name)
|
||||||
|
continue
|
||||||
|
|
||||||
|
var graph_node:GraphNode = blend_tree_node_to_graph_node[blend_tree_node]
|
||||||
|
blend_tree.remove_node(blend_tree_node)
|
||||||
|
blend_tree_node_to_graph_node.erase(blend_tree_node)
|
||||||
|
|
||||||
|
graph_node_to_blend_tree_node.erase(graph_node)
|
||||||
|
blend_tree_graph_edit.remove_child(graph_node)
|
||||||
|
graph_node.queue_free()
|
||||||
|
|
||||||
|
blend_tree_graph_edit.clear_connections()
|
||||||
|
|
||||||
|
if node_name in selected_nodes.keys():
|
||||||
|
selected_nodes.erase(node_name)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_blend_tree_graph_edit_disconnection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) -> void:
|
||||||
|
print("removing connection")
|
||||||
|
|
||||||
|
var blend_tree_source_node = blend_tree.get_node(from_node)
|
||||||
|
var blend_tree_target_node = blend_tree.get_node(to_node)
|
||||||
|
var target_port_name = blend_tree_target_node.get_input_names()[to_port]
|
||||||
|
blend_tree.remove_connection(blend_tree_source_node, blend_tree_target_node, target_port_name)
|
||||||
|
|
||||||
|
blend_tree_graph_edit.disconnect_node(from_node, from_port, to_node, to_port)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=2 format=3 uid="uid://31c6depvs0y1"]
|
[gd_scene format=3 uid="uid://31c6depvs0y1"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dvulvuytt81lw" path="res://addons/blendalot/blendalot_main_panel.gd" id="1_427jg"]
|
[ext_resource type="Script" uid="uid://dvulvuytt81lw" path="res://addons/blendalot/blendalot_main_panel.gd" id="1_427jg"]
|
||||||
|
|
||||||
@ -74,6 +74,13 @@ size_flags_vertical = 3
|
|||||||
[node name="AddNodePopupMenu" type="PopupMenu" parent="BlendTreeEditorContainer/Panel" unique_id=2020489213]
|
[node name="AddNodePopupMenu" type="PopupMenu" parent="BlendTreeEditorContainer/Panel" unique_id=2020489213]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
oversampling_override = 1.0
|
oversampling_override = 1.0
|
||||||
|
item_count = 3
|
||||||
|
item_0/text = "BLTAnimationNodeSampler"
|
||||||
|
item_0/id = 0
|
||||||
|
item_1/text = "BLTAnimationNodeBlend2"
|
||||||
|
item_1/id = 1
|
||||||
|
item_2/text = "BLTAnimationNodeBlendTree"
|
||||||
|
item_2/id = 2
|
||||||
|
|
||||||
[node name="BlendTreeGraphEdit" type="GraphEdit" parent="BlendTreeEditorContainer/Panel" unique_id=387715755]
|
[node name="BlendTreeGraphEdit" type="GraphEdit" parent="BlendTreeEditorContainer/Panel" unique_id=387715755]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
@ -83,6 +90,7 @@ anchor_right = 1.0
|
|||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
right_disconnects = true
|
||||||
|
|
||||||
[connection signal="pressed" from="BlendTreeEditorContainer/HBoxContainer/ResetGraphButton" to="." method="_on_reset_graph_button_pressed"]
|
[connection signal="pressed" from="BlendTreeEditorContainer/HBoxContainer/ResetGraphButton" to="." method="_on_reset_graph_button_pressed"]
|
||||||
[connection signal="pressed" from="BlendTreeEditorContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"]
|
[connection signal="pressed" from="BlendTreeEditorContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_pressed"]
|
||||||
@ -92,6 +100,8 @@ grow_vertical = 2
|
|||||||
[connection signal="index_pressed" from="BlendTreeEditorContainer/Panel/AddNodePopupMenu" to="." method="_on_add_node_popup_menu_index_pressed"]
|
[connection signal="index_pressed" from="BlendTreeEditorContainer/Panel/AddNodePopupMenu" to="." method="_on_add_node_popup_menu_index_pressed"]
|
||||||
[connection signal="begin_node_move" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_begin_node_move"]
|
[connection signal="begin_node_move" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_begin_node_move"]
|
||||||
[connection signal="connection_request" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_connection_request"]
|
[connection signal="connection_request" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_connection_request"]
|
||||||
|
[connection signal="delete_nodes_request" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_delete_nodes_request"]
|
||||||
|
[connection signal="disconnection_request" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_disconnection_request"]
|
||||||
[connection signal="end_node_move" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_end_node_move"]
|
[connection signal="end_node_move" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_end_node_move"]
|
||||||
[connection signal="node_deselected" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_node_deselected"]
|
[connection signal="node_deselected" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_node_deselected"]
|
||||||
[connection signal="node_selected" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_node_selected"]
|
[connection signal="node_selected" from="BlendTreeEditorContainer/Panel/BlendTreeGraphEdit" to="." method="_on_blend_tree_graph_edit_node_selected"]
|
||||||
|
|||||||
@ -3,7 +3,7 @@ extends EditorPlugin
|
|||||||
|
|
||||||
const MainPanel = preload("res://addons/blendalot/blendalot_main_panel.tscn")
|
const MainPanel = preload("res://addons/blendalot/blendalot_main_panel.tscn")
|
||||||
|
|
||||||
var main_panel_instance
|
var main_panel_instance:BlendalotMainPanel
|
||||||
|
|
||||||
func _enable_plugin() -> void:
|
func _enable_plugin() -> void:
|
||||||
# Add autoloads here.
|
# Add autoloads here.
|
||||||
@ -47,3 +47,10 @@ func _get_plugin_icon():
|
|||||||
|
|
||||||
func _handles(obj: Object) -> bool:
|
func _handles(obj: Object) -> bool:
|
||||||
return obj is BLTAnimationNodeBlendTree
|
return obj is BLTAnimationNodeBlendTree
|
||||||
|
|
||||||
|
func _edit(object: Object):
|
||||||
|
if object is BLTAnimationNodeBlendTree:
|
||||||
|
main_panel_instance.edit_blend_tree(object)
|
||||||
|
return
|
||||||
|
|
||||||
|
print("Cannot (yet) edit object " + str(object))
|
||||||
|
|||||||
13
demo/main.gd
13
demo/main.gd
@ -12,19 +12,6 @@ extends Node3D
|
|||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
blend_weight_slider.value = 0.5
|
blend_weight_slider.value = 0.5
|
||||||
|
|
||||||
var blend_tree: BLTAnimationNodeBlendTree = BLTAnimationNodeBlendTree.new()
|
|
||||||
var output_node: BLTAnimationNodeOutput = blend_tree.get_output_node()
|
|
||||||
var sampler_node_1: BLTAnimationNodeSampler = BLTAnimationNodeSampler.new()
|
|
||||||
|
|
||||||
sampler_node_1.animation = "animation_library/Walk-InPlace"
|
|
||||||
|
|
||||||
blend_tree.add_node(sampler_node_1)
|
|
||||||
var result = blend_tree.add_connection(sampler_node_1, output_node, "Input")
|
|
||||||
var anim_graph: BLTAnimationGraph = mixamo_amy_walk_run_synced.get_node("SyncedAnimationGraph")
|
|
||||||
|
|
||||||
anim_graph.tree_root = blend_tree
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
[gd_scene load_steps=14 format=3 uid="uid://svj53e2xoio"]
|
[gd_scene format=3 uid="uid://svj53e2xoio"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://d1xcqdqr1qeu6" path="res://assets/MixamoAmy.glb" id="1_0xm2m"]
|
[ext_resource type="PackedScene" uid="uid://d1xcqdqr1qeu6" path="res://assets/MixamoAmy.glb" id="1_0xm2m"]
|
||||||
[ext_resource type="Script" uid="uid://bjvgqujpqumj7" path="res://main.gd" id="1_1bvp3"]
|
[ext_resource type="Script" uid="uid://bjvgqujpqumj7" path="res://main.gd" id="1_1bvp3"]
|
||||||
[ext_resource type="AnimationLibrary" uid="uid://dwubn740aqx51" path="res://animation_library.res" id="3_1bvp3"]
|
[ext_resource type="AnimationLibrary" uid="uid://dwubn740aqx51" path="res://animation_library.res" id="3_1bvp3"]
|
||||||
[ext_resource type="AnimationNodeBlendTree" uid="uid://dqy0dgwsm8t46" path="res://animation_tree_walk_limp.tres" id="3_272bh"]
|
[ext_resource type="AnimationNodeBlendTree" uid="uid://dqy0dgwsm8t46" path="res://animation_tree_walk_limp.tres" id="3_272bh"]
|
||||||
[ext_resource type="BLTAnimationNodeBlendTree" uid="uid://2qfwr1xkiw0s" path="res://synced_blend_tree_walk_limp.tres" id="4_lquwl"]
|
[ext_resource type="BLTAnimationNodeBlendTree" uid="uid://2qfwr1xkiw0s" path="res://synced_blend_tree_walk_limp.tres" id="4_lquwl"]
|
||||||
[ext_resource type="BLTAnimationNodeBlendTree" uid="uid://qsk64ax2o47f" path="res://synced_blend_tree_walk_run.tres" id="5_7mycd"]
|
|
||||||
[ext_resource type="AnimationNodeBlendTree" uid="uid://vsf71o82lkld" path="res://animation_tree_walk_run.tres" id="6_5vw27"]
|
[ext_resource type="AnimationNodeBlendTree" uid="uid://vsf71o82lkld" path="res://animation_tree_walk_run.tres" id="6_5vw27"]
|
||||||
|
|
||||||
[sub_resource type="Theme" id="Theme_272bh"]
|
[sub_resource type="Theme" id="Theme_272bh"]
|
||||||
@ -32,6 +31,17 @@ sky = SubResource("Sky_1bvp3")
|
|||||||
tonemap_mode = 2
|
tonemap_mode = 2
|
||||||
glow_enabled = true
|
glow_enabled = true
|
||||||
|
|
||||||
|
[sub_resource type="BLTAnimationNodeSampler" id="BLTAnimationNodeSampler_7mycd"]
|
||||||
|
resource_name = "BLTAnimationNodeSampler"
|
||||||
|
position = Vector2(149.47485, 361.29053)
|
||||||
|
animation = &"animation_library/Walk-InPlace"
|
||||||
|
|
||||||
|
[sub_resource type="BLTAnimationNodeBlendTree" id="BLTAnimationNodeBlendTree_272bh"]
|
||||||
|
nodes/Output/position = Vector2(602.0149, 281.4305)
|
||||||
|
nodes/BLTAnimationNodeSampler/node = SubResource("BLTAnimationNodeSampler_7mycd")
|
||||||
|
nodes/BLTAnimationNodeSampler/position = Vector2(149.47485, 361.29053)
|
||||||
|
node_connections = ["Output", 0, "BLTAnimationNodeSampler"]
|
||||||
|
|
||||||
[node name="Main" type="Node3D" unique_id=933302313]
|
[node name="Main" type="Node3D" unique_id=933302313]
|
||||||
script = ExtResource("1_1bvp3")
|
script = ExtResource("1_1bvp3")
|
||||||
|
|
||||||
@ -156,13 +166,13 @@ unique_name_in_owner = true
|
|||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.4, 0, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.4, 0, 0)
|
||||||
|
|
||||||
[node name="AnimationPlayer2" type="AnimationPlayer" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1255239074]
|
[node name="AnimationPlayer2" type="AnimationPlayer" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1255239074]
|
||||||
|
active = false
|
||||||
libraries/animation_library = ExtResource("3_1bvp3")
|
libraries/animation_library = ExtResource("3_1bvp3")
|
||||||
|
|
||||||
[node name="SyncedAnimationGraph" type="BLTAnimationGraph" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1602406394]
|
[node name="SyncedAnimationGraph" type="BLTAnimationGraph" parent="Characters/MixamoAmyWalkRunSynced" unique_id=1602406394]
|
||||||
animation_player = NodePath("../AnimationPlayer2")
|
animation_player = NodePath("../AnimationPlayer2")
|
||||||
tree_root = ExtResource("5_7mycd")
|
tree_root = SubResource("BLTAnimationNodeBlendTree_272bh")
|
||||||
skeleton = NodePath("../Armature/Skeleton3D")
|
skeleton = NodePath("../Armature/Skeleton3D")
|
||||||
parameters/BLTAnimationNodeBlend2/blend_amount = 0.4
|
|
||||||
|
|
||||||
[connection signal="value_changed" from="UI/MarginContainer/HBoxContainer/BlendWeightSlider" to="." method="_on_blend_weight_slider_value_changed"]
|
[connection signal="value_changed" from="UI/MarginContainer/HBoxContainer/BlendWeightSlider" to="." method="_on_blend_weight_slider_value_changed"]
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ config_version=5
|
|||||||
|
|
||||||
config/name="Synced Blend Tree Test"
|
config/name="Synced Blend Tree Test"
|
||||||
run/main_scene="uid://svj53e2xoio"
|
run/main_scene="uid://svj53e2xoio"
|
||||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user