5 def __init__(self, curve):
9 for i in range(len(self.keyframe_points)-1):
10 kf1 = self.keyframe_points[i]
11 kf2 = self.keyframe_points[i+1]
12 dx = (kf2.co[0]-kf1.co[0])/3
13 slope1 = (kf1.handle_right[1]-kf1.co[1])/(kf1.handle_right[0]-kf1.co[0])
14 slope2 = (kf2.co[1]-kf2.handle_left[1])/(kf2.co[0]-kf2.handle_left[0])
17 self.knots.append(mathutils.Vector(kf1.co))
18 self.knots.append(kf1.co+mathutils.Vector((dx, slope1*dx)))
19 self.knots.append(kf2.co-mathutils.Vector((dx, slope2*dx)))
20 self.knots.append(mathutils.Vector(kf2.co))
22 def __getattr__(self, attr):
23 return getattr(self._curve, attr)
27 def __init__(self, time):
34 def __init__(self, action):
36 self.curves = [Curve(c) for c in action.fcurves]
41 for i in range(0, len(c.knots)-1, 3):
47 t = (p0[0]*(50-j)+p3[0]*j)/50
48 x = (t-p0[0])/(p3[0]-p0[0])
49 v1 = c._curve.evaluate(t)
50 v2 = p0[1]*(1-x)**3+3*p1[1]*x*(1-x)**2+3*p2[1]*x**2*(1-x)+p3[1]*x**3
52 keyframes_by_time = {}
56 for i, k in enumerate(c.knots):
59 kf_map = controls_by_time if control else keyframes_by_time
65 self.keyframes.append(kf)
67 kf.curves.append((c, i))
69 self.keyframes.sort(key=lambda k: k.time)
70 self.start_time = self.keyframes[0].time
74 k[0] -= self.start_time
76 for k in self.keyframes:
77 k.time -= self.start_time
79 def __getattr__(self, attr):
80 return getattr(self._curve, attr)
82 def check_looping(self, threshold):
85 first_y = c.knots[0][1]
86 last_y = c.knots[-1][1]
87 d = abs(last_y-first_y)
89 if c.data_path=="rotation_euler":
99 def change_fps(self, fps):
103 for c in self.curves:
107 for k in self.keyframes:
111 def create_animation_from_action(context, action, *, looping_threshold=0.001):
112 anim = Animation(action)
113 render = context.scene.render
114 anim.check_looping(looping_threshold)
115 anim.change_fps(render.fps/render.fps_base)