File indexing completed on 2025-01-19 03:59:55
0001 from ..objects.base import LottieObject, ObjectVisitor 0002 from ..objects.bezier import Bezier 0003 from ..objects.helpers import Transform 0004 from ..nvector import NVector 0005 0006 0007 class Strip(ObjectVisitor): 0008 def __init__(self, float_round, remove_attributes={}): 0009 self.float_round = float_round 0010 self.remove_attributes = remove_attributes 0011 0012 def round(self, fl): 0013 return round(fl, self.float_round) 0014 0015 def nvector(self, value): 0016 value.components = list(map(self.round, value.components)) 0017 return value 0018 0019 def visit_property(self, object, property, value): 0020 if isinstance(value, Bezier): 0021 for l in ["vertices", "in_tangents", "out_tangents"]: 0022 setattr(value, l, [self.nvector(NVector(p.x, p.y)) for p in getattr(value, l)]) 0023 elif property.lottie in self.remove_attributes: 0024 property.set(object, None) 0025 elif isinstance(value, float): 0026 property.set(object, round(value, 3)) 0027 elif isinstance(value, NVector): 0028 self.nvector(value) 0029 0030 0031 class TransformStip(Strip): 0032 def visit(self, object): 0033 if isinstance(object, Transform): 0034 self.transform_unset(object, "anchor_point", NVector(0, 0)) 0035 self.transform_unset(object, "position", NVector(0, 0)) 0036 #self.transform_unset(object, "scale", NVector(100, 100)) 0037 self.transform_unset(object, "rotation", 0) 0038 #self.transform_unset(object, "opacity", 100) 0039 self.transform_unset(object, "skew", 0) 0040 self.transform_unset(object, "skew_axis", 0) 0041 0042 def transform_unset(self, object, prop_name, value): 0043 prop = getattr(object, prop_name) 0044 if not prop.animated and prop.value == value: 0045 setattr(object, prop_name, None) 0046 0047 0048 heavy_strip = TransformStip(3, {"ind", "ix", "nm", "mn"}) 0049 float_strip = Strip(3)