Page MenuHome

TexturePaint -> Texture Slot can not be selected
Closed, ResolvedPublic

Description

System Information
Operating system: Windows

Blender Version
Broken:
(example: 2.80, rB1df6a98b176f, blender2.8, 2019-03-05)
Worked: (7d792976e100)

Short description of error
As soon as a Material uses node groups with ImageTexture Nodes, those image textures cannot be selected from the TextureSlot Dropdown.
Also please refer to my comment here:
https://developer.blender.org/rBda1323d1c95095feff98e8aa054d73fd323c363d#221015

Exact steps for others to reproduce the error
Create Suzanne. Go into Texture Paint Tab. Create two texture slots. -> selection works.
Open Shader Editor. Group those 2 textures into a new group. -> selection doesn't work.

Event Timeline

Philipp Oeser (lichtwerk) triaged this task as Confirmed, Medium priority.

Confirmed, checking...

Recent changes uncovered an old issue here. The active paint slot index depends on the order of nodes, while ED_node_sort changes that order based on selection and active state, to ensure selected and active nodes always draw on top.

could be wrong, but another thing [I think] is that the node is not actually set active when changing active_paint_slot_index (when inside a group)?, which is something the code seems to rely on
[patch below will let me select one of the slots inside the group... on the other hand this was working before @Brecht Van Lommel (brecht) 's commit, so might be utter nonsense, will check more tomorrow...]

1
2
3diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
4index ca0e58a0f5a..6d9d17ba935 100644
5--- a/source/blender/makesrna/intern/rna_material.c
6+++ b/source/blender/makesrna/intern/rna_material.c
7@@ -135,6 +135,20 @@ static void rna_Material_texpaint_begin(CollectionPropertyIterator *iter, Pointe
8 rna_iterator_array_begin(iter, (void *)ma->texpaintslot, sizeof(TexPaintSlot), ma->tot_slots, 0, NULL);
9 }
10
11+void set_node_active_recursive(bNodeTree *nodetree, Material *ma, int *index)
12+{
13+ for (bNode *node = nodetree->nodes.first; node; node = node->next) {
14+ if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
15+ if ((*index)++ == ma->paint_active_slot) {
16+ nodeSetActive(ma->nodetree, node);
17+ break;
18+ }
19+ }
20+ else if (node->type == NODE_GROUP) {
21+ set_node_active_recursive((bNodeTree *)node->id, ma, index);
22+ }
23+ }
24+}
25
26 static void rna_Material_active_paint_texture_index_update(Main *bmain, Scene *scene, PointerRNA *ptr)
27 {
28@@ -142,17 +156,8 @@ static void rna_Material_active_paint_texture_index_update(Main *bmain, Scene *s
29 Material *ma = ptr->id.data;
30
31 if (ma->use_nodes && ma->nodetree) {
32- struct bNode *node;
33 int index = 0;
34- for (node = ma->nodetree->nodes.first; node; node = node->next) {
35- if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
36- if (index++ == ma->paint_active_slot) {
37- break;
38- }
39- }
40- }
41- if (node)
42- nodeSetActive(ma->nodetree, node);
43+ set_node_active_recursive(ma->nodetree, ma, &index);
44 }
45
46 if (ma->texpaintslot) {

That indeed needs to be solved as well. The patch seems fine to commit to solve the most immediate problem.

It does not solve the entire issue but those bugs may go back to 2.7, I can look at that later with lower priority.