Fix #114760: new attribute does not get active for some domains

Problem here is that `BKE_id_attribute_to_index` [which
`BKE_id_attributes_active_set` uses] does not match
`BKE_id_attribute_from_index` which can lead to "wrong" indices (there
are "wrong" layers included while iterating such as ".corner_vert" or
".corner_edge" for faces).

Deeper reason is that `get_domains_types` swaps `ATTR_DOMAIN_FACE` and
`ATTR_DOMAIN_CORNER` (originally introduced in eae36be372 -- but unclear
at this point why this was done). Historically, this was used for operators
[vertex color rotate/inverse] introduced in c75e1598dd & 771a4dee0b,
assumption is that eae36be372 was trying to make this more generic and make
it work for other domains as well (ATTR_DOMAIN_MASK_COLOR -- the tootip
was also changed from "Rotate vertex colors inside faces" to "Rotate color
attributes inside faces"), however, at this point in time the tools clearly only work
for the corner domain (and this was made more specific in ee18b625ca as well).

So now, remove the swapping all together and make
`BKE_id_attribute_from_index` & `BKE_id_attribute_to_index` in sync.

Also change the tooltip of said operators to use "face corner color attribute".

Pull Request: https://projects.blender.org/blender/blender/pulls/114797
This commit is contained in:
Philipp Oeser
2023-12-07 15:33:28 +01:00
committed by Philipp Oeser
parent 8a6f7640d6
commit 481094ff5c
2 changed files with 9 additions and 25 deletions

View File

@@ -807,20 +807,6 @@ CustomDataLayer *BKE_id_attribute_from_index(ID *id,
return nullptr;
}
/**
* Get list of domain types but with ATTR_DOMAIN_FACE and
* ATTR_DOMAIN_CORNER swapped.
*/
static void get_domains_types(eAttrDomain domains[ATTR_DOMAIN_NUM])
{
for (const int i : IndexRange(ATTR_DOMAIN_NUM)) {
domains[i] = static_cast<eAttrDomain>(i);
}
/* Swap corner and face. */
std::swap(domains[ATTR_DOMAIN_FACE], domains[ATTR_DOMAIN_CORNER]);
}
int BKE_id_attribute_to_index(const ID *id,
const CustomDataLayer *layer,
eAttrDomainMask domain_mask,
@@ -831,21 +817,19 @@ int BKE_id_attribute_to_index(const ID *id,
}
DomainInfo info[ATTR_DOMAIN_NUM];
eAttrDomain domains[ATTR_DOMAIN_NUM];
get_domains_types(domains);
get_domains(id, info);
int index = 0;
for (int i = 0; i < ATTR_DOMAIN_NUM; i++) {
if (!(domain_mask & (1 << domains[i])) || !info[domains[i]].customdata) {
for (const int domain : IndexRange(ATTR_DOMAIN_NUM)) {
const CustomData *customdata = info[domain].customdata;
if (!customdata || !((1 << int(domain)) & domain_mask)) {
continue;
}
const CustomData *cdata = info[domains[i]].customdata;
for (int j = 0; j < cdata->totlayer; j++) {
const CustomDataLayer *layer_iter = cdata->layers + j;
if (!(CD_TYPE_AS_MASK(layer_iter->type) & layer_mask) ||
for (int i = 0; i < customdata->totlayer; i++) {
const CustomDataLayer *layer_iter = customdata->layers + i;
if (!(layer_mask & CD_TYPE_AS_MASK(layer_iter->type)) ||
(layer_iter->flag & CD_FLAG_TEMPORARY)) {
continue;
}

View File

@@ -3261,7 +3261,7 @@ void MESH_OT_colors_rotate(wmOperatorType *ot)
/* identifiers */
ot->name = "Rotate Colors";
ot->idname = "MESH_OT_colors_rotate";
ot->description = "Rotate color attributes inside faces";
ot->description = "Rotate face corner color attribute inside faces";
/* api callbacks */
ot->exec = edbm_rotate_colors_exec;
@@ -3279,7 +3279,7 @@ void MESH_OT_colors_reverse(wmOperatorType *ot)
/* identifiers */
ot->name = "Reverse Colors";
ot->idname = "MESH_OT_colors_reverse";
ot->description = "Flip direction of vertex colors inside faces";
ot->description = "Flip direction of face corner color attribute inside faces";
/* api callbacks */
ot->exec = edbm_reverse_colors_exec;