From ee18b625cadbe16cab825ecd4ebeeee57cdd7f6d Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 14 Mar 2023 12:03:46 -0400 Subject: [PATCH] Fix: Edit mesh face corner color operators always use first layer The operator went through quite a bit of trouble to pass a color attribute index to the operator, but then it always used the offset from the first layer of the active color attribute's type. Also remove the "copy domains temp" API function, which generalized this more than necessary, and exposed the internals of the custom data system a bit more than we would like. --- source/blender/blenkernel/BKE_attribute.h | 15 ------ source/blender/blenkernel/intern/attribute.cc | 49 ------------------- source/blender/bmesh/operators/bmo_utils.c | 19 +++---- source/blender/editors/mesh/editmesh_tools.cc | 4 +- 4 files changed, 12 insertions(+), 75 deletions(-) diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h index de16d207c85..096c89098bb 100644 --- a/source/blender/blenkernel/BKE_attribute.h +++ b/source/blender/blenkernel/BKE_attribute.h @@ -106,21 +106,6 @@ int BKE_id_attribute_to_index(const struct ID *id, eAttrDomainMask domain_mask, eCustomDataMask layer_mask); -/** - * Sets up a temporary ID with arbitrary CustomData domains. `r_id` will - * be zero initialized with ID type id_type and any non-nullptr - * CustomData parameter will be copied into the appropriate struct members. - * - * \param r_id: Pointer to storage sufficient for ID type-code id_type. - */ -void BKE_id_attribute_copy_domains_temp(short id_type, - const struct CustomData *vdata, - const struct CustomData *edata, - const struct CustomData *ldata, - const struct CustomData *pdata, - const struct CustomData *cdata, - struct ID *r_id); - const char *BKE_id_attributes_active_color_name(const struct ID *id); const char *BKE_id_attributes_default_color_name(const struct ID *id); void BKE_id_attributes_active_color_set(struct ID *id, const char *name); diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 935a195a2e9..c992c45a956 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -830,55 +830,6 @@ CustomDataLayer *BKE_id_attributes_color_find(const ID *id, const char *name) return nullptr; } -void BKE_id_attribute_copy_domains_temp(short id_type, - const CustomData *vdata, - const CustomData *edata, - const CustomData *ldata, - const CustomData *pdata, - const CustomData *cdata, - ID *r_id) -{ - CustomData reset; - - CustomData_reset(&reset); - - switch (id_type) { - case ID_ME: { - Mesh *me = (Mesh *)r_id; - memset((void *)me, 0, sizeof(*me)); - - me->edit_mesh = nullptr; - - me->vdata = vdata ? *vdata : reset; - me->edata = edata ? *edata : reset; - me->ldata = ldata ? *ldata : reset; - me->pdata = pdata ? *pdata : reset; - - break; - } - case ID_PT: { - PointCloud *pointcloud = (PointCloud *)r_id; - - memset((void *)pointcloud, 0, sizeof(*pointcloud)); - - pointcloud->pdata = vdata ? *vdata : reset; - break; - } - case ID_CV: { - Curves *curves = (Curves *)r_id; - - memset((void *)curves, 0, sizeof(*curves)); - - curves->geometry.point_data = vdata ? *vdata : reset; - curves->geometry.curve_data = cdata ? *cdata : reset; - break; - } - default: - break; - } - - *((short *)r_id->name) = id_type; -} const char *BKE_uv_map_vert_select_name_get(const char *uv_map_name, char *buffer) { diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c index 8d4ba5c11f8..9109a8eda42 100644 --- a/source/blender/bmesh/operators/bmo_utils.c +++ b/source/blender/bmesh/operators/bmo_utils.c @@ -573,27 +573,28 @@ void bmo_reverse_uvs_exec(BMesh *bm, BMOperator *op) /**************************************************************************** * * Cycle colors for a face **************************************************************************** */ + static void bmo_get_loop_color_ref(BMesh *bm, int index, int *r_cd_color_offset, int *r_cd_color_type) { Mesh me_query; - - BKE_id_attribute_copy_domains_temp( - ID_ME, &bm->vdata, NULL, &bm->ldata, NULL, NULL, &me_query.id); + memset(&me_query, 0, sizeof(Mesh)); + CustomData_reset(&me_query.vdata); + CustomData_reset(&me_query.edata); + CustomData_reset(&me_query.pdata); + me_query.ldata = bm->ldata; + *((short *)me_query.id.name) = ID_ME; CustomDataLayer *layer = BKE_id_attribute_from_index( - &me_query.id, index, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL); - - if (!layer || BKE_id_attribute_domain(&me_query.id, layer) != ATTR_DOMAIN_CORNER) { + &me_query.id, index, ATTR_DOMAIN_MASK_CORNER, CD_MASK_COLOR_ALL); + if (!layer) { *r_cd_color_offset = -1; return; } - int layer_i = CustomData_get_layer_index(&bm->ldata, layer->type); - - *r_cd_color_offset = bm->ldata.layers[layer_i].offset; + *r_cd_color_offset = layer->offset; *r_cd_color_type = layer->type; } diff --git a/source/blender/editors/mesh/editmesh_tools.cc b/source/blender/editors/mesh/editmesh_tools.cc index 3b477fa3f75..561ad629bd7 100644 --- a/source/blender/editors/mesh/editmesh_tools.cc +++ b/source/blender/editors/mesh/editmesh_tools.cc @@ -3133,7 +3133,7 @@ static int edbm_rotate_colors_exec(bContext *C, wmOperator *op) } int color_index = BKE_id_attribute_to_index( - &me->id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL); + &me->id, layer, ATTR_DOMAIN_MASK_CORNER, CD_MASK_COLOR_ALL); EDBM_op_init(em, &bmop, op, @@ -3187,7 +3187,7 @@ static int edbm_reverse_colors_exec(bContext *C, wmOperator *op) BMOperator bmop; int color_index = BKE_id_attribute_to_index( - &me->id, layer, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL); + &me->id, layer, ATTR_DOMAIN_MASK_CORNER, CD_MASK_COLOR_ALL); EDBM_op_init( em, &bmop, op, "reverse_colors faces=%hf color_index=%i", BM_ELEM_SELECT, color_index);