Advertisement
Guest User

ivygen_build_animation

a guest
Jan 19th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. import bpy
  2. import re
  3.  
  4. modifier_type = "Build"
  5. base_name     = 'IVY_Curve'
  6.  
  7. frame_per_face        = 1 / 4   # how to allocate a total build animation length according to the number of faces on a branch
  8. build_interval        = 15      # how many frames to wait until starting to build 2nd branch
  9. wait_between_branches = 4       # how many frames to wait between branches
  10. build_start_frame     = 1       # Build animation start frame for the first ivy branch
  11.  
  12. ivy_objects = []
  13.  
  14. for current_obj in bpy.data.objects:  # browse all objects and filter out ivy branches
  15.     if re.search(base_name, current_obj.name):          # if the object name contains the base_name
  16.         current_obj.data.update(calc_tessface=True)     # calculate face data so that...
  17.         face_count = len(current_obj.data.tessfaces)    # we can obtain the total number of faces
  18.        
  19.         ivy_objects.append( { "name" : current_obj.name, "facecount" : face_count } ) # add ivy object to list, include name and face count
  20.  
  21. biggest_obj = ""
  22. most_faces  = 0
  23.  
  24. # Find the biggest object (highest face count)
  25. for obj in ivy_objects:
  26.     if obj["facecount"] > most_faces:   # if this object's facecount is larger than the previous highscore,
  27.         most_faces  = obj["facecount"]  # then make this facecount one the new max
  28.         biggest_obj = obj["name"]       # and update the biggest object's name
  29.  
  30. # set base build animation length according to the biggest object's size
  31. base_build_length = int( most_faces * frame_per_face )
  32.  
  33. count = 0
  34.  
  35. # set animation length and start frames to all objects in list
  36. for obj in ivy_objects:
  37.     name = obj["name"]
  38.     current_object = bpy.data.objects[name]
  39.  
  40.     # set the start frame of each object's build anim. by the order of names (which corresponds to order of creation)
  41.     if count != 0: # Set build start for all the branches after the first one:
  42.         bpy.data.objects[name].modifiers[modifier_type].frame_start = int( build_start_frame + build_interval + count * wait_between_branches )
  43.     else:   # Set when the first branch starts to build
  44.         bpy.data.objects[name].modifiers[modifier_type].frame_start = int( build_start_frame )
  45.    
  46.     # Set build length in proportion to face count
  47.     ratio = obj["facecount"] / most_faces
  48.     bpy.data.objects[name].modifiers[modifier_type].frame_duration = int( ratio * base_build_length )
  49.  
  50.     count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement