From 3b6ee8cee7080af200e25e944fe30d310240e138 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 13 Jul 2021 12:10:34 -0400 Subject: Refactor: Move vertex group names to object data This commit moves the storage of `bDeformGroup` and the active index to `Mesh`, `Lattice`, and `bGPdata` instead of `Object`. Utility functions are added to allow easy access to the vertex groups given an object or an ID. As explained in T88951, the list of vertex group names is currently stored separately per object, even though vertex group data is stored on the geometry. This tends to complicate code and cause bugs, especially as geometry is created procedurally and tied less closely to an object. The "Copy Vertex Groups to Linked" operator is removed, since they are stored on the geometry anyway. This patch leaves the object-level python API for vertex groups in place. Creating a geometry-level RNA API can be a separate step; the changes in this commit are invasive enough as it is. Note that opening a file saved in 3.0 in an earlier version means the vertex groups will not be available. Differential Revision: https://developer.blender.org/D11689 --- source/blender/blenkernel/intern/mesh.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/blender/blenkernel/intern/mesh.c') diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index a92401d3ba0..c4186ad3180 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -39,6 +39,7 @@ #include "BLI_ghash.h" #include "BLI_hash.h" #include "BLI_linklist.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_memarena.h" #include "BLI_string.h" @@ -125,6 +126,8 @@ static void mesh_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int mesh_dst->mat = MEM_dupallocN(mesh_src->mat); + BKE_defgroup_copy_list(&mesh_dst->vertex_group_names, &mesh_src->vertex_group_names); + const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE; CustomData_copy(&mesh_src->vdata, &mesh_dst->vdata, mask.vmask, alloc_type, mesh_dst->totvert); CustomData_copy(&mesh_src->edata, &mesh_dst->edata, mask.emask, alloc_type, mesh_dst->totedge); @@ -155,6 +158,8 @@ static void mesh_free_data(ID *id) { Mesh *mesh = (Mesh *)id; + BLI_freelistN(&mesh->vertex_group_names); + BKE_mesh_runtime_clear_cache(mesh); mesh_clear_geometry(mesh); MEM_SAFE_FREE(mesh->mat); @@ -229,6 +234,8 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address BKE_animdata_blend_write(writer, mesh->adt); } + BKE_defbase_blend_write(writer, &mesh->vertex_group_names); + BLO_write_pointer_array(writer, mesh->totcol, mesh->mat); BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect); @@ -288,6 +295,7 @@ static void mesh_blend_read_data(BlendDataReader *reader, ID *id) /* Normally BKE_defvert_blend_read should be called in CustomData_blend_read, * but for backwards compatibility in do_versions to work we do it here. */ BKE_defvert_blend_read(reader, mesh->totvert, mesh->dvert); + BLO_read_list(reader, &mesh->vertex_group_names); CustomData_blend_read(reader, &mesh->vdata, mesh->totvert); CustomData_blend_read(reader, &mesh->edata, mesh->totedge); @@ -923,6 +931,12 @@ void BKE_mesh_copy_parameters(Mesh *me_dst, const Mesh *me_src) me_dst->texflag = me_src->texflag; copy_v3_v3(me_dst->loc, me_src->loc); copy_v3_v3(me_dst->size, me_src->size); + + /* Some callers call this on existing meshes, so free the existing vertex groups first. */ + BLI_freelistN(&me_dst->vertex_group_names); + BKE_defgroup_copy_list(&me_dst->vertex_group_names, &me_src->vertex_group_names); + + me_dst->vertex_group_active_index = me_src->vertex_group_active_index; } /** -- cgit v1.2.3 From 0cc2a72f94b71d5594a0aca088007ecbb3221b60 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 15 Jul 2021 12:25:36 -0400 Subject: Fix failing tests from vertex group name parameter copy It turns out `BKE_mesh_copy_parameters` can be called while other tools are running calculations, which meant that it was called at the same time as `armature_deform_coords_impl`. Beause of that, we shouldn't do any freeing (of the old vertex group names) there. Since the materials are copied in the "for_eval" version anyway, it seems to make sense to copy the vertex group name list there also. Fixes T89877, and also the failing `deform_modifiers` test. Differential Revision: https://developer.blender.org/D11936 --- source/blender/blenkernel/intern/mesh.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern/mesh.c') diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index c4186ad3180..4102703ca7c 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -932,10 +932,6 @@ void BKE_mesh_copy_parameters(Mesh *me_dst, const Mesh *me_src) copy_v3_v3(me_dst->loc, me_src->loc); copy_v3_v3(me_dst->size, me_src->size); - /* Some callers call this on existing meshes, so free the existing vertex groups first. */ - BLI_freelistN(&me_dst->vertex_group_names); - BKE_defgroup_copy_list(&me_dst->vertex_group_names, &me_src->vertex_group_names); - me_dst->vertex_group_active_index = me_src->vertex_group_active_index; } @@ -952,6 +948,10 @@ void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src) BKE_mesh_copy_parameters(me_dst, me_src); + /* Copy vertex group names. */ + BLI_assert(BLI_listbase_is_empty(&me_dst->vertex_group_names)); + BKE_defgroup_copy_list(&me_dst->vertex_group_names, &me_src->vertex_group_names); + /* Copy materials. */ if (me_dst->mat != NULL) { MEM_freeN(me_dst->mat); -- cgit v1.2.3 From bf5b1fa7266c510b22428f7f176aef545846004c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 16 Jul 2021 11:45:52 +1000 Subject: Cleanup: remove redundant parentheses --- source/blender/blenkernel/intern/mesh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/mesh.c') diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 4102703ca7c..b463d903303 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -312,7 +312,7 @@ static void mesh_blend_read_data(BlendDataReader *reader, ID *id) mesh->totselect = 0; } - if ((BLO_read_requires_endian_switch(reader)) && mesh->tface) { + if (BLO_read_requires_endian_switch(reader) && mesh->tface) { TFace *tf = mesh->tface; for (int i = 0; i < mesh->totface; i++, tf++) { BLI_endian_switch_uint32_array(tf->col, 4); -- cgit v1.2.3