Texture Paint: sync changing active texture in the node editor to the

active paint slot

When changing to another texture paint slot, the texture displayed in
the viewport changes accordingly (as well as the image displayed
in the Image Editor).

When changing the active texture in the Node Editor though, only the
texture displayed in the viewport changes.

This _can_ be confusing because you can end up painting on a texture
that you are not looking at in the viewport (so you dont have any
feedback whatsoever). Not 100% sure this is desired in all scenarios,
but this change makes it so that the active paint slot changes to the
one that uses the texture we chaged to in the Node Editor (keeping them
in sync).

If this is not desired in all cases, this could be made an option.

ref T88788
ref D11496

Maniphest Tasks: T88788

Differential Revision: https://developer.blender.org/D11497
This commit is contained in:
Philipp Oeser 2021-06-04 10:24:01 +02:00
parent d8b445e728
commit 3b2a01edf6
Notes: blender-bot 2023-02-14 06:32:27 +01:00
Referenced by issue #88788, When selected a texture in the Properties panel shows another texture in the 3D Viewport.
1 changed files with 12 additions and 1 deletions

View File

@ -719,11 +719,22 @@ void ED_node_set_active(
ED_node_tag_update_nodetree(bmain, ntree, node);
}
/* if active texture changed, free glsl materials */
if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) {
/* If active texture changed, free glsl materials. */
LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
if (ma->nodetree && ma->use_nodes && ntreeHasTree(ma->nodetree, ntree)) {
GPU_material_free(&ma->gpumaterial);
/* Sync to active texpaint slot, otherwise we can end up painting on a different slot
* than we are looking at. */
if (ma->texpaintslot) {
Image *image = (Image *)node->id;
for (int i = 0; i < ma->tot_slots; i++) {
if (ma->texpaintslot[i].ima == image) {
ma->paint_active_slot = i;
}
}
}
}
}