Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tool
- extends Spatial
- export(bool) var capture_transform : = false
- export(NodePath) var animation_player
- func _ready():
- set_process(true)
- pass # Replace with function body.
- func loop_through_children(node):
- for child in node.get_children():
- if child.get_child_count() > 0:
- add_transform_tracks(child)
- loop_through_children(child)
- else:
- add_transform_tracks(child)
- func add_transform_tracks(node):
- if animation_player.is_empty():
- return
- var anim_player = get_node(animation_player)
- if not(anim_player is AnimationPlayer):
- return
- var current_anim_position = anim_player.get_current_animation_position()
- var path = self.get_path_to(node)
- var current_anim = anim_player.get_animation(anim_player.get_assigned_animation())
- var track_idx : int
- track_idx = current_anim.find_track(NodePath(str(path) + ":translation"))
- if track_idx == -1:
- current_anim.add_track(Animation.TYPE_VALUE)
- current_anim.track_set_path(current_anim.get_track_count() - 1, NodePath(str(path) + ":translation"))
- track_idx = current_anim.get_track_count() - 1
- current_anim.track_insert_key(track_idx, current_anim_position, get_node(path).get("translation"))
- track_idx = current_anim.find_track(NodePath(str(path) + ":rotation_degrees"))
- if track_idx == -1:
- current_anim.add_track(Animation.TYPE_VALUE)
- current_anim.track_set_path(current_anim.get_track_count() - 1, NodePath(str(path) +":rotation_degrees"))
- track_idx = current_anim.get_track_count() - 1
- current_anim.track_insert_key(track_idx, current_anim_position, get_node(path).get("rotation_degrees"))
- track_idx = current_anim.find_track(NodePath(str(path) + ":scale"))
- if track_idx == -1:
- current_anim.add_track(Animation.TYPE_VALUE)
- current_anim.track_set_path(current_anim.get_track_count() - 1, NodePath(str(path) + ":scale"))
- track_idx = current_anim.get_track_count() - 1
- current_anim.track_insert_key(track_idx, current_anim_position, get_node(path).get("scale"))
- print("ins, idx : " + str(track_idx) + " node : " + str(get_node(path)))
- func _process(delta):
- if capture_transform:
- add_transform_tracks(self)
- loop_through_children(self)
- capture_transform = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement