Advertisement
Guest User

Godot 3D transform insert key

a guest
Apr 7th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. tool
  2. extends Spatial
  3.  
  4. export(bool) var capture_transform : = false
  5. export(NodePath) var animation_player
  6.  
  7.  
  8. func _ready():
  9.     set_process(true)
  10.     pass # Replace with function body.
  11.  
  12. func loop_through_children(node):
  13.     for child in node.get_children():
  14.         if child.get_child_count() > 0:
  15.             add_transform_tracks(child)
  16.             loop_through_children(child)
  17.         else:
  18.             add_transform_tracks(child)
  19.  
  20.  
  21. func add_transform_tracks(node):
  22.     if animation_player.is_empty():
  23.         return
  24.     var anim_player = get_node(animation_player)
  25.     if not(anim_player is AnimationPlayer):
  26.         return
  27.     var current_anim_position = anim_player.get_current_animation_position()
  28.     var path = self.get_path_to(node)
  29.     var current_anim = anim_player.get_animation(anim_player.get_assigned_animation())
  30.    
  31.     var track_idx : int
  32.    
  33.     track_idx = current_anim.find_track(NodePath(str(path) + ":translation"))
  34.     if track_idx == -1:
  35.         current_anim.add_track(Animation.TYPE_VALUE)
  36.         current_anim.track_set_path(current_anim.get_track_count() - 1, NodePath(str(path) + ":translation"))
  37.         track_idx = current_anim.get_track_count() - 1
  38.     current_anim.track_insert_key(track_idx, current_anim_position, get_node(path).get("translation"))
  39.    
  40.     track_idx = current_anim.find_track(NodePath(str(path) + ":rotation_degrees"))
  41.     if track_idx == -1:
  42.         current_anim.add_track(Animation.TYPE_VALUE)
  43.         current_anim.track_set_path(current_anim.get_track_count() - 1, NodePath(str(path) +":rotation_degrees"))
  44.         track_idx = current_anim.get_track_count() - 1
  45.     current_anim.track_insert_key(track_idx, current_anim_position, get_node(path).get("rotation_degrees"))
  46.    
  47.     track_idx = current_anim.find_track(NodePath(str(path) + ":scale"))
  48.     if track_idx == -1:
  49.         current_anim.add_track(Animation.TYPE_VALUE)
  50.         current_anim.track_set_path(current_anim.get_track_count() - 1, NodePath(str(path) + ":scale"))
  51.         track_idx = current_anim.get_track_count() - 1
  52.     current_anim.track_insert_key(track_idx, current_anim_position, get_node(path).get("scale"))
  53.     print("ins, idx : " + str(track_idx) + " node : " + str(get_node(path)))
  54.  
  55. func _process(delta):
  56.     if capture_transform:
  57.         add_transform_tracks(self)
  58.         loop_through_children(self)
  59.         capture_transform = false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement