[Bf-blender-cvs] [403ae48063d] master: UV editor: automatically show image assigned to active face.

Brecht Van Lommel noreply at git.blender.org
Mon Mar 11 14:35:07 CET 2019


Commit: 403ae48063d91126bd36ca56920290bcb53f504e
Author: Brecht Van Lommel
Date:   Mon Mar 11 12:44:14 2019 +0100
Branches: master
https://developer.blender.org/rB403ae48063d91126bd36ca56920290bcb53f504e

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.

===================================================================

M	source/blender/editors/include/ED_image.h
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/space_image/image_edit.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/makesrna/intern/rna_material.c
M	source/blender/makesrna/intern/rna_sculpt_paint.c
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h
index 240ed427479..bc5e21e4e08 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -37,7 +37,8 @@ struct wmWindowManager;
 
 /* image_edit.c, exported for transform */
 struct Image *ED_space_image(struct SpaceImage *sima);
-void          ED_space_image_set(struct Main *bmain, struct SpaceImage *sima, struct Object *obedit, struct Image *ima);
+void          ED_space_image_set(struct Main *bmain, struct SpaceImage *sima, struct Object *obedit, struct Image *ima, bool automatic);
+void          ED_space_image_auto_set(const struct bContext *C, struct SpaceImage *sima);
 struct Mask  *ED_space_image_get_mask(struct SpaceImage *sima);
 void          ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask);
 
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 4749d2a3308..9101f65dc05 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1122,7 +1122,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
 
 							if (!sima->pin) {
 								Object *obedit = CTX_data_edit_object(C);
-								ED_space_image_set(bmain, sima, obedit, ima);
+								ED_space_image_set(bmain, sima, obedit, ima, true);
 							}
 						}
 					}
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;
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 064a4d2ce11..bba336ca2e0 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1300,7 +1300,7 @@ static int image_open_exec(bContext *C, wmOperator *op)
 	}
 	else if (sa && sa->spacetype == SPACE_IMAGE) {
 		SpaceImage *sima = sa->spacedata.first;
-		ED_space_image_set(bmain, sima, obedit, ima);
+		ED_space_image_set(bmain, sima, obedit, ima, false);
 		iuser = &sima->iuser;
 	}
 	else {
@@ -2461,7 +2461,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
 		RNA_property_update(C, &data->pprop.ptr, data->pprop.prop);
 	}
 	else if (sima) {
-		ED_space_image_set(bmain, sima, obedit, ima);
+		ED_space_image_set(bmain, sima, obedit, ima, false);
 	}
 
 	BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_USER_NEW_IMAGE);
@@ -3800,7 +3800,7 @@ static int image_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op))
 
 	ima = BKE_image_verify_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
 	if (sima->image == NULL) {
-		ED_space_image_set(bmain, sima, NULL, ima);
+		ED_space_image_set(bmain, sima, NULL, ima, false);
 	}
 
 	RE_ReadRenderResult(scene, scene);
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index 6ae4eb9767b..7aa3ea57956 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -100,15 +100,19 @@ static void image_scopes_tag_refresh(ScrArea *sa)
 
 static void image_user_refresh_scene(const bContext *C, SpaceImage *sima)
 {
+	/* Update scene image user for acquiring render results. */
+	sima->iuser.scene = CTX_data_scene(C);
+
 	if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) {
-		/* for render result, try to use the currently rendering scene */
+		/* While rendering, prefer scene that is being rendered. */
 		Scene *render_scene = ED_render_job_get_current_scene(C);
 		if (render_scene) {
 			sima->iuser.scene = render_scene;
-			return;
 		}
 	}
-	sima->iuser.scene = CTX_data_scene(C);
+
+	/* Auto switch image to show in UV editor when selection changes. */
+	ED_space_image_auto_set(C, sima);
 }
 
 /* ******************** manage regions ********************* */
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index 4c400b4fb2e..90c46c8b03d 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -176,7 +176,7 @@ static void rna_Material_active_paint_texture_index_update(Main *bmain, Scene *U
 					if (sl->spacetype == SPACE_IMAGE) {
 						SpaceImage *sima = (SpaceImage *)sl;
 						if (!sima->pin) {
-							ED_space_image_set(bmain, sima, obedit, image);
+							ED_space_image_set(bmain, sima, obedit, image, true);
 						}
 					}
 				}
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index f372180dd3b..d1fdd222d79 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -490,7 +490,7 @@ static void rna_ImaPaint_canvas_update(bContext *C, PointerRNA *UNUSED(ptr))
 					SpaceImage *sima = (SpaceImage *)slink;
 
 					if (!sima->pin)
-						ED_space_image_set(bmain, sima, obedit, ima);
+						ED_space_image_set(bmain, sima, obedit, ima, true);
 				}
 			}
 		}
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 0592a524b76..d6c78fd687a 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1036,7 +1036,7 @@ static void rna_SpaceImageEditor_image_set(PointerRNA *ptr, PointerRNA value)
 	Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
 
 	BLI_assert(BKE_id_is_in_global_main(value.data));
-	ED_space_image_set(G_MAIN, sima, obedit, (Image *)value.data);
+	ED_space_image_set(G_MAIN, sima, obedit, (Image *)value.data, false);
 }
 
 static void rna_SpaceImageEditor_mask_set(PointerRNA *ptr, PointerRNA value)



More information about the Bf-blender-cvs mailing list