def pre_save_id(proxy: Proxy, target: T.ID) -> T.ID: """Process attributes that must be saved first and return a possibly updated reference to the target Args: bpy_struct: The collection that contgains the ID attr_name: Its key Returns: [bpy.types.ID]: a possibly new ID """ if isinstance(target, T.Scene): # Set 'use_node' to True first is the only way I know to be able to set the 'node_tree' attribute use_nodes = proxy.data("use_nodes") if use_nodes: target.use_nodes = True sequence_editor = proxy.data("sequence_editor") if sequence_editor is not None and target.sequence_editor is None: target.sequence_editor_create() 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() elif isinstance(target, T.ColorManagedViewSettings): use_curve_mapping = proxy.data("use_curve_mapping") if use_curve_mapping: target.use_curve_mapping = True elif isinstance(target, bpy.types.World): use_nodes = proxy.data("use_nodes") if use_nodes: target.use_nodes = True return target
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
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 isinstance(target, T.Mesh) and proxy_requires_clear_geometry( proxy, target): target.clear_geometry() elif isinstance(target, T.Material): use_nodes = proxy.data("use_nodes") if use_nodes: target.use_nodes = True 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 # Set 'use_node' to True first is the only way I know to be able to set the 'node_tree' attribute use_nodes = proxy.data("use_nodes") if use_nodes: target.use_nodes = True 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) elif isinstance(target, T.World): use_nodes = proxy.data("use_nodes") if use_nodes: target.use_nodes = True return target