Esempio n. 1
0
def pre_save_datablock(proxy: DatablockProxy, target: T.ID,
                       context: Context) -> T.ID:
    """Process attributes that must be saved first and return a possibly updated reference to the target"""

    # WARNING this is called from save() and from apply()
    # When called from save, the proxy has  all the synchronized properties
    # WHen called from apply, the proxy only contains the updated properties

    if target.library:
        return target

    #  animation_data is handled in StructProxy (parent class of DatablockProxy)

    if isinstance(target, T.Mesh):
        from mixer.blender_data.mesh_proxy import MeshProxy

        assert isinstance(proxy, MeshProxy)
        if proxy.requires_clear_geometry(target):
            target.clear_geometry()
    elif isinstance(target, T.Material):
        is_grease_pencil = proxy.data("is_grease_pencil")
        # will be None for a DeltaUpdate that does not modify "is_grease_pencil"
        if is_grease_pencil is not None:
            # Seems to be write once as no depsgraph update is fired
            if is_grease_pencil and not target.grease_pencil:
                bpy.data.materials.create_gpencil_data(target)
            elif not is_grease_pencil and target.grease_pencil:
                bpy.data.materials.remove_gpencil_data(target)
    elif isinstance(target, T.Scene):
        from mixer.blender_data.misc_proxies import NonePtrProxy

        sequence_editor = proxy.data("sequence_editor")
        if sequence_editor is not None:
            # NonePtrProxy or StructProxy
            if not isinstance(sequence_editor,
                              NonePtrProxy) and target.sequence_editor is None:
                target.sequence_editor_create()
            elif isinstance(
                    sequence_editor,
                    NonePtrProxy) and target.sequence_editor is not None:
                target.sequence_editor_clear()
    elif isinstance(target, _morphable_types):
        # required first to have access to new datablock attributes
        type_ = proxy.data("type")
        if type_ is not None and type_ != target.type:
            target.type = type_
            # must reload the reference
            target = target.type_recast()
            uuid = proxy.mixer_uuid
            context.proxy_state.remove_datablock(uuid)
            context.proxy_state.add_datablock(uuid, target)
    elif isinstance(target, T.Action):
        groups = proxy.data("groups")
        if groups:
            groups.save(target.groups, target, "groups", context)

    return target
Esempio n. 2
0
def pre_save_datablock(proxy: DatablockProxy, target: T.ID,
                       context: Context) -> T.ID:
    """Process attributes that must be saved first and return a possibly updated reference to the target"""

    # WARNING this is called from save() and from apply()
    # When called from save, the proxy has  all the synchronized properties
    # WHen called from apply, the proxy only contains the updated properties

    if target.library:
        return target

    if isinstance(target, T.Mesh) and proxy.requires_clear_geometry(target):
        target.clear_geometry()
    elif isinstance(target, T.Material):
        is_grease_pencil = proxy.data("is_grease_pencil")
        # will be None for a DeltaUpdate that does not modify "is_grease_pencil"
        if is_grease_pencil is not None:
            # Seems to be write once as no depsgraph update is fired
            if is_grease_pencil and not target.grease_pencil:
                bpy.data.materials.create_gpencil_data(target)
            elif not is_grease_pencil and target.grease_pencil:
                bpy.data.materials.remove_gpencil_data(target)
    elif isinstance(target, T.Scene):
        from mixer.blender_data.misc_proxies import NonePtrProxy

        sequence_editor = proxy.data("sequence_editor")
        if sequence_editor is not None:
            # NonePtrProxy or StructProxy
            if not isinstance(sequence_editor,
                              NonePtrProxy) and target.sequence_editor is None:
                target.sequence_editor_create()
            elif isinstance(
                    sequence_editor,
                    NonePtrProxy) and target.sequence_editor is not None:
                target.sequence_editor_clear()
    elif isinstance(target, T.Light):
        # required first to have access to new light type attributes
        light_type = proxy.data("type")
        if light_type is not None and light_type != target.type:
            target.type = light_type
            # must reload the reference
            target = proxy.target(context)

    return target