Skip to content

Commit

Permalink
[Lottie Exporter] Added support for Vector X and Vector Y convert met…
Browse files Browse the repository at this point in the history
…hod (#1516)

* Added support for Vector X and Vector Y convert method

* Reduced Lines of code
  • Loading branch information
saurabh-ramola authored Jun 29, 2020
1 parent 15080f9 commit 5102d5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions synfig-studio/plugins/lottie-exporter/common/Param.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,23 @@ def recur_animate(self, anim_type):
self.expression = ret
return ret, self.expression_controllers

elif self.param[0].tag == "vectorx":
self.subparams["vectorx"].extract_subparams()
vector, eff_1 = self.subparams["vectorx"].subparams["vector"].recur_animate("vector")
self.expression_controllers.extend(eff_1)
ret = "[{x}[0], {x}[0]]" if self.dimension == 2 else "{x}[0]"
ret = ret.format(x=vector)
self.expression = ret
return ret, self.expression_controllers

elif self.param[0].tag == "vectory":
self.subparams["vectory"].extract_subparams()
vector, eff_1 = self.subparams["vectory"].subparams["vector"].recur_animate("vector")
self.expression_controllers.extend(eff_1)
ret = "[{y}[1], {y}[1]]" if self.dimension == 2 else "{y}[1]"
ret = ret.format(y=vector)
self.expression = ret
return ret, self.expression_controllers
else:
self.single_animate(anim_type)
# Insert the animation into the effect
Expand Down Expand Up @@ -875,6 +892,14 @@ def __get_value(self, frame):
rad = math.pi/180
ret = math.atan2(vector[1],vector[0])/rad

elif self.param[0].tag == "vectorx":
vector = self.subparams["vectorx"].subparams["vector"].__get_value(frame)
ret = vector[0]

elif self.param[0].tag == "vectory":
vector = self.subparams["vectory"].subparams["vector"].__get_value(frame)
ret = vector[1]

else:
ret = self.get_single_value(frame)
if isinstance(ret, list):
Expand Down Expand Up @@ -1040,6 +1065,14 @@ def update_frame_window(self, window):
self.subparams["vectorangle"].extract_subparams()
self.subparams["vectorangle"].subparams["vector"].update_frame_window(window)

elif node.tag == "vectorx":
self.subparams["vectorx"].extract_subparams()
self.subparams["vectorx"].subparams["vector"].update_frame_window(window)

elif node.tag == "vectory":
self.subparams["vectory"].extract_subparams()
self.subparams["vectory"].subparams["vector"].update_frame_window(window)

if is_animated(node) == settings.ANIMATED:
for waypoint in node:
fr = common.misc.get_frame(waypoint)
Expand Down
2 changes: 1 addition & 1 deletion synfig-studio/plugins/lottie-exporter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
GROUP_LAYER = {"group", "switch"}
SKELETON_LAYER = {"skeleton"}
UNKNOWN_LAYER = "unknown_layer"
CONVERT_METHODS = {"add", "atan2","average", "bone", "bone_link", "bone_root", "composite", "cos", "exp", "fromint", "linear", "radial_composite", "scale", "sine", "subtract", "switch", "vectorangle","weighted_average"}
CONVERT_METHODS = {"add", "atan2","average", "bone", "bone_link", "bone_root", "composite", "cos", "exp", "fromint", "linear", "radial_composite", "scale", "sine", "subtract", "switch", "vectorangle", "vectorx", "vectory", "weighted_average"}
BONES = {"bone", "bone_root"}

# Some waypoint animated definitions
Expand Down

0 comments on commit 5102d5e

Please sign in to comment.