[Bf-blender-cvs] [da172ea0f68] temp-T96709-painting-target: Add attribute selection using material source.
Jeroen Bakker
noreply at git.blender.org
Wed Apr 6 10:50:43 CEST 2022
Commit: da172ea0f684ad7c04485f07391babdfd003e3b2
Author: Jeroen Bakker
Date: Wed Apr 6 10:43:17 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rBda172ea0f684ad7c04485f07391babdfd003e3b2
Add attribute selection using material source.
===================================================================
M source/blender/blenkernel/BKE_attribute.h
M source/blender/blenkernel/intern/attribute.c
M source/blender/blenkernel/intern/material.c
M source/blender/makesrna/intern/rna_material.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index f3968c0d761..bb5c65fad34 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -121,6 +121,7 @@ struct CustomDataLayer *BKE_id_attributes_active_color_get(const struct ID *id);
void BKE_id_attributes_active_color_set(struct ID *id, struct CustomDataLayer *active_layer);
struct CustomDataLayer *BKE_id_attributes_render_color_get(const struct ID *id);
void BKE_id_attributes_render_color_set(struct ID *id, struct CustomDataLayer *active_layer);
+struct CustomDataLayer *BKE_id_attributes_color_find(const struct ID *id, const char *name);
bool BKE_id_attribute_calc_unique_name(struct ID *id, const char *name, char *outname);
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 13c896fd1ab..5662ab35a37 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -615,6 +615,21 @@ void BKE_id_attributes_render_color_set(ID *id, CustomDataLayer *active_layer)
id, active_layer, CD_FLAG_COLOR_RENDER, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
}
+CustomDataLayer *BKE_id_attributes_color_find(const ID *id, const char *name)
+{
+ CustomDataLayer *layer = BKE_id_attribute_find(id, name, CD_PROP_COLOR, ATTR_DOMAIN_POINT);
+ if (layer == NULL) {
+ layer = BKE_id_attribute_find(id, name, CD_PROP_COLOR, ATTR_DOMAIN_CORNER);
+ }
+ if (layer == NULL) {
+ layer = BKE_id_attribute_find(id, name, CD_MLOOPCOL, ATTR_DOMAIN_POINT);
+ }
+ if (layer == NULL) {
+ layer = BKE_id_attribute_find(id, name, CD_MLOOPCOL, ATTR_DOMAIN_CORNER);
+ }
+ return layer;
+}
+
void BKE_id_attribute_copy_domains_temp(short id_type,
const CustomData *vdata,
const CustomData *edata,
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 846dcda5f5f..07f158d7787 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1446,18 +1446,7 @@ static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
slot->attribute_name = storage->name;
if (storage->type == SHD_ATTRIBUTE_GEOMETRY) {
const Mesh *mesh = (const Mesh *)fill_data->ob->data;
- CustomDataLayer *layer = BKE_id_attribute_find(
- &mesh->id, storage->name, CD_PROP_COLOR, ATTR_DOMAIN_POINT);
- if (layer == NULL) {
- layer = BKE_id_attribute_find(
- &mesh->id, storage->name, CD_PROP_COLOR, ATTR_DOMAIN_CORNER);
- }
- if (layer == NULL) {
- layer = BKE_id_attribute_find(&mesh->id, storage->name, CD_MLOOPCOL, ATTR_DOMAIN_POINT);
- }
- if (layer == NULL) {
- layer = BKE_id_attribute_find(&mesh->id, storage->name, CD_MLOOPCOL, ATTR_DOMAIN_CORNER);
- }
+ CustomDataLayer *layer = BKE_id_attributes_color_find(&mesh->id, storage->name);
slot->valid = layer != NULL;
}
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index 7cedf71b7e2..15e7e12bbf8 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -178,18 +178,14 @@ static void rna_Material_active_paint_texture_index_update(bContext *C, PointerR
}
}
- /* For compatibility reasons with sculpt vertex paint we make the color attribute active.
- * TODO(jbakker): In the future we should migrate vertex painting to use TexPaintSlots
- * directly.
- */
+ /* For compatibility reasons with vertex paint we activate the color attribute. */
if (slot->attribute_name) {
Object *ob = CTX_data_active_object(C);
if (ob != NULL && ob->type == OB_MESH) {
Mesh *mesh = ob->data;
- int layer = CustomData_get_named_layer_index(
- &mesh->vdata, CD_PROP_COLOR, slot->attribute_name);
- if (layer != -1) {
- CustomData_set_layer_active_index(&mesh->vdata, CD_PROP_COLOR, layer);
+ CustomDataLayer *layer = BKE_id_attributes_color_find(&mesh->id, slot->attribute_name);
+ if (layer != NULL) {
+ BKE_id_attributes_active_color_set(&mesh->id, layer);
}
DEG_id_tag_update(&ob->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, &ob->id);
More information about the Bf-blender-cvs
mailing list