Texture Paint: sync adding a new texture slot to the Image Editor
When changing the texture paint slot index or activating a Texture Node, the texture displayed in the Image Editor changes accordingly. This patch syncs the Image Editor when a new texture paint slot was added, which currently is not the case. Also deduplicates some code.
This commit is contained in:
parent
77c4d3154b
commit
1d71f82033
|
@ -51,6 +51,7 @@ void ED_space_image_set(struct Main *bmain,
|
|||
struct SpaceImage *sima,
|
||||
struct Image *ima,
|
||||
bool automatic);
|
||||
void ED_space_image_sync(struct Main *bmain, Image *image, bool ignore_render_viewer);
|
||||
void ED_space_image_auto_set(const struct bContext *C, struct SpaceImage *sima);
|
||||
struct Mask *ED_space_image_get_mask(const struct SpaceImage *sima);
|
||||
void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask);
|
||||
|
|
|
@ -780,20 +780,7 @@ void ED_object_texture_paint_mode_enter_ex(Main *bmain, Scene *scene, Object *ob
|
|||
}
|
||||
|
||||
if (ima) {
|
||||
wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
|
||||
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
||||
const bScreen *screen = WM_window_get_active_screen(win);
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
SpaceLink *sl = static_cast<SpaceLink *>(area->spacedata.first);
|
||||
if (sl->spacetype == SPACE_IMAGE) {
|
||||
SpaceImage *sima = (SpaceImage *)sl;
|
||||
|
||||
if (!sima->pin) {
|
||||
ED_space_image_set(bmain, sima, ima, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ED_space_image_sync(bmain, ima, false);
|
||||
}
|
||||
|
||||
ob->mode |= OB_MODE_TEXTURE_PAINT;
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
#include "DEG_depsgraph.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "ED_image.h"
|
||||
#include "ED_node.h"
|
||||
#include "ED_object.h"
|
||||
#include "ED_paint.h"
|
||||
|
@ -6704,6 +6705,7 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
|
|||
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);
|
||||
ED_space_image_sync(bmain, ima, false);
|
||||
}
|
||||
if (layer) {
|
||||
BKE_texpaint_slot_refresh_cache(scene, ma, ob);
|
||||
|
|
|
@ -67,6 +67,30 @@ void ED_space_image_set(Main *bmain, SpaceImage *sima, Image *ima, bool automati
|
|||
WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL);
|
||||
}
|
||||
|
||||
void ED_space_image_sync(struct Main *bmain, struct Image *image, bool ignore_render_viewer)
|
||||
{
|
||||
wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
|
||||
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
||||
const bScreen *screen = WM_window_get_active_screen(win);
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
||||
if (sl->spacetype != SPACE_IMAGE) {
|
||||
continue;
|
||||
}
|
||||
SpaceImage *sima = (SpaceImage *)sl;
|
||||
if (sima->pin) {
|
||||
continue;
|
||||
}
|
||||
if (ignore_render_viewer && sima->image &&
|
||||
ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
|
||||
continue;
|
||||
}
|
||||
ED_space_image_set(bmain, sima, image, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ED_space_image_auto_set(const bContext *C, SpaceImage *sima)
|
||||
{
|
||||
if (sima->mode != SI_MODE_UV || sima->pin) {
|
||||
|
|
|
@ -737,26 +737,7 @@ void ED_node_set_active(
|
|||
* - current image is not a Render Result or ViewerNode (want to keep looking at these) */
|
||||
if (node->id != nullptr && GS(node->id->name) == ID_IM) {
|
||||
Image *image = (Image *)node->id;
|
||||
wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
|
||||
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
||||
const bScreen *screen = WM_window_get_active_screen(win);
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
||||
if (sl->spacetype != SPACE_IMAGE) {
|
||||
continue;
|
||||
}
|
||||
SpaceImage *sima = (SpaceImage *)sl;
|
||||
if (sima->pin) {
|
||||
continue;
|
||||
}
|
||||
if (sima->image &&
|
||||
ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
|
||||
continue;
|
||||
}
|
||||
ED_space_image_set(bmain, sima, image, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
ED_space_image_sync(bmain, image, true);
|
||||
}
|
||||
|
||||
if (r_active_texture_changed) {
|
||||
|
|
|
@ -142,7 +142,6 @@ static void rna_Material_texpaint_begin(CollectionPropertyIterator *iter, Pointe
|
|||
static void rna_Material_active_paint_texture_index_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
bScreen *screen;
|
||||
Material *ma = (Material *)ptr->owner_id;
|
||||
|
||||
if (ma->use_nodes && ma->nodetree) {
|
||||
|
@ -157,25 +156,7 @@ static void rna_Material_active_paint_texture_index_update(bContext *C, PointerR
|
|||
TexPaintSlot *slot = &ma->texpaintslot[ma->paint_active_slot];
|
||||
Image *image = slot->ima;
|
||||
if (image) {
|
||||
for (screen = bmain->screens.first; screen; screen = screen->id.next) {
|
||||
wmWindow *win = ED_screen_window_find(screen, bmain->wm.first);
|
||||
if (win == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ScrArea *area;
|
||||
for (area = screen->areabase.first; area; area = area->next) {
|
||||
SpaceLink *sl;
|
||||
for (sl = area->spacedata.first; sl; sl = sl->next) {
|
||||
if (sl->spacetype == SPACE_IMAGE) {
|
||||
SpaceImage *sima = (SpaceImage *)sl;
|
||||
if (!sima->pin) {
|
||||
ED_space_image_set(bmain, sima, image, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ED_space_image_sync(bmain, image, false);
|
||||
}
|
||||
|
||||
/* For compatibility reasons with vertex paint we activate the color attribute. */
|
||||
|
|
|
@ -537,24 +537,9 @@ static void rna_ImaPaint_canvas_update(bContext *C, PointerRNA *UNUSED(ptr))
|
|||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
BKE_view_layer_synced_ensure(scene, view_layer);
|
||||
Object *ob = BKE_view_layer_active_object_get(view_layer);
|
||||
bScreen *screen;
|
||||
Image *ima = scene->toolsettings->imapaint.canvas;
|
||||
|
||||
for (screen = bmain->screens.first; screen; screen = screen->id.next) {
|
||||
ScrArea *area;
|
||||
for (area = screen->areabase.first; area; area = area->next) {
|
||||
SpaceLink *slink;
|
||||
for (slink = area->spacedata.first; slink; slink = slink->next) {
|
||||
if (slink->spacetype == SPACE_IMAGE) {
|
||||
SpaceImage *sima = (SpaceImage *)slink;
|
||||
|
||||
if (!sima->pin) {
|
||||
ED_space_image_set(bmain, sima, ima, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ED_space_image_sync(bmain, ima, false);
|
||||
|
||||
if (ob && ob->type == OB_MESH) {
|
||||
ED_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
|
||||
|
|
Loading…
Reference in New Issue