[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58889] branches/ soc-2013-meshdata_transfer/source/blender: UV transfer Operator: Managing UV layers for transfer and fixing initializations related to Multiple layers transfer

Walid Shouman eng.walidshouman at gmail.com
Sun Aug 4 05:26:38 CEST 2013


Revision: 58889
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58889
Author:   walid
Date:     2013-08-04 03:26:38 +0000 (Sun, 04 Aug 2013)
Log Message:
-----------
UV transfer Operator: Managing UV layers for transfer and fixing initializations related to Multiple layers transfer

Modified Paths:
--------------
    branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
    branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
    branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c

Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-08-04 03:02:35 UTC (rev 58888)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c	2013-08-04 03:26:38 UTC (rev 58889)
@@ -1339,7 +1339,7 @@
 
 bool BM_mesh_uv_copy2(BMesh *bm_src, BMesh *bm_dst, float UNUSED(tolerance), float UNUSED(radius_interp),
                             int UNUSED(dist_pow), int UNUSED(no_pow), bool UNUSED(USE_NORMALS),
-                            ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay, float tmp_mat[4][4])
+                            ReplaceGroupMode replace_mode, int *UNUSED(act_shapekey_lay), float tmp_mat[4][4])
 {
 	//-----uv dependent variables
 	BMLoop *l, *l2;						//used for iterating the destination's loops
@@ -1606,7 +1606,7 @@
 	}
 
 	tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * exp_vert_per_face, "tmp_weight bmesh_data_transfer.c");
-	if (replace_mode == ST_APPEND_SHAPEKEY_GROUPS) {
+	if (replace_mode == APPEND_GROUPS) {
 		//add 1 to skip the basis
 		src_lay_start = 0;
 		src_lay_end = tot_layer_src;
@@ -1614,19 +1614,18 @@
 		dst_lay_end = tot_layer_dst;
 	}
 
-	else if ((replace_mode == ST_REPLACE_ENOUGH_SHAPEKEY_GROUPS) || (replace_mode == ST_REPLACE_ALL_SHAPEKEY_GROUPS)) {
+	else if ((replace_mode == REPLACE_ENOUGH_GROUPS) || (replace_mode == REPLACE_ALL_GROUPS)) {
 		src_lay_start = 0;
 		src_lay_end = tot_layer_src;
 		dst_lay_start = 0;
 		dst_lay_end = tot_layer_src;
 	}
 
-	else if (replace_mode == ST_REPLACE_ACTIVE_SHAPEKEY_GROUP) {
-		//passed shapekey reperesents the # of shapekeys (starts from one), however lay_start uses it as an index
-		src_lay_start = act_shapekey_lay[0] - 1;
-		src_lay_end = act_shapekey_lay[0];
-		dst_lay_start = act_shapekey_lay[1] - 1;
-		dst_lay_end = act_shapekey_lay[1];
+	else if (replace_mode == REPLACE_ACTIVE_GROUP) {
+		src_lay_start = CustomData_get_active_layer_index(&bm_src->ldata, CD_MLOOPUV);
+		src_lay_end = src_lay_start + 1;	//stopping condition
+		dst_lay_start = CustomData_get_active_layer_index(&bm_dst->ldata, CD_MLOOPUV);
+		dst_lay_end = dst_lay_start + 1;
 	}
 
 	for (src_lay_iter = src_lay_start, dst_lay_iter = dst_lay_start; src_lay_iter < src_lay_end;
@@ -1668,6 +1667,7 @@
 			if (fl_table[f_src->head.index].f == NULL) {	//if the face source reperesnts a new entry
 				f_src_table[f_src_count] = f_src;
 				f_src_count++;
+				fl_table[f_src->head.index].count = 0;	//this init to take into account coming from another layer
 
 				if (f_dst->len > exp_dst_loops_per_src_face)
 				{
@@ -1684,7 +1684,7 @@
 			}
 
 			fl_table[f_src->head.index].f = f_src;
-			fl_table[f_src->head.index].count += f_dst->len;	//we need count to be init with zero (calloc) in adv
+			fl_table[f_src->head.index].count += f_dst->len;
 
 			//get a coordinate list of the f verts
 			BM_ITER_ELEM_INDEX (v2, &iter2, f_src, BM_VERTS_OF_FACE, v_src_count) {
@@ -1861,9 +1861,14 @@
 			//copy the value to each of them
 			for (i = 0; i < l_grp[h].count; i++) {
 				//commenting this would leave us with the output of interpolation for each face ^_^
-				copy_v2_v2(BM_ELEM_CD_GET_VOID_P(l_grp[h].l[i], CD_dst),mid_uv);
+				copy_v2_v2(BM_ELEM_CD_GET_VOID_P(l_grp[h].l[i], CD_dst), mid_uv);
 			}
 		}
+
+		//reset the faces for the next addition to the fl_table
+		BM_ITER_MESH_INDEX (f_src, &iter, bm_src, BM_FACES_OF_MESH, b) {
+			fl_table[b].f = NULL;
+		}
 	}
 
 	BM_ITER_MESH_INDEX (f_src, &iter, bm_src, BM_FACES_OF_MESH, b) {

Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h	2013-08-04 03:02:35 UTC (rev 58888)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h	2013-08-04 03:26:38 UTC (rev 58889)
@@ -34,6 +34,13 @@
 	ST_APPEND_SHAPEKEY_GROUPS = 4
 } ST_ShapekeyGroupMode;
 
+typedef enum ReplaceGroupMode {
+	REPLACE_ACTIVE_GROUP = 1,
+	REPLACE_ENOUGH_GROUPS = 2,
+	REPLACE_ALL_GROUPS = 3,
+	APPEND_GROUPS = 4
+} ReplaceGroupMode;
+
 bool BKE_bmesh_calc_relative_deform(const int v_count, const float (*vert_cos_src)[], const float (*vert_cos_dst)[],
 									const float (*vert_cos_org)[],	float (*vert_cos_new)[]);
 bool BM_edge_has_consistant_loops(BMEdge *e, int CD_offset);
@@ -44,7 +51,7 @@
 
 bool BM_mesh_uv_copy2(BMesh *bm_src, BMesh *bm_dst, float UNUSED(tolerance), float UNUSED(radius_interp),
                             int UNUSED(dist_pow), int UNUSED(no_pow), bool UNUSED(USE_NORMALS),
-                            ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay, float tmp_mat[4][4]);
+                            ReplaceGroupMode replace_mode, int *UNUSED_act_shapekey_lay, float tmp_mat[4][4]);
 
 bool BM_mesh_shapekey_copy(BMesh *bm_src, BMesh *bm_dst, float tolerance, float radius_interp,
                            int interp_pow, int no_pow, bool USE_NORMALS, ST_ShapekeyGroupMode replace_mode,

Modified: branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c	2013-08-04 03:02:35 UTC (rev 58888)
+++ branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c	2013-08-04 03:26:38 UTC (rev 58889)
@@ -466,19 +466,31 @@
 	}
 }
 
-typedef enum UT_UVTransferMode {
-	UT_USE_NEAREST_VERTEX = 1,
-	UT_USE_NEAREST_FACE = 2
-} UT_UVTransferMode;
+typedef enum TransferMode {
+	SPATIAL_TRANSFER = 1,
+	PROJECTION_TRANSFER = 2
+} TransferMode;
 
-static EnumPropertyItem UT_transfer_mode_item[] = {
-    {UT_USE_NEAREST_VERTEX,
-	 "UT_USE_NEAREST_VERTEX", 0, "Nearest vertex", "Copy from the nearest vertices"},
-    {UT_USE_NEAREST_FACE,
-	 "UT_USE_NEAREST_FACE", 0, "Nearest face", "Copy from the nearest face"},
+static EnumPropertyItem transfer_mode_item[] = {
+    {SPATIAL_TRANSFER,
+	 "SPATIAL_TRANSFER", 0, "Spatial transfer", "Copy by analyzing the spatial relations"},
+    {PROJECTION_TRANSFER,
+	 "PROJECTION_TRANSFER", 0, "Projection transfer", "Copy by projecting the desitnation onto the source"},
     {0, NULL, 0, NULL, NULL}
 };
 
+static EnumPropertyItem replace_mode_item[] = {
+    {REPLACE_ACTIVE_GROUP,
+	 "REPLACE_ACTIVE_GROUP", 0, "Active", "Overwrite active group only"},
+    {REPLACE_ENOUGH_GROUPS,
+	 "REPLACE_ENOUGH_GROUPS", 0, "Enough", "Overwrite source groups only as needed"},
+    {REPLACE_ALL_GROUPS,
+	 "REPLACE_ALL_GROUPS", 0, "All", "Overwrite all groups"},
+    {APPEND_GROUPS,
+	 "APPEND_GROUPS", 0, "Append", "Add groups without overwriting"},
+	{0, NULL, 0, NULL, NULL}
+};
+
 static bool ED_mesh_uv_transfer(Object *ob_dst, Object *ob_src, bContext *UNUSED(C), Scene *UNUSED(scene), wmOperator * op)
 {
 	Mesh *me_dst, *me_src;
@@ -489,7 +501,8 @@
 	int interp_pow = RNA_int_get(op->ptr, "interp_power");
 	bool interp_normals = RNA_boolean_get(op->ptr, "interp_normals");
 	int no_pow = RNA_int_get(op->ptr, "normals_power");
-	UT_UVTransferMode transfer_mode = RNA_enum_get(op->ptr, "transfer_mode");
+	ReplaceGroupMode replace_mode = RNA_enum_get(op->ptr, "replace_mode");
+	TransferMode transfer_mode = RNA_enum_get(op->ptr, "transfer_mode");
 
 	int num_src_lay, num_dst_lay;
 
@@ -497,6 +510,10 @@
 
 	float tmp_mat[4][4];
 
+	int CD_src;
+	int active_dst, active_src;
+	char *src_name;
+
 	invert_m4_m4(ob_src->imat, ob_src->obmat);
 	mul_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
 
@@ -509,15 +526,87 @@
 
 	if (num_src_lay < 1) {
 		//the source should have UV layers
+		BKE_report(op->reports, RPT_ERROR,
+		           "Transfer failed no UV groups were found (source mesh should have -at least- UV group)");
+
 		return false;
 	}
 
-	//adding enough layers
-	for(i = 0; i < (num_src_lay - num_dst_lay); i++)
+	if (replace_mode == REPLACE_ENOUGH_GROUPS) {
+
+		//add layers as needed
+		i = num_src_lay - num_dst_lay;
+		while (i > 0) {
+			ED_mesh_uv_texture_add(me_dst, NULL, true);
+			i--;
+		}
+		CD_src = CustomData_get_layer_index(&me_src->pdata, CD_MTEXPOLY);
+		//copy the names
+		for (i = 0; i < num_src_lay; ++i) {
+
+			src_name = me_src->pdata.layers[CD_src + i].name;
+			CustomData_set_layer_name(&me_dst->ldata, CD_MLOOPUV, i, src_name);
+			CustomData_set_layer_name(&me_dst->pdata, CD_MTEXPOLY, i, src_name);
+//			CustomData_set_layer_name(&me_dst->fdata, CD_MFACE, i, src_name);	//could that be of any need?
+		}
+	}
+
+	//we'll tell the copy function to start copying from # of source layers from the end of the dst layers
+	else if (replace_mode == APPEND_GROUPS)
 	{
-		ED_mesh_uv_texture_add(me_dst, NULL, true);
+		CD_src = CustomData_get_layer_index(&me_src->pdata, CD_MTEXPOLY);
+		for (i = 0; i < num_src_lay; ++i) {
+
+			src_name = me_src->pdata.layers[CD_src + i].name;
+			//append uv layer with the src names
+			ED_mesh_uv_texture_add(me_dst, src_name, true);
+		}
 	}
 
+	else if (replace_mode == REPLACE_ALL_GROUPS)
+	{
+		i = num_dst_lay;
+		while (i > 0) {
+			i--;
+			ED_mesh_uv_texture_remove_index(me_dst, i);
+		}
+
+		CD_src = CustomData_get_layer_index(&me_src->pdata, CD_MTEXPOLY);
+		for (i = 0; i < num_src_lay; ++i) {
+			src_name = me_src->pdata.layers[CD_src + i].name;
+			//add uv layer with the src name
+			ED_mesh_uv_texture_add(me_dst, src_name, true);
+		}
+	}
+
+	else if (replace_mode == REPLACE_ACTIVE_GROUP) {
+
+		//find the source active layer
+		active_src = CustomData_get_active_layer_index(&me_src->ldata, CD_MLOOPUV);
+		active_dst = CustomData_get_active_layer_index(&me_dst->ldata, CD_MLOOPUV);
+
+		CD_src = CustomData_get_layer_index(&me_src->pdata, CD_MTEXPOLY);
+
+		if (num_src_lay == 0) {	//empty destination
+			src_name = me_src->pdata.layers[CD_src + active_src].name;
+
+			//add uv layer with the src name
+			ED_mesh_uv_texture_add(me_dst, src_name, true);
+
+			//make the added layer the active one
+			///what about the MTEXPOLY
+			CustomData_set_layer_active(&me_dst->ldata, CD_MLOOPUV, 0);
+		}
+
+		else {	//destination has layers (accordingly there's a selected layer)
+
+			src_name = me_src->pdata.layers[CD_src + active_src].name;
+
+			CustomData_set_layer_name(&me_dst->ldata, CD_MLOOPUV, active_dst, src_name);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list