export_all = bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
collection = bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
+ looping_threshold = bpy.props.FloatProperty(name="Looping threshold", description="Tolerance for curve beginning and end values for looping", min=0.0, soft_max=1.0, precision=4, default=0.001)
def check(self, context):
result = False
col.prop(self, "export_all")
if self.export_all:
col.prop(self, "collection")
+ col.prop(self, "looping_threshold")
class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
bl_idname = "export_scene.mspgl_scene"
+import math
import mathutils
class Curve:
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):
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
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
def __init__(self):
self.export_all = False
self.collection = True
+ self.looping_threshold = 0.001
def export_to_file(self, context, out_fn):
if self.export_all:
def export_animation(self, context, action):
from .animation import create_animation_from_action
- anim = create_animation_from_action(context, action)
+ anim = create_animation_from_action(context, action, looping_threshold=self.looping_threshold)
from .datafile import Resource, Statement
resource = Resource(action.name+".anim")
resource.statements.append(st)
+ resource.statements.append(Statement("looping", anim.looping))
+
return resource