diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-11 14:44:14 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-11 16:34:13 +0300 |
commit | 403ae48063d91126bd36ca56920290bcb53f504e (patch) | |
tree | cbaa40f691f9c1a270ad1e33fffa9ee2a1d689f0 /source/blender/editors/space_image/image_edit.c | |
parent | b5349d967f1af433a9ee914aec72e028c3b2cd10 (diff) |
UV editor: automatically show image assigned to active face.
When manually selecting a different image, this image will become pinned and
continue to show. The material node is not automatically modified as it was in
old Blender versions, only the image displayed in the UV editor.
Fixes T61239: confusing behavior when unwrapping non-square images. By showing
the relevant image by default it's more clear why it does aspect correction.
Diffstat (limited to 'source/blender/editors/space_image/image_edit.c')
-rw-r--r-- | source/blender/editors/space_image/image_edit.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index 9a6f7431d17..c8edccb0472 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -57,9 +57,13 @@ Image *ED_space_image(SpaceImage *sima) return sima->image; } -/* called to assign images to UV faces */ -void ED_space_image_set(Main *bmain, SpaceImage *sima, Object *obedit, Image *ima) +void ED_space_image_set(Main *bmain, SpaceImage *sima, Object *obedit, Image *ima, bool automatic) { + /* Automatically pin image when manually assigned, otherwise it follows object. */ + if (!automatic && sima->image != ima && sima->mode == SI_MODE_UV) { + sima->pin = true; + } + /* change the space ima after because uvedit_face_visible_test uses the space ima * to check if the face is displayed in UV-localview */ sima->image = ima; @@ -81,6 +85,38 @@ void ED_space_image_set(Main *bmain, SpaceImage *sima, Object *obedit, Image *im WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL); } +void ED_space_image_auto_set(const bContext *C, SpaceImage *sima) +{ + if (sima->mode != SI_MODE_UV || sima->pin) { + return; + } + + /* Track image assigned to active face in edit mode. */ + Object *ob = CTX_data_active_object(C); + if (!(ob && (ob->mode & OB_MODE_EDIT) && ED_space_image_show_uvedit(sima, ob))) { + return; + } + + BMEditMesh *em = BKE_editmesh_from_object(ob); + BMesh *bm = em->bm; + BMFace *efa = BM_mesh_active_face_get(bm, true, false); + if (efa == NULL) { + return; + } + + Image *ima = NULL; + ED_object_get_active_image(ob, efa->mat_nr + 1, &ima, NULL, NULL, NULL); + + if (ima != sima->image) { + sima->image = ima; + + if (sima->image) { + Main *bmain = CTX_data_main(C); + BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE); + } + } +} + Mask *ED_space_image_get_mask(SpaceImage *sima) { return sima->mask_info.mask; |