diff --git a/synfig-studio/plugins/lottie-exporter/canvas.py b/synfig-studio/plugins/lottie-exporter/canvas.py index 2869ba6..11df306 100644 --- a/synfig-studio/plugins/lottie-exporter/canvas.py +++ b/synfig-studio/plugins/lottie-exporter/canvas.py @@ -5,28 +5,30 @@ import settings from misc import calculate_pixels_per_unit def calc_time(root, lottie, which): + """ + Converts the starting time and ending time to lottie format + """ if which == "ip": - st = "begin-time" + phase = "begin-time" elif which == "op": - st = "end-time" - time = root.attrib[st].split(" ") + phase = "end-time" + time = root.attrib[phase].split(" ") lottie[which] = 0 - for fr in time: + for frame in time: # Adding time in seconds - if fr[-1] == "s": - lottie[which] += float(fr[:-1]) * lottie["fr"] + if frame[-1] == "s": + lottie[which] += float(frame[:-1]) * lottie["fr"] # Adding time in frames - elif fr[-1] == "f": - lottie[which] += float(fr[:-1]) + elif frame[-1] == "f": + lottie[which] += float(frame[:-1]) def gen_canvas(lottie, root): - """ + """ Generates the canvas for the lottie format It is the outer most dictionary in the lottie json format """ - settings.view_box_canvas["val"] = [float(itr) - for itr in root.attrib["view-box"].split()] + settings.view_box_canvas["val"] = [float(itr) for itr in root.attrib["view-box"].split()] if "width" in root.attrib.keys(): lottie["w"] = int(root.attrib["width"]) else: diff --git a/synfig-studio/plugins/lottie-exporter/helpers/transform.py b/synfig-studio/plugins/lottie-exporter/helpers/transform.py index 81da12e..4bf30ef 100644 --- a/synfig-studio/plugins/lottie-exporter/helpers/transform.py +++ b/synfig-studio/plugins/lottie-exporter/helpers/transform.py @@ -1,11 +1,12 @@ """ -Fill this +This module will store all the functions required for transformations +corresponding to lottie """ import sys -sys.path.append("../") import settings -from misc import Count, change_axis +from misc import Count from properties.value import gen_properties_value +sys.path.append("../") def gen_helpers_transform(lottie, layer): """ @@ -19,22 +20,34 @@ def gen_helpers_transform(lottie, layer): lottie["s"] = {} # Scale of the layer # setting the default location - gen_properties_value(lottie["p"], [0, 0], index.inc(), settings.DEFAULT_ANIMATED, settings.NO_INFO) + gen_properties_value(lottie["p"], + [0, 0], + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) # setting the default opacity i.e. 100 - gen_properties_value(lottie["o"], settings.DEFAULT_OPACITY, index.inc(), - settings.DEFAULT_ANIMATED, settings.NO_INFO) + gen_properties_value(lottie["o"], + settings.DEFAULT_OPACITY, + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) + + # setting the rotation + gen_properties_value(lottie["r"], + settings.DEFAULT_ROTATION, + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) - gen_properties_value( - lottie["r"], - settings.DEFAULT_ROTATION, - index.inc(), - settings.DEFAULT_ANIMATED, - settings.NO_INFO) - gen_properties_value( - lottie["a"], [ - 0, 0, 0], index.inc(), settings.DEFAULT_ANIMATED, settings.NO_INFO) - gen_properties_value( - lottie["s"], [ - 100, 100, 100], index.inc(), settings.DEFAULT_ANIMATED, settings.NO_INFO) + gen_properties_value(lottie["a"], + [0, 0, 0], + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) + gen_properties_value(lottie["s"], + [100, 100, 100], + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) diff --git a/synfig-studio/plugins/lottie-exporter/layers/shape.py b/synfig-studio/plugins/lottie-exporter/layers/shape.py index 9e597a1..7268611 100644 --- a/synfig-studio/plugins/lottie-exporter/layers/shape.py +++ b/synfig-studio/plugins/lottie-exporter/layers/shape.py @@ -1,13 +1,13 @@ """ -Fill this +Will store all the functions corresponding to shapes in lottie """ import sys -sys.path.append("..") import settings from helpers.transform import gen_helpers_transform from misc import Count from shapes.star import gen_shapes_star from shapes.fill import gen_shapes_fill +sys.path.append("..") def gen_layer_shape(lottie, layer, idx): """ diff --git a/synfig-studio/plugins/lottie-exporter/misc.py b/synfig-studio/plugins/lottie-exporter/misc.py index 5c690bd..9c56769 100644 --- a/synfig-studio/plugins/lottie-exporter/misc.py +++ b/synfig-studio/plugins/lottie-exporter/misc.py @@ -20,93 +20,113 @@ class Count: class Vector: """ To store the position of layers + val1 represents the x-axis value + val2 represents the y-axis value + + For other parameters + val1 represents the value of the parameter + val2 represents the time parameter """ - def __init__(self, x = 0, y = 0): - self.x = x - self.y = y + def __init__(self, val1=0, val2=0): + self.val1 = val1 + self.val2 = val2 def __str__(self): - return "({0},{1})".format(self.x,self.y) + return "({0},{1})".format(self.val1, self.val2) def __add__(self, other): - x = self.x + other.x - y = self.y + other.y - return Vector(x, y) + val1 = self.val1 + other.val1 + val2 = self.val2 + other.val2 + return Vector(val1, val2) def __sub__(self, other): - x = self.x - other.x - y = self.y - other.y - return Vector(x, y) + val1 = self.val1 - other.val1 + val2 = self.val2 - other.val2 + return Vector(val1, val2) # other can only be of type real def __mul__(self, other): if not isinstance(other, self.__class__): - x = self.x * other - y = self.y * other - return Vector(x, y) + val1 = self.val1 * other + val2 = self.val2 * other + return Vector(val1, val2) + raise Exception('Multiplication with {} not defined'.format(type(other))) def __rmul__(self, other): return self.__mul__(other) def __truediv__(self, other): if not isinstance(other, self.__class__): - x = self.x / other - y = self.y / other - return Vector(x, y) + val1 = self.val1 / other + val2 = self.val2 / other + return Vector(val1, val2) + raise Exception('Division with {} not defined'.format(type(other))) def get_list(self): - return [self.x, self.y] + """ + Get val1 and val2 values in the format required by lottie + """ + return [self.val1, self.val2] def get_val(self): - return [self.x] + """ + Get only val1 value in the format required by lottie + """ + return [self.val1] class Color: """ To store the colors in Synfig and operations on them """ - def __init__(self, r = 1, g = 1, b = 1, a = 1): - self.r = r - self.g = g - self.b = b - self.a = a + def __init__(self, red=1, green=1, blue=1, alpha=1): + self.red = red + self.green = green + self.blue = blue + self.alpha = alpha def __str__(self): - return "({0}, {1}, {2}, {3})".format(self.r, self.g, self.b, self.a) + return "({0}, {1}, {2}, {3})".format(self.red, self.green, self.blue, + self.alpha) def __add__(self, other): - r = self.r + other.r - g = self.g + other.g - b = self.b + other.b - return Color(r, g, b, self.a) + red = self.red + other.red + green = self.green + other.green + blue = self.blue + other.blue + return Color(red, green, blue, self.alpha) def __sub__(self, other): - r = self.r - other.r - g = self.g - other.g - b = self.b - other.b - return Color(r, g, b, self.a) + red = self.red - other.red + green = self.green - other.green + blue = self.blue - other.blue + return Color(red, green, blue, self.alpha) def __mul__(self, other): if not isinstance(other, self.__class__): - r = self.r * other - g = self.g * other - b = self.b * other - return Color(r, g, b, self.a) + red = self.red * other + green = self.green * other + blue = self.blue * other + return Color(red, green, blue, self.alpha) + raise Exception('Multiplication with {} not defined'.format(type(other))) def __rmul__(self, other): return self.__mul__(other) def __truediv__(self, other): if not isinstance(other, self.__class__): - r = self.r / other - g = self.g / other - b = self.b / other - return Color(r, g, b, self.a) + red = self.red / other + green = self.green / other + blue = self.blue / other + return Color(red, green, blue, self.alpha) + raise Exception('Division with {} not defined'.format(type(other))) def get_val(self): - return [self.r, self.g, self.b, self.a] + """ + Get the color in the format required by lottie + """ + return [self.red, self.green, self.blue, self.alpha] def calculate_pixels_per_unit(): - """ + """ Gives the value of 1 unit in terms of pixels according to the canvas defined """ image_width = float(settings.lottie_format["w"]) @@ -139,19 +159,24 @@ def parse_position(animated, i): elif animated.attrib["type"] == "angle": pos = [get_angle(float(animated[i][0].attrib["value"])), - float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] + float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] elif animated.attrib["type"] == "opacity": pos = [float(animated[i][0].attrib["value"]) * settings.OPACITY_CONSTANT, - float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] + float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] elif animated.attrib["type"] == "points": pos = [int(animated[i][0].attrib["value"]), - float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] + float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] elif animated.attrib["type"] == "color": - red, green, blue, alpha = float(animated[i][0][0].text), float(animated[i][0][1].text), float(animated[i][0][2].text), float(animated[i][0][3].text) - red, green, blue = red ** (1/settings.GAMMA), green ** (1/settings.GAMMA), blue ** (1/settings.GAMMA) + red = float(animated[i][0][0].text) + green = float(animated[i][0][1].text) + blue = float(animated[i][0][2].text) + alpha = float(animated[i][0][3].text) + red = red ** (1/settings.GAMMA) + green = green ** (1/settings.GAMMA) + blue = blue ** (1/settings.GAMMA) return Color(red, green, blue, alpha) return Vector(pos[0], pos[1]) @@ -163,8 +188,8 @@ def parse_value(animated, i): return: Vector(value, time) """ pos = [float(animated[i][0].attrib["value"]) * settings.PIX_PER_UNIT, - float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] - return pos + float(animated[i].attrib["time"][:-1]) * settings.lottie_format["fr"]] + return pos def get_angle(theta): """ @@ -182,13 +207,18 @@ def get_angle(theta): return theta def is_animated(node): + """ + Tells whether a parater is animated or not + Return: 0, if not animated + : 1, if only single waypoint is present + : 2, if more than one waypoint is present + """ + case = 0 if node.tag == "animated": if len(node) == 1: - # This means not animated - return 1 + case = 1 else: - # This means animated - return 2 + case = 2 else: - # Not animated - return 0 + case = 0 + return case diff --git a/synfig-studio/plugins/lottie-exporter/properties/multiDimensionalKeyframed.py b/synfig-studio/plugins/lottie-exporter/properties/multiDimensionalKeyframed.py index dfd7ec9..6f5f416 100644 --- a/synfig-studio/plugins/lottie-exporter/properties/multiDimensionalKeyframed.py +++ b/synfig-studio/plugins/lottie-exporter/properties/multiDimensionalKeyframed.py @@ -1,11 +1,12 @@ """ -Fill this +Will store all the functions required for generation of +multiDimensionalKeyframed file in lottie """ import sys -sys.path.append("..") import settings from properties.offsetKeyframe import gen_properties_offset_keyframe from properties.timeAdjust import time_adjust +sys.path.append("..") def gen_properties_multi_dimensional_keyframed(lottie, animated, idx): """ diff --git a/synfig-studio/plugins/lottie-exporter/properties/offsetKeyframe.py b/synfig-studio/plugins/lottie-exporter/properties/offsetKeyframe.py index b02235e..4723706 100644 --- a/synfig-studio/plugins/lottie-exporter/properties/offsetKeyframe.py +++ b/synfig-studio/plugins/lottie-exporter/properties/offsetKeyframe.py @@ -1,19 +1,24 @@ """ -Fill this +Will store all the function necessary for generation of offset properties of a +keyframe in lottie """ import sys import copy -sys.path.append("..") import settings from misc import parse_position, change_axis, Vector +sys.path.append("..") -""" -A Function for testing approximate equality -""" -def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): - return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol) +def isclose(a_val, b_val, rel_tol=1e-09, abs_tol=0.0): + """ + A Function for testing approximate equality + """ + return abs(a_val - b_val) <= max(rel_tol * max(abs(a_val), abs(b_val)), abs_tol) def clamped_tangent(p1, p2, p3, animated, i): + """ + Function corresponding to clamped function in Synfig + It generates the tangent when clamped waypoints are used + """ # pw -> prev_waypoint, w -> waypoint, nw -> next_waypoint pw, w, nw = animated[i-1], animated[i], animated[i+1] t1 = float(pw.attrib["time"][:-1]) * settings.lottie_format["fr"] @@ -49,30 +54,45 @@ def clamped_tangent(p1, p2, p3, animated, i): return tangent def clamped_vector(p1, p2, p3, animated, i, lottie, ease): - x_tan = clamped_tangent(p1.x, p2.x, p3.x, animated, i) - y_tan = clamped_tangent(p1.y, p2.y, p3.y, animated, i) + """ + Function to generate the collective tangents i.e. x tangent and y tangent + when clamped waypoints are used + """ + x_tan = clamped_tangent(p1.val1, p2.val1, p3.val1, animated, i) + y_tan = clamped_tangent(p1.val2, p2.val2, p3.val2, animated, i) if isclose(x_tan, 0.0) or isclose(y_tan, 0.0): if ease == "in": ease_in(lottie) else: ease_out(lottie) - return Vector(clamped_tangent(p1.x, p2.x, p3.x, animated, i), clamped_tangent(p1.y, p2.y, p3.y, animated, i)) + return Vector(x_tan, y_tan) def ease_out(lottie): - lottie["o"]["x"] = settings.OUT_TANGENT_X + """ + To set the ease out values in lottie format + """ + lottie["o"]["x"] = settings.OUT_TANGENT_X lottie["o"]["y"] = settings.OUT_TANGENT_Y def ease_in(lottie): + """ + To set the ease in values in lottie format + """ lottie["i"]["x"] = settings.IN_TANGENT_X lottie["i"]["y"] = settings.IN_TANGENT_Y def handle_color(): + """ + Default linear tangent values for color interpolations + """ out_val = Vector(0.5, 0.5) in_val = Vector(0.5, 0.5) return out_val, in_val def calc_tangent(animated, lottie, i): - + """ + Calculates the tangent, given two waypoints and there interpolation methods + """ waypoint, next_waypoint = animated[i], animated[i+1] cur_get_after, next_get_before = waypoint.attrib["after"], next_waypoint.attrib["before"] cur_get_before, next_get_after = waypoint.attrib["before"], next_waypoint.attrib["after"] @@ -175,7 +195,13 @@ def calc_tangent(animated, lottie, i): if next_get_before == "clamped": if i + 2 <= len(animated) - 1: ease = "in" - in_val = clamped_vector(cur_pos, next_pos, after_next_pos, animated, i + 1, lottie, ease) + in_val = clamped_vector(cur_pos, + next_pos, + after_next_pos, + animated, + i + 1, + lottie, + ease) else: in_val = next_pos - cur_pos # t2 = p2 - p1 @@ -187,14 +213,16 @@ def calc_tangent(animated, lottie, i): if animated.attrib["type"] == "vector": del lottie["to"], lottie["ti"] del lottie["i"], lottie["o"] - # "e" is not needed, but is still not deleted as it is of use in the last iteration of animation + # "e" is not needed, but is still not deleted as + # it is of use in the last iteration of animation + # See properties/multiDimenstionalKeyframed.py for more details # del lottie["e"] # If the number of points is decresing, then hold interpolation should # have reverse effect. The value should instantly decrease and remain # same for the rest of the interval if animated.attrib["type"] == "points": - if i > 0 and prev_pos.x > cur_pos.x: + if i > 0 and prev_pos.val1 > cur_pos.val1: t_now = float(animated[i-1].attrib["time"][:-1]) * settings.lottie_format["fr"] + 1 lottie["t"] = t_now return @@ -255,17 +283,17 @@ def gen_properties_offset_keyframe(curve_list, animated, i): if next_get_before == "halt": # For ease in ease_in(lottie) lottie["t"] = float(waypoint.attrib["time"][:-1]) * settings.lottie_format["fr"] - lottie["s"] = change_axis(cur_pos.x, cur_pos.y) - lottie["e"] = change_axis(next_pos.x, next_pos.y) + lottie["s"] = change_axis(cur_pos.val1, cur_pos.val2) + lottie["e"] = change_axis(next_pos.val1, next_pos.val2) lottie["to"] = [] lottie["ti"] = [] # Calculating the unchanged tangent try: out_val, in_val = calc_tangent(animated, lottie, i) - except: + except Exception as excep: # This means constant interval - return + return excep lottie["to"] = out_val.get_list() lottie["ti"] = in_val.get_list() diff --git a/synfig-studio/plugins/lottie-exporter/properties/timeAdjust.py b/synfig-studio/plugins/lottie-exporter/properties/timeAdjust.py index a40e457..5594b2e 100644 --- a/synfig-studio/plugins/lottie-exporter/properties/timeAdjust.py +++ b/synfig-studio/plugins/lottie-exporter/properties/timeAdjust.py @@ -1,8 +1,15 @@ -import sys -import settings +""" +Stores the functions required for adjusting time factor in the neighbouring +waypoints in Synfig +""" +import sys sys.path.append("../") def time_adjust(lottie, animated): + """ + Adjusts the tangents between neighbouring waypoints depending upon the time + factor between previous waypoints or next waypoints + """ timeadjust = 0.5 for i in range(len(animated) - 1): if i == 0: diff --git a/synfig-studio/plugins/lottie-exporter/properties/value.py b/synfig-studio/plugins/lottie-exporter/properties/value.py index 59258ff..4d56f45 100644 --- a/synfig-studio/plugins/lottie-exporter/properties/value.py +++ b/synfig-studio/plugins/lottie-exporter/properties/value.py @@ -1,5 +1,6 @@ """ -Fill this +Implements all the functions required for generating value for properties +related to layers in Synfig """ import sys import settings @@ -8,7 +9,7 @@ sys.path.append("../") def gen_properties_value(lottie, val, index, animated, expression): """ Generates the dictionary corresponding to properties/value.json in lottie - documentation and properties/multidimensional.json + documentation """ lottie["k"] = val lottie["ix"] = index diff --git a/synfig-studio/plugins/lottie-exporter/properties/valueKeyframe.py b/synfig-studio/plugins/lottie-exporter/properties/valueKeyframe.py index 52249ee..dd7be3e 100644 --- a/synfig-studio/plugins/lottie-exporter/properties/valueKeyframe.py +++ b/synfig-studio/plugins/lottie-exporter/properties/valueKeyframe.py @@ -1,16 +1,22 @@ """ -Fill this +Implements function required for generating tangent between two value key frames """ import sys -import settings import random -sys.path.append("../") +import settings from misc import parse_position -from properties.offsetKeyframe import ease_in, ease_out, calc_tangent, isclose +from properties.offsetKeyframe import calc_tangent +sys.path.append("../") def normalize_tangents(cur_pos, next_pos, t_in, t_out): - time_scale = next_pos.y - cur_pos.y # time_scale means converting time(on x-axis) to 0-1 range - value_scale = next_pos.x - cur_pos.x # value_scale -> converting value(on y-axis to 0-1 range) + """ + Converts the tangents from arbitrary range to the range of 0-1 + """ + # time_scale means converting time(on x-axis) to 0-1 range + time_scale = next_pos.val2 - cur_pos.val2 + + # value_scale -> converting value(on y-axis to 0-1 range) + value_scale = next_pos.val1 - cur_pos.val1 # If ever the value scale equals to absolute zero, randomly add or subtract # 1e-9 to it, in order to avoid division by zero @@ -20,14 +26,15 @@ def normalize_tangents(cur_pos, next_pos, t_in, t_out): bias *= 1e-9 value_scale += bias - time_diff = cur_pos.y / time_scale - value_diff = cur_pos.x / value_scale + time_diff = cur_pos.val2 / time_scale + value_diff = cur_pos.val1 / value_scale - t_out["x"][0] += cur_pos.y # The tangents were relative to cur_pos, now relative to 0 - t_out["y"][0] += cur_pos.x + t_out["x"][0] += cur_pos.val2 # The tangents were relative to cur_pos, now relative to 0 + t_out["y"][0] += cur_pos.val1 - t_in["x"][0] = next_pos.y - t_in["x"][0] # -ve sign because lottie and synfig use opposite in tangents - t_in["y"][0] = next_pos.x - t_in["y"][0] + # -ve sign because lottie and synfig use opposite "in" tangents + t_in["x"][0] = next_pos.val2 - t_in["x"][0] + t_in["y"][0] = next_pos.val1 - t_in["y"][0] # abs is put in order to deal with decreasing value t_out["x"][0] = abs(t_out["x"][0] / time_scale - time_diff) @@ -82,19 +89,19 @@ def gen_value_Keyframe(curve_list, animated, i): lottie["s"] = cur_pos.get_val() lottie["e"] = next_pos.get_val() - lottie["i"] = {} - lottie["o"] = {} + lottie["i"] = {} + lottie["o"] = {} try: out_val, in_val = calc_tangent(animated, lottie, i) - except: + except Exception as excep: # That means halt/constant interval - return + return excep set_tangents(out_val, in_val, cur_pos, next_pos, lottie, animated) if cur_get_after == "halt": # For ease out - lottie["o"]["x"][0] = settings.OUT_TANGENT_X + lottie["o"]["x"][0] = settings.OUT_TANGENT_X lottie["o"]["y"][0] = settings.OUT_TANGENT_Y if next_get_before == "halt": # For ease in lottie["i"]["x"][0] = settings.IN_TANGENT_X @@ -105,15 +112,17 @@ def gen_value_Keyframe(curve_list, animated, i): # need value for previous tangents # It may be helpful to store them somewhere - ov, iv = calc_tangent(animated, curve_list[-2], i - 1) - iv = out_val - set_tangents(ov, iv, parse_position(animated, i-1), cur_pos, curve_list[-2]) + prev_ov, prev_iv = calc_tangent(animated, curve_list[-2], i - 1) + prev_iv = out_val + set_tangents(prev_ov, prev_iv, parse_position(animated, i-1), cur_pos, curve_list[-2]) if cur_get_after == "halt": curve_list[-2]["i"]["x"][0] = settings.IN_TANGENT_X curve_list[-2]["i"]["y"][0] = settings.IN_TANGENT_Y def set_tangents(out_val, in_val, cur_pos, next_pos, lottie, animated): - + """ + To set the tangents as required by the lottie format for value waypoints + """ out_lst = out_val.get_list() in_lst = in_val.get_list() diff --git a/synfig-studio/plugins/lottie-exporter/properties/valueKeyframed.py b/synfig-studio/plugins/lottie-exporter/properties/valueKeyframed.py index 725dac5..ae1f97b 100644 --- a/synfig-studio/plugins/lottie-exporter/properties/valueKeyframed.py +++ b/synfig-studio/plugins/lottie-exporter/properties/valueKeyframed.py @@ -1,11 +1,11 @@ """ -Fill this +Stores all the functions required for generating value key frames in lottie """ import sys import settings -sys.path.append("../") from properties.timeAdjust import time_adjust from properties.valueKeyframe import gen_value_Keyframe +sys.path.append("../") def gen_value_Keyframed(lottie, animated, idx): """ @@ -30,6 +30,7 @@ def gen_value_Keyframed(lottie, animated, idx): if animated.attrib["type"] == "points": if lottie["k"][-2]["s"][0] > lottie["k"][-1]["s"][0]: # Adding 1 frame to the previous time - lottie["k"][-1]["t"] = float(animated[-2].attrib["time"][:-1]) * settings.lottie_format["fr"] + 1 + prev_frames = float(animated[-2].attrib["time"][:-1]) * settings.lottie_format["fr"] + lottie["k"][-1]["t"] = prev_frames + 1 time_adjust(lottie, animated) diff --git a/synfig-studio/plugins/lottie-exporter/settings.py b/synfig-studio/plugins/lottie-exporter/settings.py index 895af4e..3ccfc63 100644 --- a/synfig-studio/plugins/lottie-exporter/settings.py +++ b/synfig-studio/plugins/lottie-exporter/settings.py @@ -30,6 +30,10 @@ OUT_TANGENT_X = 0.42 OUT_TANGENT_Y = 0 def init(): + """ + Initialises the final dictionary corresponding to conversion and + also the canvas dictionary needed in misc functions + """ # Final converted dictionary global lottie_format lottie_format = {} diff --git a/synfig-studio/plugins/lottie-exporter/shapes/fill.py b/synfig-studio/plugins/lottie-exporter/shapes/fill.py index d170bb7..ef5bb48 100644 --- a/synfig-studio/plugins/lottie-exporter/shapes/fill.py +++ b/synfig-studio/plugins/lottie-exporter/shapes/fill.py @@ -1,12 +1,12 @@ """ -Fill this +Will have all the functions required for generate the fill(color) in lottie """ import sys -sys.path.append("..") import settings from properties.value import gen_properties_value from properties.valueKeyframed import gen_value_Keyframed from misc import Count, is_animated +sys.path.append("..") def gen_shapes_fill(lottie, layer): """ @@ -34,10 +34,12 @@ def gen_shapes_fill(lottie, layer): red, green, blue = red ** (1/settings.GAMMA), green **\ (1/settings.GAMMA), blue ** (1/ settings.GAMMA) alpha = float(val[3].text) - gen_properties_value( - lottie["c"], [ - red, green, blue, alpha], index.inc(), - settings.DEFAULT_ANIMATED, settings.NO_INFO) + gen_properties_value(lottie["c"], + [red, green, blue, alpha], + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) + elif child.attrib["name"] == "amount": is_animate = is_animated(child[0]) if is_animate == 2: @@ -50,5 +52,8 @@ def gen_shapes_fill(lottie, layer): val = float(child[0].attrib["value"]) * settings.OPACITY_CONSTANT else: val = float(child[0][0][0].attrib["value"]) * settings.OPACITY_CONSTANT - gen_properties_value(lottie["o"], val, index.inc(), settings.DEFAULT_ANIMATED, settings.NO_INFO) - + gen_properties_value(lottie["o"], + val, + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) diff --git a/synfig-studio/plugins/lottie-exporter/shapes/star.py b/synfig-studio/plugins/lottie-exporter/shapes/star.py index a18d787..8f03e26 100644 --- a/synfig-studio/plugins/lottie-exporter/shapes/star.py +++ b/synfig-studio/plugins/lottie-exporter/shapes/star.py @@ -1,13 +1,13 @@ """ -Fill this +Will store all functions needed to generate the star layer in lottie """ import sys -sys.path.append("..") import settings from properties.value import gen_properties_value from misc import get_angle, Count, change_axis, is_animated from properties.multiDimensionalKeyframed import gen_properties_multi_dimensional_keyframed from properties.valueKeyframed import gen_value_Keyframed +sys.path.append("..") def gen_shapes_star(lottie, layer, idx): """ @@ -27,6 +27,7 @@ def gen_shapes_star(lottie, layer, idx): if child.tag == "param": if child.attrib["name"] == "regular_polygon": regular_polygon = child[0].attrib["value"] + elif child.attrib["name"] == "points": is_animate = is_animated(child[0]) if is_animate == 2: @@ -91,31 +92,40 @@ def gen_shapes_star(lottie, layer, idx): is_animate = is_animated(child[0]) if is_animate == 2: gen_properties_multi_dimensional_keyframed(lottie["p"], - child[0], index.inc()) + child[0], + index.inc()) else: x_val, y_val = 0, 0 if is_animate == 0: x_val = float(child[0][0].text) * settings.PIX_PER_UNIT - y_val = float(child[0][0].text) * settings.PIX_PER_UNIT + y_val = float(child[0][1].text) * settings.PIX_PER_UNIT else: x_val = float(child[0][0][0][0].text) * settings.PIX_PER_UNIT - y_val = float(child[0][0][0][0].text) * settings.PIX_PER_UNIT - gen_properties_value(lottie["p"], change_axis(x_val, y_val), - index.inc(), settings.DEFAULT_ANIMATED, + y_val = float(child[0][0][0][1].text) * settings.PIX_PER_UNIT + gen_properties_value(lottie["p"], + change_axis(x_val, y_val), + index.inc(), + settings.DEFAULT_ANIMATED, settings.NO_INFO) if regular_polygon == "false": lottie["sy"] = 1 # Star Type # inner property is only needed if type is star - gen_properties_value(lottie["is"], 0, index.inc(), - settings.DEFAULT_ANIMATED, settings.NO_INFO) + gen_properties_value(lottie["is"], + 0, + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) else: lottie["sy"] = 2 # Polygon Type # for polygon type, "ir" and "is" must not be present del lottie["ir"] - gen_properties_value(lottie["os"], 0, index.inc(), - settings.DEFAULT_ANIMATED, settings.NO_INFO) + gen_properties_value(lottie["os"], + 0, + index.inc(), + settings.DEFAULT_ANIMATED, + settings.NO_INFO) lottie["ix"] = idx