diff options
author | Jeroen Bakker <jbakker> | 2022-04-08 17:37:35 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-04-08 17:42:50 +0300 |
commit | 8b7cd1ed2a17e40661101eea4adae99e8e3d02e9 (patch) | |
tree | 8c3f1f2a14d699fad0367ce529254f2efb517acf /source/blender/nodes/shader | |
parent | 63d2980efa2fb170b471e4905ec81cd1472e5268 (diff) |
Painting: Canvas switcher for painting brushes/tools.
This patch adds color attributes to TexPaintSlot. This allows an easier selection
when painting color attributes.
Previously when selecting a paint tool the user had to start a stroke, before the
UI reflected the correct TexPaintSlot. Now when switching the slot the active
tool is checked and immediate the UI is drawn correctly.
In the future the canvas selector will also be used to select an image or image texture node
to paint on. Basic implementation has already been done inside this patch.
A limitation of this patch is that is isn't possible anymore to rename images directly from
the selection panel. This is currently allowed in master. But as CustomDataLayers
aren't ID fields and not owned by the material supporting this wouldn't be easy.
{F12953989}
In the future we should update the create slot operator to also include color attributes.
Sources could also be extended to use other areas of the object that use image textures
(particles, geom nodes, etc... ).
Reviewed By: brecht
Maniphest Tasks: T96709
Differential Revision: https://developer.blender.org/D14455
Diffstat (limited to 'source/blender/nodes/shader')
-rw-r--r-- | source/blender/nodes/shader/node_shader_util.cc | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/source/blender/nodes/shader/node_shader_util.cc b/source/blender/nodes/shader/node_shader_util.cc index 16a4c5bae88..728e2760f9a 100644 --- a/source/blender/nodes/shader/node_shader_util.cc +++ b/source/blender/nodes/shader/node_shader_util.cc @@ -162,8 +162,21 @@ static void data_from_gpu_stack_list(ListBase *sockets, bNodeStack **ns, GPUNode } } -bNode *nodeGetActiveTexture(bNodeTree *ntree) +bool nodeSupportsActiveFlag(const bNode *node, int sub_activity) +{ + BLI_assert(ELEM(sub_activity, NODE_ACTIVE_TEXTURE, NODE_ACTIVE_PAINT_CANVAS)); + switch (sub_activity) { + case NODE_ACTIVE_TEXTURE: + return node->typeinfo->nclass == NODE_CLASS_TEXTURE; + case NODE_ACTIVE_PAINT_CANVAS: + return ELEM(node->type, SH_NODE_TEX_IMAGE, SH_NODE_ATTRIBUTE); + } + return false; +} + +static bNode *node_get_active(bNodeTree *ntree, int sub_activity) { + BLI_assert(ELEM(sub_activity, NODE_ACTIVE_TEXTURE, NODE_ACTIVE_PAINT_CANVAS)); /* this is the node we texture paint and draw in textured draw */ bNode *inactivenode = nullptr, *activetexnode = nullptr, *activegroup = nullptr; bool hasgroup = false; @@ -173,14 +186,14 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) } LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->flag & NODE_ACTIVE_TEXTURE) { + if (node->flag & sub_activity) { activetexnode = node; /* if active we can return immediately */ if (node->flag & NODE_ACTIVE) { return node; } } - else if (!inactivenode && node->typeinfo->nclass == NODE_CLASS_TEXTURE) { + else if (!inactivenode && nodeSupportsActiveFlag(node, sub_activity)) { inactivenode = node; } else if (node->type == NODE_GROUP) { @@ -195,7 +208,7 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) /* first, check active group for textures */ if (activegroup) { - bNode *tnode = nodeGetActiveTexture((bNodeTree *)activegroup->id); + bNode *tnode = node_get_active((bNodeTree *)activegroup->id, sub_activity); /* active node takes priority, so ignore any other possible nodes here */ if (tnode) { return tnode; @@ -210,8 +223,8 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) /* node active texture node in this tree, look inside groups */ LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { if (node->type == NODE_GROUP) { - bNode *tnode = nodeGetActiveTexture((bNodeTree *)node->id); - if (tnode && ((tnode->flag & NODE_ACTIVE_TEXTURE) || !inactivenode)) { + bNode *tnode = node_get_active((bNodeTree *)node->id, sub_activity); + if (tnode && ((tnode->flag & sub_activity) || !inactivenode)) { return tnode; } } @@ -221,6 +234,16 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) return inactivenode; } +bNode *nodeGetActiveTexture(bNodeTree *ntree) +{ + return node_get_active(ntree, NODE_ACTIVE_TEXTURE); +} + +bNode *nodeGetActivePaintCanvas(bNodeTree *ntree) +{ + return node_get_active(ntree, NODE_ACTIVE_PAINT_CANVAS); +} + void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node) { bNodeExec *nodeexec; |