From 874cf52c10d73911cfec709d9b0202ac690aab6f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 6 Oct 2020 17:43:12 +0200 Subject: Refactor: Remove `BKE_XXX_localize()`, in favor of using regular ID copying code. Besides the NodeTree case (which remains unchanged), the localize code is only used in one place (to generate previews of shading data-blocks). This commit introduces a new `LIB_ID_CREATE_LOCAL` option for ID creation/copying, which essentially implements the behavior of the removed `BKE_XXX_localize()` functions into regular mainstream ID copy code. When this option is set: - new ID is tagged with `LIB_TAG_LOCALIZED`; - Some ID copying callbacks have specific behaviors, mainly the root nodetree of shading IDs gets duplicated with specialized `ntreeLocalize()` function. Note that I would not consider getting rid of `ntreeLocalize` for now, this function is recursive, which should ideally never happen within ID management copying code (this introduces all kind of complications). No behavioral change expected from this commit. --- source/blender/editors/render/render_preview.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 4a4f6127851..d7eaaf3277b 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -325,7 +325,13 @@ static World *preview_get_localized_world(ShaderPreview *sp, World *world) if (sp->worldcopy != NULL) { return sp->worldcopy; } - sp->worldcopy = BKE_world_localize(world); + + ID *id_copy; + BKE_id_copy_ex(NULL, + &world->id, + &id_copy, + LIB_ID_CREATE_LOCAL | LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA); + sp->worldcopy = (World *)id_copy; BLI_addtail(&sp->pr_main->worlds, sp->worldcopy); return sp->worldcopy; } @@ -339,13 +345,16 @@ static ID *duplicate_ids(ID *id) switch (GS(id->name)) { case ID_MA: - return (ID *)BKE_material_localize((Material *)id); case ID_TE: - return (ID *)BKE_texture_localize((Tex *)id); case ID_LA: - return (ID *)BKE_light_localize((Light *)id); - case ID_WO: - return (ID *)BKE_world_localize((World *)id); + case ID_WO: { + ID *id_copy; + BKE_id_copy_ex(NULL, + id, + &id_copy, + LIB_ID_CREATE_LOCAL | LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA); + return id_copy; + } case ID_IM: case ID_BR: case ID_SCR: -- cgit v1.2.3