BKE_library: id_copy: More general usage of LIB_ID_COPY_LOCALIZE.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 4 Feb 2019 16:51:15 +0000 (17:51 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 5 Feb 2019 09:53:16 +0000 (10:53 +0100)
Turns out most of our 'local working copy' cases can use same set of
flags.

Note that this commit adds LIB_ID_COPY_CACHES to all our local meshes
copying, however this is no-op since that flag is unused during mesh
copying... We may want to add another set of flags without that one at
some point, but for now it would not be useful imho.

17 files changed:
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/mesh_convert.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/particle_distribute.c
source/blender/blenkernel/intern/particle_system.c
source/blender/collada/collada_utils.cpp
source/blender/editors/physics/particle_object.c
source/blender/modifiers/intern/MOD_boolean.c
source/blender/modifiers/intern/MOD_cloth.c
source/blender/modifiers/intern/MOD_collision.c
source/blender/modifiers/intern/MOD_datatransfer.c
source/blender/modifiers/intern/MOD_normal_edit.c
source/blender/modifiers/intern/MOD_ocean.c
source/blender/modifiers/intern/MOD_surface.c
source/blender/modifiers/intern/MOD_util.c
source/blender/modifiers/intern/MOD_weighted_normal.c

index 28cdf3b3b3627d451e1a743a33ce303168c8b8d3..5df8210d075f6cff00658c762735053898fb258c 100644 (file)
@@ -999,9 +999,7 @@ static void curve_calc_modifiers_post(
                        if (modified) {
                                if (vertCos) {
                                        Mesh *temp_mesh;
-                                       BKE_id_copy_ex(NULL, &modified->id, (ID **)&temp_mesh,
-                                                      LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT |
-                                                      LIB_ID_CREATE_NO_DEG_TAG | LIB_ID_COPY_NO_PREVIEW);
+                                       BKE_id_copy_ex(NULL, &modified->id, (ID **)&temp_mesh, LIB_ID_COPY_LOCALIZE);
                                        BKE_id_free(NULL, modified);
                                        modified = temp_mesh;
 
@@ -1044,9 +1042,7 @@ static void curve_calc_modifiers_post(
        if (vertCos) {
                if (modified) {
                        Mesh *temp_mesh;
-                       BKE_id_copy_ex(NULL, &modified->id, (ID **)&temp_mesh,
-                                      LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT |
-                                      LIB_ID_CREATE_NO_DEG_TAG | LIB_ID_COPY_NO_PREVIEW);
+                       BKE_id_copy_ex(NULL, &modified->id, (ID **)&temp_mesh, LIB_ID_COPY_LOCALIZE);
                        BKE_id_free(NULL, modified);
                        modified = temp_mesh;
 
index 30080b64e9509b93f4d655412a67a471d1804fe2..93bba2cf9d2caffb7887a3e42ef15027cba2d8d9 100644 (file)
@@ -609,9 +609,7 @@ Mesh *BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int lo
        Mesh *mesh = BKE_libblock_alloc(
                NULL, ID_ME,
                BKE_idcode_to_name(ID_ME),
-               LIB_ID_CREATE_NO_MAIN |
-               LIB_ID_CREATE_NO_USER_REFCOUNT |
-               LIB_ID_CREATE_NO_DEG_TAG);
+               LIB_ID_COPY_LOCALIZE);
        BKE_libblock_init_empty(&mesh->id);
 
        /* don't use CustomData_reset(...); because we dont want to touch customdata */
@@ -691,10 +689,7 @@ Mesh *BKE_mesh_new_nomain_from_template(
 
 Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference)
 {
-       int flags = (LIB_ID_CREATE_NO_MAIN |
-                    LIB_ID_CREATE_NO_USER_REFCOUNT |
-                    LIB_ID_CREATE_NO_DEG_TAG |
-                    LIB_ID_COPY_NO_PREVIEW);
+       int flags = LIB_ID_COPY_LOCALIZE;
 
        if (reference) {
                flags |= LIB_ID_COPY_CD_REFERENCE;
index b48ede55e522725920101e304e2d025f7e18dc46..ee72291b87a436dff15dea447c1918c47815300f 100644 (file)
@@ -1141,12 +1141,7 @@ Mesh *BKE_mesh_create_derived_for_modifier(
                float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts);
 
                mti->deformVerts(md, &mectx, NULL, deformedVerts, numVerts);
-               BKE_id_copy_ex(
-                       NULL, &me->id, (ID **)&result,
-                       LIB_ID_CREATE_NO_MAIN |
-                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                       LIB_ID_CREATE_NO_DEG_TAG |
-                       LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, &me->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
                BKE_mesh_apply_vert_coords(result, deformedVerts);
 
                if (build_shapekey_layers)
@@ -1156,12 +1151,7 @@ Mesh *BKE_mesh_create_derived_for_modifier(
        }
        else {
                Mesh *mesh_temp;
-               BKE_id_copy_ex(
-                       NULL, &me->id, (ID **)&mesh_temp,
-                       LIB_ID_CREATE_NO_MAIN |
-                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                       LIB_ID_CREATE_NO_DEG_TAG |
-                       LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, &me->id, (ID **)&mesh_temp, LIB_ID_COPY_LOCALIZE);
 
                if (build_shapekey_layers)
                        add_shapekey_layers(mesh_temp, me);
index daa7ce80ba212cae0674595d454bba484219d03f..4c09c6877247c9c2caa0d149b750992eaae59f67 100644 (file)
@@ -2035,9 +2035,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
                 */
                BKE_id_copy_ex(
                        NULL, &ntree->id, (ID **)&ltree,
-                       (LIB_ID_CREATE_NO_MAIN |
-                        LIB_ID_CREATE_NO_USER_REFCOUNT |
-                        LIB_ID_COPY_NO_PREVIEW |
+                       (LIB_ID_COPY_LOCALIZE |
                         LIB_ID_COPY_NO_ANIMDATA));
 
                for (node = ltree->nodes.first; node; node = node->next) {
index b2372c40b46f7272688a35dbc87717b17732b195..2abfebfe9022aeafb425d13520ff01fa3c32dbe3 100644 (file)
@@ -858,12 +858,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
                                mesh = final_mesh;
                        }
                        else {
-                               BKE_id_copy_ex(
-                                       NULL, ob->data, (ID **)&mesh,
-                                       LIB_ID_CREATE_NO_MAIN |
-                                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                                       LIB_ID_CREATE_NO_DEG_TAG |
-                                       LIB_ID_COPY_NO_PREVIEW);
+                               BKE_id_copy_ex(NULL, ob->data, (ID **)&mesh, LIB_ID_COPY_LOCALIZE);
                        }
                        BKE_mesh_tessface_ensure(mesh);
 
@@ -909,12 +904,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
                if (psys->part->use_modifier_stack)
                        mesh = final_mesh;
                else
-                       BKE_id_copy_ex(
-                                   NULL, ob->data, (ID **)&mesh,
-                                   LIB_ID_CREATE_NO_MAIN |
-                                   LIB_ID_CREATE_NO_USER_REFCOUNT |
-                                   LIB_ID_CREATE_NO_DEG_TAG |
-                                   LIB_ID_COPY_NO_PREVIEW);
+                       BKE_id_copy_ex(NULL, ob->data, (ID **)&mesh, LIB_ID_COPY_LOCALIZE);
 
                BKE_mesh_tessface_ensure(mesh);
 
index 77422ca20e387d2344a3753f0adf2d6913d4273f..aebee71fc5122c1962a8943cabd3ca8925d3d18f 100644 (file)
@@ -3195,12 +3195,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
        clmd_effweights = psys->clmd->sim_parms->effector_weights;
        psys->clmd->sim_parms->effector_weights = psys->part->effector_weights;
 
-       BKE_id_copy_ex(
-                   NULL, &psys->hair_in_mesh->id, (ID **)&psys->hair_out_mesh,
-                   LIB_ID_CREATE_NO_MAIN |
-                   LIB_ID_CREATE_NO_USER_REFCOUNT |
-                   LIB_ID_CREATE_NO_DEG_TAG |
-                   LIB_ID_COPY_NO_PREVIEW);
+       BKE_id_copy_ex(NULL, &psys->hair_in_mesh->id, (ID **)&psys->hair_out_mesh, LIB_ID_COPY_LOCALIZE);
        deformedVerts = BKE_mesh_vertexCos_get(psys->hair_out_mesh, NULL);
        clothModifier_do(psys->clmd, sim->depsgraph, sim->scene, sim->ob, psys->hair_in_mesh, deformedVerts);
        BKE_mesh_apply_vert_coords(psys->hair_out_mesh, deformedVerts);
index 63290f38ac8df732ee766fedf0dc32a1e943c4e7..1b9deded8a8888c96ea4d0b578ab074e15af54aa 100644 (file)
@@ -283,11 +283,7 @@ Mesh *bc_get_mesh_copy(
                tmpmesh = (Mesh *)ob->data;
        }
 
-       BKE_id_copy_ex(NULL, &tmpmesh->id, (ID **)&tmpmesh,
-                      LIB_ID_CREATE_NO_MAIN |
-                      LIB_ID_CREATE_NO_USER_REFCOUNT |
-                      LIB_ID_CREATE_NO_DEG_TAG |
-                      LIB_ID_COPY_NO_PREVIEW);
+       BKE_id_copy_ex(NULL, &tmpmesh->id, (ID **)&tmpmesh, LIB_ID_COPY_LOCALIZE);
 
        if (triangulate) {
                bc_triangulate_mesh(tmpmesh);
index 4894828f80823c499dad96c75c074a8412a50b7a..c8a161b7ac01f65d73ba00fa7a14087e00c1c5dc 100644 (file)
@@ -717,12 +717,7 @@ static bool remap_hair_emitter(
                return false;
        }
        /* don't modify the original vertices */
-       BKE_id_copy_ex(
-                   NULL, &mesh->id, (ID **)&mesh,
-                   LIB_ID_CREATE_NO_MAIN |
-                   LIB_ID_CREATE_NO_USER_REFCOUNT |
-                   LIB_ID_CREATE_NO_DEG_TAG |
-                   LIB_ID_COPY_NO_PREVIEW);
+       BKE_id_copy_ex(NULL, &mesh->id, (ID **)&mesh, LIB_ID_COPY_LOCALIZE);
 
        /* BMESH_ONLY, deform dm may not have tessface */
        BKE_mesh_tessface_ensure(mesh);
@@ -1098,12 +1093,7 @@ static bool copy_particle_systems_to_object(const bContext *C,
                modifier_unique_name(&ob_to->modifiers, (ModifierData *)psmd);
 
                psmd->psys = psys;
-               BKE_id_copy_ex(
-                           NULL, &final_mesh->id, (ID **)&psmd->mesh_final,
-                           LIB_ID_CREATE_NO_MAIN |
-                           LIB_ID_CREATE_NO_USER_REFCOUNT |
-                           LIB_ID_CREATE_NO_DEG_TAG |
-                           LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, &final_mesh->id, (ID **)&psmd->mesh_final, LIB_ID_COPY_LOCALIZE);
 
                BKE_mesh_calc_normals(psmd->mesh_final);
                BKE_mesh_tessface_ensure(psmd->mesh_final);
index 2aab1b7844db2446b85f8b2d3424fd3e98635801..c4fbce54937cc3c200eed8d08f93d565baff4515 100644 (file)
@@ -111,11 +111,7 @@ static Mesh *get_quick_mesh(
                                        result = mesh_self;
                                }
                                else {
-                                       BKE_id_copy_ex(NULL, &mesh_other->id, (ID **)&result,
-                                                      LIB_ID_CREATE_NO_MAIN |
-                                                      LIB_ID_CREATE_NO_USER_REFCOUNT |
-                                                      LIB_ID_CREATE_NO_DEG_TAG |
-                                                      LIB_ID_COPY_NO_PREVIEW);
+                                       BKE_id_copy_ex(NULL, &mesh_other->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
 
                                        float imat[4][4];
                                        float omat[4][4];
index 27ec0595b542af5bb8f14373ca2b91860d4b2275..c1072ba94cf7032049da7fede8c6d24ee6f5e530 100644 (file)
@@ -87,12 +87,7 @@ static void deformVerts(
        else {
                /* Not possible to use get_mesh() in this case as we'll modify its vertices
                 * and get_mesh() would return 'mesh' directly. */
-               BKE_id_copy_ex(
-                       NULL, (ID *)mesh, (ID **)&mesh_src,
-                       LIB_ID_CREATE_NO_MAIN |
-                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                       LIB_ID_CREATE_NO_DEG_TAG |
-                       LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, (ID *)mesh, (ID **)&mesh_src, LIB_ID_COPY_LOCALIZE);
        }
 
        /* TODO(sergey): For now it actually duplicates logic from DerivedMesh.c
index 541bbf32af8ad0a46c4b93e3874ec2278776835d..cba6f8774ed2dd8a174568419b5c6dc7df6fa83c 100644 (file)
@@ -107,12 +107,7 @@ static void deformVerts(
        else {
                /* Not possible to use get_mesh() in this case as we'll modify its vertices
                 * and get_mesh() would return 'mesh' directly. */
-               BKE_id_copy_ex(
-                       NULL, (ID *)mesh, (ID **)&mesh_src,
-                       LIB_ID_CREATE_NO_MAIN |
-                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                       LIB_ID_CREATE_NO_DEG_TAG |
-                       LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, (ID *)mesh, (ID **)&mesh_src, LIB_ID_COPY_LOCALIZE);
        }
 
        if (!ob->pd) {
index 1e90642cf62d23361bff8036f42f817df538faf5..56fda2951f6c1f2703926667133eeee07bce9633 100644 (file)
@@ -177,12 +177,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
        {
                /* We need to duplicate data here, otherwise setting custom normals, edges' shaprness, etc., could
                 * modify org mesh, see T43671. */
-               BKE_id_copy_ex(
-                       NULL, &me_mod->id, (ID **)&result,
-                       LIB_ID_CREATE_NO_MAIN |
-                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                       LIB_ID_CREATE_NO_DEG_TAG |
-                       LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, &me_mod->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
        }
 
        BKE_reports_init(&reports, RPT_STORE);
index 37e3acdee1f862423102bd5b57effb49edf21116..e06a53cc0587ca872d43a82556618a937d3d0f50 100644 (file)
@@ -411,12 +411,7 @@ static Mesh *normalEditModifier_do(
        if (mesh->medge == ((Mesh *)ob->data)->medge) {
                /* We need to duplicate data here, otherwise setting custom normals (which may also affect sharp edges) could
                 * modify org mesh, see T43671. */
-               BKE_id_copy_ex(
-                       NULL, &mesh->id, (ID **)&result,
-                       LIB_ID_CREATE_NO_MAIN |
-                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                       LIB_ID_CREATE_NO_DEG_TAG |
-                       LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
        }
        else {
                result = mesh;
index e0f6eff56d46f6e7b9e5270b319c84e34466d31b..f44c70f088c56ac5c46d512128a57eb68775f07b 100644 (file)
@@ -384,11 +384,7 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes
                BKE_mesh_ensure_normals(result);
        }
        else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) {
-               BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result,
-                              LIB_ID_CREATE_NO_MAIN |
-                              LIB_ID_CREATE_NO_USER_REFCOUNT |
-                              LIB_ID_CREATE_NO_DEG_TAG |
-                              LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
        }
 
        cfra_for_cache = cfra_scene;
index beaf471778b5760a059f8519e67bb21506193237..343e4b048fd4450e8cefd4fbfc0f61300d5231d5 100644 (file)
@@ -114,12 +114,7 @@ static void deformVerts(
        if (mesh) {
                /* Not possible to use get_mesh() in this case as we'll modify its vertices
                 * and get_mesh() would return 'mesh' directly. */
-               BKE_id_copy_ex(
-                       NULL, (ID *)mesh, (ID **)&surmd->mesh,
-                       LIB_ID_CREATE_NO_MAIN |
-                       LIB_ID_CREATE_NO_USER_REFCOUNT |
-                       LIB_ID_CREATE_NO_DEG_TAG |
-                       LIB_ID_COPY_NO_PREVIEW);
+               BKE_id_copy_ex(NULL, (ID *)mesh, (ID **)&surmd->mesh, LIB_ID_COPY_LOCALIZE);
        }
        else {
                surmd->mesh = MOD_deform_mesh_eval_get(ctx->object, NULL, NULL, NULL, numVerts, false, false);
index d40dd6545b75184109c8cc983f449c779f9dd2e6..6953ee3c3b8a3f14bc82980576711a92b1358516 100644 (file)
@@ -186,10 +186,7 @@ Mesh *MOD_deform_mesh_eval_get(
                        Mesh *mesh_prior_modifiers = BKE_object_get_pre_modified_mesh(ob);
                        BKE_id_copy_ex(
                                NULL, &mesh_prior_modifiers->id, (ID **)&mesh,
-                               (LIB_ID_CREATE_NO_MAIN |
-                                LIB_ID_CREATE_NO_USER_REFCOUNT |
-                                LIB_ID_CREATE_NO_DEG_TAG |
-                                LIB_ID_COPY_NO_PREVIEW |
+                               (LIB_ID_COPY_LOCALIZE |
                                 LIB_ID_COPY_CD_REFERENCE));
                        mesh->runtime.deformed_only = 1;
                }
index d61fcb01d5e1a695b7ad62d2210715359051acf1..a21854060adba4827a99651967132ded3444f80c 100644 (file)
@@ -490,12 +490,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes
        }
 
        Mesh *result;
-       BKE_id_copy_ex(
-               NULL, &mesh->id, (ID **)&result,
-               LIB_ID_CREATE_NO_MAIN |
-               LIB_ID_CREATE_NO_USER_REFCOUNT |
-               LIB_ID_CREATE_NO_DEG_TAG |
-               LIB_ID_COPY_NO_PREVIEW);
+       BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, LIB_ID_COPY_LOCALIZE);
 
        const int numVerts = result->totvert;
        const int numEdges = result->totedge;