[Bf-blender-cvs] [8648d7145fd] temp-T96709-painting-target: Only show material attributes that are supported.

Jeroen Bakker noreply at git.blender.org
Wed Apr 6 10:50:43 CEST 2022


Commit: 8648d7145fd2bb008b7f69daebd5e466b7b6c456
Author: Jeroen Bakker
Date:   Wed Apr 6 10:27:20 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rB8648d7145fd2bb008b7f69daebd5e466b7b6c456

Only show material attributes that are supported.

===================================================================

M	source/blender/blenkernel/intern/material.c

===================================================================

diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 63dabb51c07..846dcda5f5f 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -43,6 +43,7 @@
 #include "BLT_translation.h"
 
 #include "BKE_anim_data.h"
+#include "BKE_attribute.h"
 #include "BKE_brush.h"
 #include "BKE_curve.h"
 #include "BKE_displist.h"
@@ -1400,6 +1401,7 @@ static int count_texture_nodes_recursive(bNodeTree *nodetree, ePaintSlotFilter s
 
 struct FillTexPaintSlotsData {
   bNode *active_node;
+  const Object *ob;
   Material *ma;
   int index;
   int slot_len;
@@ -1442,8 +1444,29 @@ static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
       TexPaintSlot *slot = &ma->texpaintslot[index];
       NodeShaderAttribute *storage = node->storage;
       slot->attribute_name = storage->name;
-      /* TODO(jbakker): check if attribute is a known color attribute for the active object... */
-      slot->valid = true;
+      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);
+        }
+        slot->valid = layer != NULL;
+      }
+
+      /* Do not show unsupported attributes. */
+      if (!slot->valid) {
+        slot->attribute_name = NULL;
+        fill_data->index--;
+      }
+
       break;
     }
   }
@@ -1453,11 +1476,12 @@ static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
 
 static void fill_texpaint_slots_recursive(bNodeTree *nodetree,
                                           bNode *active_node,
+                                          const Object *ob,
                                           Material *ma,
                                           int slot_len,
                                           ePaintSlotFilter slot_filter)
 {
-  struct FillTexPaintSlotsData fill_data = {active_node, ma, 0, slot_len};
+  struct FillTexPaintSlotsData fill_data = {active_node, ob, ma, 0, slot_len};
   ntree_foreach_texnode_recursive(nodetree, fill_texpaint_slots_cb, &fill_data, slot_filter);
 }
 
@@ -1518,7 +1542,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const struct Ob
 
   bNode *active_node = nodeGetActivePaintCanvas(ma->nodetree);
 
-  fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, count, slot_filter);
+  fill_texpaint_slots_recursive(ma->nodetree, active_node, ob, ma, count, slot_filter);
 
   ma->tot_slots = count;



More information about the Bf-blender-cvs mailing list