[Bf-blender-cvs] [d011ae1e038] master: Fix T59972: UV live unwrap does not pack islands.

Brecht Van Lommel noreply at git.blender.org
Thu Jan 24 15:02:26 CET 2019


Commit: d011ae1e0389c6262acdcc2e14122e913cf226c7
Author: Brecht Van Lommel
Date:   Thu Jan 24 12:14:24 2019 +0100
Branches: master
https://developer.blender.org/rBd011ae1e0389c6262acdcc2e14122e913cf226c7

Fix T59972: UV live unwrap does not pack islands.

Packing was not being called after multi-object editing changes. Includes code
refactoring to make function parameters more clear.

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

M	source/blender/editors/include/ED_uvedit.h
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c

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

diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h
index 3cc285a53de..b17fea2b299 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -127,12 +127,9 @@ void ED_uvedit_live_unwrap_begin(struct Scene *scene, struct Object *obedit);
 void ED_uvedit_live_unwrap_re_solve(void);
 void ED_uvedit_live_unwrap_end(short cancel);
 
-void ED_uvedit_live_unwrap(struct Scene *scene, struct Object *obedit);
+void ED_uvedit_live_unwrap(struct Scene *scene, struct Object **objects, int objects_len);
 void ED_uvedit_add_simple_uvs(struct Main *bmain, struct Scene *scene, struct Object *ob);
 
-/* single call up unwrap using scene settings, used for edge tag unwrapping */
-void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel, const bool pack);
-
 
 /* uvedit_draw.c */
 void ED_image_draw_cursor(
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index b8dd46f3cc3..af227ff0eb9 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -1006,10 +1006,16 @@ static int edbm_mark_seam_exec(bContext *C, wmOperator *op)
 				BM_elem_flag_enable(eed, BM_ELEM_SEAM);
 			}
 		}
+	}
+
+	ED_uvedit_live_unwrap(scene, objects, objects_len);
 
-		ED_uvedit_live_unwrap(scene, obedit);
+	for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+		Object *obedit = objects[ob_index];
+		BMEditMesh *em = BKE_editmesh_from_object(obedit);
 		EDBM_update_generic(em, true, false);
 	}
+
 	MEM_freeN(objects);
 
 	return OPERATOR_FINISHED;
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index bb56f9f18b0..0a9677834e8 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -4568,6 +4568,8 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op)
 	uint objects_len = 0;
 	Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, ((View3D *)NULL), &objects_len);
 
+	bool changed = false;
+
 	for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
 		Object *ob = objects[ob_index];
 		Mesh *me = (Mesh *)ob->data;
@@ -4580,8 +4582,6 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op)
 
 		const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
 
-		bool changed = false;
-
 		BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 			BM_ITER_ELEM (loop, &liter, efa, BM_LOOPS_OF_FACE) {
 				if (uvedit_edge_select_test(scene, loop, cd_loop_uv_offset)) {
@@ -4592,14 +4592,15 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op)
 		}
 
 		if (changed) {
-			if (scene->toolsettings->edge_mode_live_unwrap) {
-				ED_unwrap_lscm(scene, ob, false, false);
-			}
-
 			DEG_id_tag_update(&me->id, 0);
 			WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
 		}
 	}
+
+	if (changed) {
+		ED_uvedit_live_unwrap(scene, objects, objects_len);
+	}
+
 	MEM_freeN(objects);
 
 	return OPERATOR_FINISHED;
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 93ba2f62029..9316065a230 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -164,7 +164,14 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *UNUSED(scene), Object *obed
 
 /****************** Parametrizer Conversion ***************/
 
-static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, bool implicit)
+typedef struct UnwrapOptions {
+	bool topology_from_uvs; /* Connectivity based on UV coordinates instead of seams. */
+	bool only_selected;     /* Only affect selected faces. */
+	bool fill_holes;        /* Fill holes to better preserve shape. */
+	bool correct_aspect;    /* Correct for mapped image texture aspect ratio. */
+} UnwrapOptions;
+
+static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, const UnwrapOptions *options)
 {
 	BMFace *efa;
 	BMLoop *l;
@@ -190,7 +197,7 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, bool implicit)
 				break;
 		}
 
-		if (implicit && !l)
+		if (options->topology_from_uvs && !l)
 			continue;
 
 		return true;
@@ -200,13 +207,14 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, bool implicit)
 }
 
 static bool uvedit_have_selection_multi(
-        Scene *scene, Object **objects, const uint objects_len, bool implicit)
+        Scene *scene, Object **objects, const uint objects_len,
+        const UnwrapOptions *options)
 {
 	bool have_select = false;
 	for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
 		Object *obedit = objects[ob_index];
 		BMEditMesh *em = BKE_editmesh_from_object(obedit);
-		if (uvedit_have_selection(scene, em, implicit)) {
+		if (uvedit_have_selection(scene, em, options)) {
 			have_select = true;
 			break;
 		}
@@ -268,8 +276,7 @@ static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene,
 /* See: construct_param_handle_multi to handle multiple objects at once. */
 static ParamHandle *construct_param_handle(
         Scene *scene, Object *ob, BMesh *bm,
-        const bool implicit, const bool fill, const bool sel,
-        const bool correct_aspect)
+        const UnwrapOptions *options)
 {
 	ParamHandle *handle;
 	BMFace *efa;
@@ -282,7 +289,7 @@ static ParamHandle *construct_param_handle(
 
 	handle = param_construct_begin();
 
-	if (correct_aspect) {
+	if (options->correct_aspect) {
 		float aspx, aspy;
 
 		ED_uvedit_get_aspect(scene, ob, bm, &aspx, &aspy);
@@ -296,11 +303,13 @@ static ParamHandle *construct_param_handle(
 
 	BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
 
-		if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) || (sel && BM_elem_flag_test(efa, BM_ELEM_SELECT) == 0)) {
+		if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) ||
+		    (options->only_selected && BM_elem_flag_test(efa, BM_ELEM_SELECT) == 0))
+		{
 			continue;
 		}
 
-		if (implicit) {
+		if (options->topology_from_uvs) {
 			bool is_loopsel = false;
 
 			BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -317,7 +326,7 @@ static ParamHandle *construct_param_handle(
 		construct_param_handle_face_add(handle, scene, efa, i, cd_loop_uv_offset);
 	}
 
-	if (!implicit) {
+	if (!options->topology_from_uvs) {
 		BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
 			if (BM_elem_flag_test(eed, BM_ELEM_SEAM)) {
 				ParamKey vkeys[2];
@@ -328,7 +337,7 @@ static ParamHandle *construct_param_handle(
 		}
 	}
 
-	param_construct_end(handle, fill, implicit);
+	param_construct_end(handle, options->fill_holes, options->topology_from_uvs);
 
 	return handle;
 }
@@ -338,8 +347,7 @@ static ParamHandle *construct_param_handle(
  */
 static ParamHandle *construct_param_handle_multi(
         Scene *scene, Object **objects, const uint objects_len,
-        const bool implicit, const bool fill, const bool sel,
-        const bool correct_aspect)
+        const UnwrapOptions *options)
 {
 	ParamHandle *handle;
 	BMFace *efa;
@@ -348,10 +356,9 @@ static ParamHandle *construct_param_handle_multi(
 	BMIter iter, liter;
 	int i;
 
-
 	handle = param_construct_begin();
 
-	if (correct_aspect) {
+	if (options->correct_aspect) {
 		Object *ob = objects[0];
 		BMEditMesh *em = BKE_editmesh_from_object(ob);
 		BMesh *bm = em->bm;
@@ -377,11 +384,13 @@ static ParamHandle *construct_param_handle_multi(
 
 		BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
 
-			if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) || (sel && BM_elem_flag_test(efa, BM_ELEM_SELECT) == 0)) {
+			if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) ||
+			    (options->only_selected && BM_elem_flag_test(efa, BM_ELEM_SELECT) == 0))
+			{
 				continue;
 			}
 
-			if (implicit) {
+			if (options->topology_from_uvs) {
 				bool is_loopsel = false;
 
 				BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -398,7 +407,7 @@ static ParamHandle *construct_param_handle_multi(
 			construct_param_handle_face_add(handle, scene, efa, i + offset, cd_loop_uv_offset);
 		}
 
-		if (!implicit) {
+		if (!options->topology_from_uvs) {
 			BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
 				if (BM_elem_flag_test(eed, BM_ELEM_SEAM)) {
 					ParamKey vkeys[2];
@@ -411,7 +420,7 @@ static ParamHandle *construct_param_handle_multi(
 		offset += bm->totface;
 	}
 
-	param_construct_end(handle, fill, implicit);
+	param_construct_end(handle, options->fill_holes, options->topology_from_uvs);
 
 	return handle;
 }
@@ -444,7 +453,7 @@ static void texface_from_original_index(BMFace *efa, int index, float **uv, Para
 
 /* unwrap handle initialization for subsurf aware-unwrapper. The many modifications required to make the original function(see above)
  * work justified the existence of a new function. */
-static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, BMEditMesh *em, short fill, short sel, short correct_aspect)
+static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, BMEditMesh *em, const UnwrapOptions *options)
 {
 	ParamHandle *handle;
 	/* index pointers */
@@ -480,7 +489,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
 
 	handle = param_construct_begin();
 
-	if (correct_aspect) {
+	if (options->correct_aspect) {
 		float aspx, aspy;
 
 		ED_uvedit_get_aspect(scene, ob, em->bm, &aspx, &aspy);
@@ -546,8 +555,11 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
 				continue;
 		}
 		else {
-			if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN) || (sel && !BM_elem_flag_test(origFace, BM_ELEM_SELECT)))
+			if (BM_elem_flag_test(origFace, BM_ELEM_HIDDEN) ||
+			    (options->only_selected && !BM_elem_flag_test(origFace, BM_ELEM_SELECT)))
+			{
 				continue;
+			}
 		}
 
 		mloop = &subsurfedLoops[mpoly->loopstart];
@@ -585,7 +597,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
 		}
 	}
 
-	param_construct_end(handle, fill, 0);
+	param_construct_end(handle, options->fill_holes, options->topology_from_uvs);
 
 	/* cleanup */
 	MEM_freeN(faceMap);
@@ -613,26 +625,29 @@ static bool minimize_stretch

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list