X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=blender%2Fio_mspgl%2Fanimation.py;h=59f34b4d7c532e35e0a852493b81120a1a9fff61;hp=ffce11f596fc8099b2e48e39d8401beca84f45d2;hb=569abc900f42d8e7b70520e2c9ef8a5547878266;hpb=6a832fe1771f8c7bca0faa0d383fbbab062a1c56 diff --git a/blender/io_mspgl/animation.py b/blender/io_mspgl/animation.py index ffce11f5..59f34b4d 100644 --- a/blender/io_mspgl/animation.py +++ b/blender/io_mspgl/animation.py @@ -1,3 +1,4 @@ +import math import mathutils class Curve: @@ -34,6 +35,7 @@ class Animation: self._action = action self.curves = [Curve(c) for c in action.fcurves] self.fps = 1 + self.looping = False for c in self.curves: for i in range(0, len(c.knots)-1, 3): @@ -77,6 +79,24 @@ class Animation: def __getattr__(self, attr): return getattr(self._curve, attr) + def check_looping(self, threshold): + self.looping = True + for c in self.curves: + first_y = c.knots[0][1] + last_y = c.knots[-1][1] + d = abs(last_y-first_y) + + if c.data_path=="rotation_euler": + while d>math.pi/2: + d -= math.pi + while d<-math.pi/2: + d += math.pi + + print("Difference for {} {} is {}".format(c.data_path, c.array_index, d)) + if d>threshold: + self.looping = False + break + def change_fps(self, fps): scale = self.fps/fps self.fps = fps @@ -89,8 +109,9 @@ class Animation: k.time *= scale -def create_animation_from_action(context, action): +def create_animation_from_action(context, action, *, looping_threshold=0.001): anim = Animation(action) render = context.scene.render + anim.check_looping(looping_threshold) anim.change_fps(render.fps/render.fps_base) return anim