keyframes.py (2034B)
1 ### EXESOFT PYIGNITION ### 2 # Copyright David Barker 2010 3 # 4 # Keyframe object and generic keyframe creation function 5 6 7 from constants import * 8 9 10 def CreateKeyframe(parentframes, frame, variables): 11 newframe = Keyframe(frame, variables) 12 13 # Look for duplicate keyframes and copy other defined variables 14 try: 15 oldkey = (keyframe for keyframe in parentframes if keyframe.frame == frame).__next__() 16 except StopIteration: 17 oldkey = None 18 19 if oldkey != None: 20 for var in oldkey.variables.keys(): # For every variable defined by the old keyframe 21 if (var not in newframe.variables or newframe.variables[var] == None) and (oldkey.variables[var] != None): # If a variable is undefined, copy its value to the new keyframe 22 newframe.variables[var] = oldkey.variables[var] 23 24 # Remove the duplicate keyframe, if it existed 25 for duplicate in (keyframe for keyframe in parentframes if keyframe.frame == frame): 26 parentframes.remove(duplicate) 27 break 28 29 # Append the new keyframe then sort them all by frame 30 parentframes.append(newframe) 31 sortedframes = sorted(parentframes, key=lambda keyframe: keyframe.frame) 32 parentframes[:] = sortedframes 33 34 return newframe # Return a reference to the new keyframe, in case it's needed 35 36 def ConsolidateKeyframes(parentframes, frame, variables): 37 newframe = Keyframe(frame, variables) 38 parentframes.append(newframe) 39 40 finallist = [] # A truncated list of keyframes 41 42 # Append all the frames which come after the current one to the final list 43 for keyframe in parentframes: 44 if keyframe.frame >= frame: 45 finallist.append(keyframe) 46 47 # Sort the keyframes and give them to the parent object 48 sortedframes = sorted(finallist, key=lambda keyframe: keyframe.frame) 49 parentframes[:] = sortedframes 50 51 class Keyframe: 52 def __init__(self, frame = 0, variables = {}): 53 self.frame = frame 54 self.variables = variables 55 56 if not ('interpolationtype' in self.variables): 57 self.variables['interpolationtype'] = INTERPOLATIONTYPE_LINEAR 58