예제 #1
0
def gen_layer_translate(lottie, layer):
    """
    Help generate transform properties of translate layer

    Args:
        lottie (dict) : Transform properties in lottie format
        layer  (common.Layer.Layer) : Transform properties in Synfig format

    Returns:
        (None)
    """

    origin = layer.get_param("origin")
    origin.animate("vector")
    pos = origin

    st = "<param name='anchor'><vector><x>0.00</x><y>0.00</y></vector></param>"
    anchor = etree.fromstring(st)
    anchor = Param(anchor, layer)
    anchor.animate("vector")
    anchor.add_offset()

    if settings.INSIDE_PRECOMP:
        pos.add_offset()
    anchor.animate("vector", True)
    pos.animate("vector", True)

    gen_helpers_transform(lottie, pos, anchor)
예제 #2
0
파일: group.py 프로젝트: warlockz/synfig
def gen_layer_group(lottie, layer, idx):
    """
    Will generate a pre composition but has small differences than pre-comp layer used in
    layers/preComp.py
    This function will be used for group layer as well as switch group layer

    Args:
        lottie (dict)               : Lottie format layer will be stored here
        layer (common.Layer.Layer) : Synfig format group/switch layer
        idx   (int)                 : Index of the layer

    Returns:
        (None)
    """
    lottie["ddd"] = settings.DEFAULT_3D
    lottie["ind"] = idx
    lottie["ty"] = settings.LAYER_PRECOMP_TYPE
    lottie["sr"] = settings.LAYER_DEFAULT_STRETCH
    lottie["ks"] = {}  # Transform properties to be filled
    lottie["nm"] = layer.get_description()
    index = Count()

    # Extract parameters
    canvas = Canvas(layer.get_param("canvas"))
    origin = layer.get_param("origin")
    opacity = layer.get_param("amount")
    outline_grow = layer.get_param("outline_grow")
    time_offset = layer.get_param("time_offset")
    time_dilation = layer.get_param("time_dilation")
    transformation = layer.get_param("transformation")
    transform = transformation[0]
    try_par = Param(transform, Param(transformation.get(), layer))
    for child in transform:
        if child.tag == "scale":
            scale = Param(child, try_par)
        elif child.tag == "offset":
            pos = Param(child, try_par)
        elif child.tag == "angle":
            angle = Param(child, try_par)
        elif child.tag == "skew_angle":
            skew = Param(child, try_par)

    outline_grow.animate("real")

    origin.animate("vector")
    anchor = origin
    anchor.add_offset()

    angle.animate("rotate_layer_angle")

    pos.animate("vector")
    if settings.INSIDE_PRECOMP:
        pos.add_offset()

    scale.animate("group_layer_scale")
    # Generating animation for skew
    skew.animate("rotate_layer_angle")
    # Animating opacity
    opacity.animate("opacity")

    # Reset the animations after adding offset
    anchor.animate("vector", True)
    pos.animate("vector", True)
    # Generate the transform properties here
    gen_helpers_transform(lottie["ks"], pos, anchor, scale, angle, opacity,
                          skew)

    # Store previous states, to be recovered at the end of group layer
    prev_state = settings.INSIDE_PRECOMP
    settings.OUTLINE_GROW.append(
        outline_grow
    )  # Storing the outline grow in settings, will be used inside child outlines

    settings.INSIDE_PRECOMP = True

    settings.lottie_format["assets"].append({})
    asset = add_precomp_asset(settings.lottie_format["assets"][-1], canvas,
                              canvas.get_num_layers())
    lottie["refId"] = asset

    lottie["w"] = settings.lottie_format[
        "w"] + settings.ADDITIONAL_PRECOMP_WIDTH  # Experimental increase in width and height of precomposition
    lottie[
        "h"] = settings.lottie_format["h"] + settings.ADDITIONAL_PRECOMP_HEIGHT
    lottie["ao"] = settings.LAYER_DEFAULT_AUTO_ORIENT
    lottie["ip"] = settings.lottie_format["ip"]
    lottie["op"] = settings.lottie_format["op"]
    lottie["st"] = 0  # Don't know yet
    get_blend(lottie, layer)

    # Time offset and speed
    lottie["tm"] = {}
    gen_time_remap(lottie["tm"], time_offset, time_dilation, index.inc())

    # Change opacity of layers for switch-group layers
    if layer.get_type() == "switch":
        change_opacity_switch(layer, lottie)
    # Change opacity of layers for group layers
    elif layer.get_type() == "group":
        change_opacity_group(layer, lottie)

    # Return to previous state, when we go outside the group layer
    settings.INSIDE_PRECOMP = prev_state
    settings.OUTLINE_GROW.pop()