[Bf-blender-cvs] [3be9c15] mesh-transfer-data: First hooking of transfer data and geom mapping for polys and loops.

Bastien Montagne noreply at git.blender.org
Tue Oct 7 23:00:25 CEST 2014


Commit: 3be9c154080cfdec0965601b99edb6dff2af7d5b
Author: Bastien Montagne
Date:   Tue Oct 7 22:15:41 2014 +0200
Branches: mesh-transfer-data
https://developer.blender.org/rB3be9c154080cfdec0965601b99edb6dff2af7d5b

First hooking of transfer data and geom mapping for polys and loops.

Using UVMap as test subject. Not even half working yet, though.

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

M	source/blender/blenkernel/BKE_customdata.h
M	source/blender/blenkernel/intern/mesh_mapping.c
M	source/blender/editors/object/object_transfer_data.c

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

diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index f08fd3c..e3028e2 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -387,6 +387,7 @@ enum {
 
 	/* Multiple types of mesh elements... */
 	CD_FAKE_BWEIGHT     = CD_FAKE | CD_BWEIGHT,  /* *sigh*. */
+	CD_FAKE_UV          = CD_FAKE | CD_MLOOPUV,  /* UV flag, because we handle both loop's UVs and poly's textures. */
 
 	CD_FAKE_SHARP       = CD_FAKE | 200,  /* Sharp flag for edges, smooth flag for faces. */
 };
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index 4389233..2d83698 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -1408,7 +1408,7 @@ void BKE_dm2mesh_mapping_loops_compute(
 
 		const bool use_from_vert = (mode & M2MMAP_USE_VERT);
 
-		Mesh2MeshMappingIslands islands;
+		Mesh2MeshMappingIslands islands = {0};
 		bool use_islands = false;
 
 		float (*poly_nors_src)[3] = NULL;
@@ -1513,11 +1513,11 @@ void BKE_dm2mesh_mapping_loops_compute(
 		if (gen_islands_src) {
 			use_islands = gen_islands_src(dm_src, &islands);
 			num_trees = use_islands ? islands.nbr_islands : 1;
-			treedata = MEM_mallocN(sizeof(*treedata) * (size_t)num_trees, __func__);
+			treedata = MEM_callocN(sizeof(*treedata) * (size_t)num_trees, __func__);
 		}
 		else {
 			num_trees = 1;
-			treedata = MEM_mallocN(sizeof(*treedata), __func__);
+			treedata = MEM_callocN(sizeof(*treedata), __func__);
 		}
 
 		/* Build our BVHtrees, either from verts or tessfaces. */
@@ -1754,7 +1754,7 @@ void BKE_dm2mesh_mapping_loops_compute(
 					}
 					else if (use_from_vert) {
 						/* Indices stored in facs are those of loops, one per dest loop. */
-						lidx_src = (int)facs[tidx][plidx_dst][2];
+						lidx_src = (int)facs[best_island_idx][plidx_dst][2];
 						if (lidx_src >= 0) {
 							bke_mesh2mesh_mapping_item_define(&r_map->items[lidx_dst],
 							                                  facs[best_island_idx][plidx_dst][1],
@@ -1769,10 +1769,10 @@ void BKE_dm2mesh_mapping_loops_compute(
 					}
 					else {
 						/* Else, we use source poly, indices stored in facs are those of polygons. */
-						pidx_src = (int)facs[tidx][plidx_dst][2];
+						pidx_src = (int)facs[best_island_idx][plidx_dst][2];
 						if (pidx_src >= 0) {
 							MPoly *mp_src = &polys_src[pidx_src];
-							float *hit_co = &facs[tidx][plidx_dst][3];
+							float *hit_co = &facs[best_island_idx][plidx_dst][3];
 							int best_loop_idx_src;
 
 							if (mode == M2MMAP_MODE_LOOP_POLY_NEAREST) {
diff --git a/source/blender/editors/object/object_transfer_data.c b/source/blender/editors/object/object_transfer_data.c
index ef793cb..0efd6f5 100644
--- a/source/blender/editors/object/object_transfer_data.c
+++ b/source/blender/editors/object/object_transfer_data.c
@@ -88,10 +88,10 @@
 
 #define MDT_DATATYPE_IS_VERT(_dt) ELEM(_dt, CD_FAKE_MDEFORMVERT, CD_FAKE_SHAPEKEY, CD_MVERT_SKIN, CD_FAKE_BWEIGHT)
 #define MDT_DATATYPE_IS_EDGE(_dt) ELEM(_dt, CD_FAKE_CREASE, CD_FAKE_SHARP, CD_FAKE_SEAM, CD_FAKE_BWEIGHT)
-#define MDT_DATATYPE_IS_POLY(_dt) (_dt == CD_FAKE_SHARP)
-#define MDT_DATATYPE_IS_LOOP(_dt) (false)
+#define MDT_DATATYPE_IS_POLY(_dt) ELEM(_dt, CD_FAKE_UV, CD_FAKE_SHARP)
+#define MDT_DATATYPE_IS_LOOP(_dt) (_dt == CD_FAKE_UV)
 
-#define MDT_DATATYPE_IS_MULTILAYERS(_dt) ELEM(_dt, CD_FAKE_MDEFORMVERT, CD_FAKE_SHAPEKEY)
+#define MDT_DATATYPE_IS_MULTILAYERS(_dt) ELEM(_dt, CD_FAKE_MDEFORMVERT, CD_FAKE_SHAPEKEY, CD_FAKE_UV)
 
 /* All possible data to transfer.
  * Note some are 'fake' ones, i.e. they are not hold by real CDLayers. */
@@ -101,12 +101,14 @@ static EnumPropertyItem MDT_layer_items[] = {
 	{CD_FAKE_SHAPEKEY, "SHAPEKEYS", 0, "Shapekey(s)", "Transfer active or all shape keys"},
 	/* XXX When SkinModifier is enabled, it seems to erase its own CD_MVERT_SKIN layer from final DM :( */
 	{CD_MVERT_SKIN, "SKIN", 0, "Skin Weight", "Transfer skin weights"},
+	{CD_FAKE_BWEIGHT, "BEVEL_WEIGHT", 0, "Bevel Weight", "Transfer bevel weights"},
 	{0, "", 0, "Edge Data", ""},
 	{CD_FAKE_SHARP, "SHARP", 0, "Sharp", "Transfer sharp flag"},
 	{CD_FAKE_SEAM, "SEAM", 0, "Seam", "Transfer UV seam flag"},
 	{CD_FAKE_CREASE, "CREASE", 0, "Subsurf Crease", "Transfer crease values"},
+	{CD_FAKE_BWEIGHT, "BEVEL_WEIGHT", 0, "Bevel Weight", "Transfer bevel weights"},
 	{0, "", 0, "Face Data", ""},
-	/* TODO */
+	{CD_FAKE_UV, "UV", 0, "UVs", "Transfer UV layers"},
 	{0, "", 0, "Face Corner Data", ""},
 	/* TODO */
 	{0, NULL, 0, NULL, NULL}
@@ -141,13 +143,27 @@ static EnumPropertyItem MDT_method_edge_items[] = {
 
 static EnumPropertyItem MDT_method_poly_items[] = {
 	{M2MMAP_MODE_TOPOLOGY, "TOPOLOGY", 0, "Topology", "Copy from identical topology meshes"},
-	/* TODO add other modes */
+	{M2MMAP_MODE_POLY_NEAREST, "NEAREST", 0, "Nearest Face",
+			"Copy from nearest polygon (using center points)"},
+	{M2MMAP_MODE_POLY_NOR, "NORMAL", 0, "Best Normal-Matching",
+			"Copy from source polygon which normal is the closest to dest one"},
+	{M2MMAP_MODE_POLY_POLYINTERP_PNORPROJ, "POLYINTERP_PNORPROJ", 0, "Projected Face Interpolated",
+			"Interpolate all source polygons intersected by the projection of dest one along its own normal"},
 	{0, NULL, 0, NULL, NULL}
 };
 
 static EnumPropertyItem MDT_method_loop_items[] = {
 	{M2MMAP_MODE_TOPOLOGY, "TOPOLOGY", 0, "Topology", "Copy from identical topology meshes"},
-	/* TODO add other modes */
+	{M2MMAP_MODE_LOOP_NEAREST_LOOPNOR, "NEAREST_NORMAL", 0, "Nearest Corner And Best Matching Normal",
+			"Copy from nearest corner which has the best matching normal"},
+	{M2MMAP_MODE_LOOP_NEAREST_POLYNOR, "NEAREST_POLYNOR", 0, "Nearest Corner And Best Matching Face Normal",
+			"Copy from nearest corner which has the face with the best matching normal to dest corner's face one"},
+	{M2MMAP_MODE_LOOP_POLY_NEAREST, "NEAREST_POLY", 0, "Nearest Corner Of Nearest Face",
+			"Copy from nearest corner of nearest polygon"},
+	{M2MMAP_MODE_LOOP_POLYINTERP_NEAREST, "POLYINTERP_NEAREST", 0, "Nearest Face Interpolated",
+			"Copy from interpolated corners of the nearest source polygon"},
+	{M2MMAP_MODE_LOOP_POLYINTERP_LNORPROJ, "POLYINTERP_LNORPROJ", 0, "Projected Face Interpolated",
+			"Copy from interpolated corners of the source polygon hit by corner normal projection"},
 	{0, NULL, 0, NULL, NULL}
 };
 
@@ -350,8 +366,8 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(
 						BLI_freelistN(r_map);
 						return false;
 					}
-					CustomData_add_layer_named(data_dst, data_type, CD_CALLOC, NULL, num_create, name);
-					idx_dst = CustomData_get_named_layer(data_dst, data_type, name);
+					CustomData_add_layer_named(cd_dst, data_type, CD_CALLOC, NULL, num_create, name);
+					idx_dst = CustomData_get_named_layer(cd_dst, data_type, name);
 				}
 				data_src = CustomData_get_layer_n(cd_src, data_type, idx_src);
 				data_dst = CustomData_get_layer_n(cd_dst, data_type, idx_dst);
@@ -428,6 +444,7 @@ bool ED_data_transfer_layersmapping_cdlayers(
 						CustomData_add_layer_named(cd_dst, data_type, CD_CALLOC, NULL, num_create, name);
 						idx_dst = CustomData_get_named_layer(cd_dst, data_type, name);
 					}
+					data_dst = CustomData_get_layer_n(cd_dst, data_type, idx_dst);
 				}
 				break;
 			default:
@@ -457,12 +474,12 @@ bool ED_data_transfer_layersmapping_cdlayers(
 }
 
 static bool data_transfer_layersmapping_generate(
-        ListBase *r_map, Object *ob_src, Object *ob_dst, DerivedMesh *dm_src, Mesh *me_dst,
-        const int data_type, const int num_create, const int fromlayers_select, const int tolayers_select)
+        ListBase *r_map, Object *ob_src, Object *ob_dst, DerivedMesh *dm_src, Mesh *me_dst, const int elem_type,
+        int data_type, const int num_create, const int fromlayers_select, const int tolayers_select)
 {
 	CustomData *cd_src, *cd_dst;
 
-	if (MDT_DATATYPE_IS_VERT(data_type)) {
+	if (elem_type == ME_VERT) {
 		if (!(data_type & CD_FAKE)) {
 			cd_src = dm_src->getVertDataLayout(dm_src);
 			cd_dst = &me_dst->vdata;
@@ -507,7 +524,7 @@ static bool data_transfer_layersmapping_generate(
 			return false;
 		}
 	}
-	else if (MDT_DATATYPE_IS_EDGE(data_type)) {
+	if (elem_type == ME_EDGE) {
 		if (!(data_type & CD_FAKE)) {  /* Unused for edges, currently... */
 			cd_src = dm_src->getEdgeDataLayout(dm_src);
 			cd_dst = &me_dst->edata;
@@ -522,6 +539,7 @@ static bool data_transfer_layersmapping_generate(
 				/* We handle specific source selection cases here. */
 				return false;
 			}
+			return true;
 		}
 		else if (data_type == CD_FAKE_CREASE) {
 			const size_t elem_size = sizeof(*((MEdge *)NULL));
@@ -569,13 +587,63 @@ static bool data_transfer_layersmapping_generate(
 			return false;
 		}
 	}
+	if (elem_type == ME_POLY) {
+		if (data_type == CD_FAKE_UV) {
+			data_type = CD_MTEXPOLY;
+		}
+
+		if (!(data_type & CD_FAKE)) {
+			cd_src = dm_src->getPolyDataLayout(dm_src);
+			cd_dst = &me_dst->pdata;
+
+			if (!CustomData_has_layer(cd_src, data_type)) {
+				return false;
+			}
+
+			if (!ED_data_transfer_layersmapping_cdlayers(r_map, data_type, num_create, cd_src, cd_dst,
+			                                             fromlayers_select, tolayers_select))
+			{
+				/* We handle specific source selection cases here. */
+				return false;
+			}
+			return true;
+		}
+		else {
+			return false;
+		}
+	}
+	if (elem_type == ME_LOOP) {
+		if (data_type == CD_FAKE_UV) {
+			data_type = CD_MLOOPUV;
+		}
+
+		if (!(data_type & CD_FAKE)) {
+			cd_src = dm_src->getLoopDataLayout(dm_src);
+			cd_dst = &me_dst->ldata;
+
+			if (!CustomData_has_layer(cd_src, data_type)) {
+				return false;
+			}
+
+			if (!ED_data_transfer_layersmapping_cdlayers(r_map, data_type, num_create, cd_src, cd_dst,
+			                                             fromlayers_select, tolayers_select))
+			{
+				/* We handle specific source selection cases here. */
+				return false;
+			}
+			return true;
+		}
+		else {
+			return false;
+		}
+	}
 
 	return false;
 }
 
 bool ED_data_transfer(
         Scene *scene, Object *ob_src, Object *ob_dst, const int data_type, const bool use_create,
-        const 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list