[Bf-blender-cvs] [9a6dcc340bd] temp-T96709-painting-target: Use flag to update paint slots.
Jeroen Bakker
noreply at git.blender.org
Tue Mar 29 15:55:15 CEST 2022
Commit: 9a6dcc340bd269e105d51fb153def2cac2e17773
Author: Jeroen Bakker
Date: Tue Mar 29 15:55:06 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rB9a6dcc340bd269e105d51fb153def2cac2e17773
Use flag to update paint slots.
===================================================================
M source/blender/blenkernel/BKE_material.h
M source/blender/blenkernel/intern/material.c
M source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index de89d656c8c..080c54e4a1e 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -7,6 +7,7 @@
* \ingroup bke
* \brief General operations, lookup, etc. for materials.
*/
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -18,6 +19,12 @@ struct Object;
struct Scene;
struct bNode;
+/** Bitwise filter for updating paint slots. */
+typedef enum ePaintSlotFilter {
+ PAINT_SLOT_IMAGE = 1 << 0,
+ PAINT_SLOT_COLOR_ATTRIBUTE = 1 << 1,
+} ePaintSlotFilter;
+
/* -------------------------------------------------------------------- */
/** \name Module
* \{ */
@@ -106,7 +113,7 @@ struct MaterialGPencilStyle *BKE_gpencil_material_settings(struct Object *ob, sh
void BKE_texpaint_slot_refresh_cache(struct Scene *scene,
struct Material *ma,
- const bool do_color_attributes);
+ const struct Object *ob);
void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob);
struct bNode *BKE_texpaint_slot_material_find_node(struct Material *ma, short texpaint_slot);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index a956a94d1b9..ee3762e29bf 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1351,10 +1351,12 @@ typedef bool (*ForEachTexNodeCallback)(bNode *node, void *userdata);
static bool ntree_foreach_texnode_recursive(bNodeTree *nodetree,
ForEachTexNodeCallback callback,
void *userdata,
- const bool do_color_attributes)
+ ePaintSlotFilter slot_filter)
{
+ const bool do_image_nodes = (slot_filter & PAINT_SLOT_IMAGE) != 0;
+ const bool do_color_attributes = (slot_filter & PAINT_SLOT_COLOR_ATTRIBUTE) != 0;
LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) {
- if (node->typeinfo->nclass == NODE_CLASS_TEXTURE &&
+ if (do_image_nodes && node->typeinfo->nclass == NODE_CLASS_TEXTURE &&
node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
if (!callback(node, userdata)) {
return false;
@@ -1382,11 +1384,10 @@ static bool count_texture_nodes_cb(bNode *UNUSED(node), void *userdata)
return true;
}
-static int count_texture_nodes_recursive(bNodeTree *nodetree, const bool do_color_attributes)
+static int count_texture_nodes_recursive(bNodeTree *nodetree, ePaintSlotFilter slot_filter)
{
int tex_nodes = 0;
- ntree_foreach_texnode_recursive(
- nodetree, count_texture_nodes_cb, &tex_nodes, do_color_attributes);
+ ntree_foreach_texnode_recursive(nodetree, count_texture_nodes_cb, &tex_nodes, slot_filter);
return tex_nodes;
}
@@ -1448,14 +1449,28 @@ static void fill_texpaint_slots_recursive(bNodeTree *nodetree,
bNode *active_node,
Material *ma,
int slot_len,
- const bool do_color_attributes)
+ ePaintSlotFilter slot_filter)
{
struct FillTexPaintSlotsData fill_data = {active_node, ma, 0, slot_len};
- ntree_foreach_texnode_recursive(
- nodetree, fill_texpaint_slots_cb, &fill_data, do_color_attributes);
+ ntree_foreach_texnode_recursive(nodetree, fill_texpaint_slots_cb, &fill_data, slot_filter);
}
-void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const bool do_color_attributes)
+/** Check which type of paint slots should be filled for the given object. */
+static ePaintSlotFilter material_paint_slot_filter(const struct Object *ob)
+{
+ ePaintSlotFilter slot_filter = 0;
+ if (ob->mode == OB_MODE_SCULPT) {
+ SET_FLAG_FROM_TEST(
+ slot_filter, U.experimental.use_sculpt_vertex_colors, PAINT_SLOT_COLOR_ATTRIBUTE);
+ SET_FLAG_FROM_TEST(slot_filter, U.experimental.use_sculpt_texture_paint, PAINT_SLOT_IMAGE);
+ }
+ else if (ob->mode == OB_MODE_TEXTURE_PAINT) {
+ slot_filter = PAINT_SLOT_IMAGE;
+ }
+ return slot_filter;
+}
+
+void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const struct Object *ob)
{
int count = 0;
@@ -1463,6 +1478,8 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const bool do_c
return;
}
+ const ePaintSlotFilter slot_filter = material_paint_slot_filter(ob);
+
/* COW needed when adding texture slot on an object with no materials. */
DEG_id_tag_update(&ma->id, ID_RECALC_SHADING | ID_RECALC_COPY_ON_WRITE);
@@ -1484,7 +1501,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const bool do_c
return;
}
- count = count_texture_nodes_recursive(ma->nodetree, do_color_attributes);
+ count = count_texture_nodes_recursive(ma->nodetree, slot_filter);
if (count == 0) {
ma->paint_active_slot = 0;
@@ -1496,7 +1513,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const bool do_c
bNode *active_node = nodeGetActiveTexture(ma->nodetree);
- fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, count, do_color_attributes);
+ fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, count, slot_filter);
ma->tot_slots = count;
@@ -1511,11 +1528,9 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const bool do_c
void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob)
{
- const bool do_color_attributes = (ob->mode == OB_MODE_SCULPT) &&
- U.experimental.use_sculpt_vertex_colors;
for (int i = 1; i < ob->totcol + 1; i++) {
Material *ma = BKE_object_material_get(ob, i);
- BKE_texpaint_slot_refresh_cache(scene, ma, do_color_attributes);
+ BKE_texpaint_slot_refresh_cache(scene, ma, ob);
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 82e1a2f82a8..9d7f7c2fee6 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -6336,10 +6336,7 @@ bool ED_paint_proj_mesh_data_check(
hasmat = true;
if (ma->texpaintslot == NULL) {
/* refresh here just in case */
- const bool do_color_attributes = (ob->mode == OB_MODE_SCULPT) &&
- U.experimental.use_sculpt_vertex_colors;
-
- BKE_texpaint_slot_refresh_cache(scene, ma, do_color_attributes);
+ BKE_texpaint_slot_refresh_cache(scene, ma, ob);
}
if (ma->texpaintslot != NULL &&
(ma->texpaintslot[ma->paint_active_slot].ima == NULL ||
@@ -6609,7 +6606,7 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
nodePositionPropagate(out_node);
if (ima) {
- BKE_texpaint_slot_refresh_cache(scene, ma, false);
+ BKE_texpaint_slot_refresh_cache(scene, ma, ob);
BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE);
WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);
}
More information about the Bf-blender-cvs
mailing list