From 242321fd7aa60e083caec15c7b4a58663b9a56d7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 12 Sep 2021 15:52:22 +0200 Subject: [PATCH] Bone hierarchy editing support. --- game/addons/bone_editor/BoneEditor.gd | 13 ++++++++++++ game/addons/bone_editor/BoneHandle.gd | 29 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/game/addons/bone_editor/BoneEditor.gd b/game/addons/bone_editor/BoneEditor.gd index 7afd91e4..4670314b 100644 --- a/game/addons/bone_editor/BoneEditor.gd +++ b/game/addons/bone_editor/BoneEditor.gd @@ -5,6 +5,8 @@ export(NodePath) var control_skeleton:NodePath setget set_control_skeleton export(NodePath) var edit_animation_player:NodePath setget set_edit_animation_player export(bool) var enabled:bool = true +export(bool) var edit_bone_hierarchy : bool = false + export(String) var add_bone_name : String = "" export(bool) var add_bone : bool = false setget set_add_bone, get_add_bone @@ -171,6 +173,14 @@ func _save_poses_to_animation( animation:Animation ): ) print( "* added new key for ", target_bone.name ) +func set_bone_parent(bone_id, parent_bone_id): + ensure_nodes() + + if !skeleton: + return + + skeleton.set_bone_parent(bone_id, parent_bone_id) + func ensure_nodes(): if !skeleton: skeleton = get_node(control_skeleton) @@ -220,3 +230,6 @@ func set_add_bone(val): func get_add_bone(): return false + +func is_done_editor(): + return true diff --git a/game/addons/bone_editor/BoneHandle.gd b/game/addons/bone_editor/BoneHandle.gd index 7497ac70..1eedcfe9 100644 --- a/game/addons/bone_editor/BoneHandle.gd +++ b/game/addons/bone_editor/BoneHandle.gd @@ -46,3 +46,32 @@ func _process( delta:float ): t.origin = self.original_parent_rest.basis.xform_inv( self.transform.origin - self.original_global_rest_origin ) self.skeleton.set_bone_pose( self.bone_id, t ) self.pose = t + +func ensure_bone_editor(): + if !bone_editor: + var n : Node = get_parent() + + while n: + if n.has_method("is_done_editor"): + bone_editor = n + return + + n = n.get_parent() + +func _notification(what): + if what == NOTIFICATION_PARENTED: + ensure_bone_editor() + + if !bone_editor: + return + + if !bone_editor.edit_bone_hierarchy: + return + + var n : Node = get_parent() + + if n == bone_editor: + bone_editor.set_bone_parent(bone_id, -1) + else: + bone_editor.set_bone_parent(bone_id, n.bone_id) +