[Bf-blender-cvs] [a7a2d38] mesh-transfer-data: Code compiles again - which does not means it works, by far!

Bastien Montagne noreply at git.blender.org
Sat Oct 4 19:46:43 CEST 2014


Commit: a7a2d382f491a854fb7d18f80d82e6b90ceb5334
Author: Bastien Montagne
Date:   Sat Oct 4 17:04:13 2014 +0200
Branches: mesh-transfer-data
https://developer.blender.org/rBa7a2d382f491a854fb7d18f80d82e6b90ceb5334

Code compiles again - which does not means it works, by far!

Anyway, neither poly nor loop mapping code is linked to anything yet.

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

M	source/blender/blenkernel/BKE_mesh_mapping.h
M	source/blender/blenkernel/intern/bvhutils.c
M	source/blender/blenkernel/intern/mesh_mapping.c

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

diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h
index 235bb45..739d569 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -279,6 +279,13 @@ void BKE_dm2mesh_mapping_polys_compute(
         struct MLoop *loops_dst, const int numloops_dst, struct CustomData *pdata_dst, struct DerivedMesh *dm_src,
         struct Mesh2MeshMapping *r_map);
 
+void BKE_dm2mesh_mapping_loops_compute(
+        const int mode, const struct SpaceTransform *space_transform, const float max_dist,
+        struct MVert *verts_dst, const int numverts_dst, struct MEdge *edges_dst, const int numedges_dst,
+        struct MPoly *polys_dst, const int numpolys_dst, struct MLoop *loops_dst, const int numloops_dst,
+        struct CustomData *pdata_dst, struct CustomData *ldata_dst, const float split_angle_dst,
+        struct DerivedMesh *dm_src, loop_island_compute gen_islands_src, struct Mesh2MeshMapping *r_map);
+
 /* No good (portable) way to have exported inlined functions... */
 #define BKE_MESH_TESSFACE_VINDEX_ORDER(_mf, _v)  (                          \
     (CHECK_TYPE_INLINE(_mf, MFace *),                                       \
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index 6cb5ea8..acc1dcb 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -590,8 +590,8 @@ BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *dm, float e
 	BMEditMesh *em = data->em_evil;
 	const int bvhcache_type = em ? BVHTREE_FROM_FACES_EDITMESH : BVHTREE_FROM_FACES;
 	BVHTree *tree;
-	MVert *vert;
-	MFace *face;
+	MVert *vert = NULL;
+	MFace *face = NULL;
 	bool vert_allocated = false, face_allocated = false;
 
 	BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ);
@@ -679,12 +679,6 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data)
 		if (data->face_allocated) {
 			MEM_freeN(data->face);
 		}
-		if (data->loop_allocated) {
-			MEM_freeN(data->loop);
-		}
-		if (data->poly_allocated) {
-			MEM_freeN(data->poly);
-		}
 
 		memset(data, 0, sizeof(*data));
 	}
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index 240dcf5..4389233 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -584,7 +584,7 @@ static void bke_mesh2mesh_mapping_item_define(
 
 void BKE_mesh2mesh_mapping_islands_create(Mesh2MeshMappingIslands *r_islands, const int num_loops)
 {
-	r_islands->loops_to_islands = MEM_mallocN(sizeof(*r_islands->loops_to_islands) * (size_t)num_loops, __func__);
+	r_islands->loops_to_islands_idx = MEM_mallocN(sizeof(*r_islands->loops_to_islands_idx) * (size_t)num_loops, __func__);
 	r_islands->islands = NULL;
 	r_islands->nbr_islands = 0;
 	r_islands->mem = NULL;
@@ -594,30 +594,28 @@ void BKE_mesh2mesh_mapping_islands_add_island(Mesh2MeshMappingIslands *r_islands
                                               const int num_loops, int *loop_indices,
                                               const int num_polys, int *poly_indices)
 {
-	Mesh2MeshMappingIslandItem *island;
+	Mesh2MeshMappingIslandItem *islands;
 	const int curr_island_idx = r_islands->nbr_islands++;
 	const size_t curr_num_islands = (size_t)r_islands->nbr_islands;
 	int i = num_loops;
 
+	r_islands->nbr_loops = num_loops;
 	while (i--) {
-		r_islands->loops_to_islands[loop_indices[i]] = curr_island_idx;
+		r_islands->loops_to_islands_idx[loop_indices[i]] = curr_island_idx;
 	}
 
 	/* XXX TODO UGLY!!! Quick code, to be done better. */
-	island = MEM_mallocN(sizeof(*islands) * curr_num_islands, __func__);
+	islands = MEM_mallocN(sizeof(*islands) * curr_num_islands, __func__);
 	if (curr_island_idx) {
-		memcpy(island, r_islands->islands, curr_num_islands - 1);
+		memcpy(islands, r_islands->islands, curr_num_islands - 1);
 		MEM_freeN(r_islands->islands);
 	}
 	r_islands->islands = islands;
 
 	islands = &islands[curr_island_idx];
-	islands->nbr_loops = num_loops;
-	islands->island_to_loops = MEM_mallocN(sizeof(*islands->island_to_loops) * (size_t)num_loops, __func__);
-	memcpy(islands->island_to_loops, loop_indices, sizeof(*islands->island_to_loops) * (size_t)num_loops);
 	islands->nbr_polys = num_polys;
-	islands->island_to_polys = MEM_mallocN(sizeof(*islands->island_to_polys) * (size_t)num_polys, __func__);
-	memcpy(islands->island_to_polys, poly_indices, sizeof(*islands->island_to_polys) * (size_t)num_polys);
+	islands->polys_idx = MEM_mallocN(sizeof(*islands->polys_idx) * (size_t)num_polys, __func__);
+	memcpy(islands->polys_idx, poly_indices, sizeof(*islands->polys_idx) * (size_t)num_polys);
 }
 
 static void bke_mesh2mesh_mapping_islands_free(Mesh2MeshMappingIslands *islands)
@@ -631,17 +629,16 @@ static void bke_mesh2mesh_mapping_islands_free(Mesh2MeshMappingIslands *islands)
 
 	while (i--) {
 		Mesh2MeshMappingIslandItem *it = &islands->islands[i];
-		if (it->nbr_loops) {
-			MEM_freeN(it->island_to_loops);
-		}
 		if (it->nbr_polys) {
-			MEM_freeN(it->island_to_polys);
+			MEM_freeN(it->polys_idx);
 		}
 	}
 
 	MEM_freeN(islands->islands);
-	MEM_freeN(islands->loops_to_islands);
+	MEM_freeN(islands->loops_to_islands_idx);
 
+	islands->nbr_loops = 0;
+	islands->loops_to_islands_idx = NULL;
 	islands->nbr_islands = 0;
 	islands->islands = NULL;
 	islands->mem = NULL;
@@ -1433,26 +1430,25 @@ void BKE_dm2mesh_mapping_loops_compute(
 		MPoly *polys_src = DM_get_poly_array(dm_src, &polys_allocated_src);
 		const int num_polys_src = dm_src->getNumPolys(dm_src);
 		bool faces_allocated_src;
-		MFace *faces_src;
+		MFace *faces_src = NULL;
 		int num_faces_src;
 
 		int *orig_poly_idx_src = NULL;
 
-		size_t interp_buff_size = 32;  /* Will be enough in 99% of cases. */
+		size_t buff_size_interp = 32;  /* Will be enough in 99% of cases. */
 		float (*vcos_interp)[3] = NULL;
 		int *indices_interp = NULL;
 		float *weights_interp = NULL;
 
-		int tidx, pidx_dst, lidx_dst, plidx_dst;
-		int i, j, k;
+		int tidx, pidx_dst, lidx_dst, plidx_dst, pidx_src, lidx_src;
 
 		if (!use_from_vert) {
 			vcos_src = MEM_mallocN(sizeof(*vcos_src) * (size_t)num_verts_src, __func__);
 			dm_src->getVertCos(dm_src, vcos_src);
 
-			vcos_interp = MEM_mallocN(sizeof(*vcos_interp) * interp_buff_size, __func__);
-			indices_interp = MEM_mallocN(sizeof(*indices_interp) * interp_buff_size, __func__);
-			weights_interp = MEM_mallocN(sizeof(*weights_interp) * interp_buff_size, __func__);
+			vcos_interp = MEM_mallocN(sizeof(*vcos_interp) * buff_size_interp, __func__);
+			indices_interp = MEM_mallocN(sizeof(*indices_interp) * buff_size_interp, __func__);
+			weights_interp = MEM_mallocN(sizeof(*weights_interp) * buff_size_interp, __func__);
 		}
 
 		{
@@ -1477,9 +1473,9 @@ void BKE_dm2mesh_mapping_loops_compute(
 				if (!loop_nors_dst) {
 					loop_nors_dst = CustomData_add_layer(ldata_dst, CD_NORMAL, CD_CALLOC, NULL, numloops_dst);
 					CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
-					void BKE_mesh_normals_loop_split(verts_dst, numverts_dst, edges_dst, numedges_dst,
-					                                 loops_dst, loop_nors_dst, numloops_dst,
-					                                 polys_dst, poly_nors_dst, numpolys_dst, split_angle_dst);
+					BKE_mesh_normals_loop_split(verts_dst, numverts_dst, edges_dst, numedges_dst,
+					                            loops_dst, loop_nors_dst, numloops_dst,
+					                            polys_dst, poly_nors_dst, numpolys_dst, split_angle_dst);
 				}
 			}
 			if (need_pnors_src || need_lnors_src) {
@@ -1536,8 +1532,8 @@ void BKE_dm2mesh_mapping_loops_compute(
 						memset(verts_active, 0, sizeof(*verts_active) * (size_t)num_verts_src);
 						for (i = 0; i < isld->nbr_polys; i++) {
 							MPoly *mp_src = &polys_src[isld->polys_idx[i]];
-							for (lidx = mp->loopstart; lidx < mp_src->loopstart + mp_src->totloop; lidx++) {
-								verts_active[loops_src[lidx].v] = true;
+							for (lidx_src = mp_src->loopstart; lidx_src < mp_src->loopstart + mp_src->totloop; lidx_src++) {
+								verts_active[loops_src[lidx_src].v] = true;
 								num_verts_active++;
 							}
 						}
@@ -1553,13 +1549,15 @@ void BKE_dm2mesh_mapping_loops_compute(
 				MEM_freeN(verts_active);
 			}
 			else {
-				bvhtree_from_mesh_verts(&treedata[tidx], dm_src, 0.0, 2, 6);
+				for (tidx = 0; tidx < num_trees; tidx++) {
+					bvhtree_from_mesh_verts(&treedata[tidx], dm_src, 0.0, 2, 6);
+				}
 			}
 		}
 		else {  /* We use polygons. */
 			if (use_islands) {
 				/* bvhtree here uses tesselated faces... */
-				const int dirty_tess_flag = dm_src->dirty & DM_DIRTY_TESS_CDLAYERS;
+				const unsigned int dirty_tess_flag = dm_src->dirty & DM_DIRTY_TESS_CDLAYERS;
 				bool *faces_active;
 
 				/* We do not care about tessellated data here, only geometry itself is important. */
@@ -1575,7 +1573,7 @@ void BKE_dm2mesh_mapping_loops_compute(
 				orig_poly_idx_src = dm_src->getTessFaceDataArray(dm_src, CD_ORIGINDEX);
 				faces_active = MEM_mallocN(sizeof(*faces_active) * (size_t)num_faces_src, __func__);
 
-				for (tidx = 0; tidx < numtrees; tidx++) {
+				for (tidx = 0; tidx < num_trees; tidx++) {
 					Mesh2MeshMappingIslandItem *isld = gen_islands_src ? &islands.islands[tidx] : NULL;
 					if (isld) {
 						int num_faces_active = 0;
@@ -1599,9 +1597,13 @@ void BKE_dm2mesh_mapping_loops_compute(
 						}
 					}
 				}
+
+				MEM_freeN(faces_active);
 			}
 			else {
-				bvhtree_from_mesh_faces(&treedata[tidx], dm_src, 0.0, 2, 6);
+				for (tidx = 0; tidx < num_trees; tidx++) {
+					bvhtree_from_mesh_faces(&treedata[tidx], dm_src, 0.0, 2, 6);
+				}
 				orig_poly_idx_src = dm_src->getTessFaceDataArray(dm_src, CD_ORIGINDEX);
 			}
 		}
@@ -1648,7 +1650,7 @@ void BKE_dm2mesh_mapping_loops_compute(
 							int best_idx_src = -1;
 
 							if (mode == M2MMAP_MODE_LOOP_NEAREST_LOOPNOR) {
-								nor_dst = &loop_nors_dst[plidx + mp_src->loopstart];
+								nor_dst = &loop_nors_dst[plidx_dst + mp_dst->loopstart];
 								nors_src = loop_nors_src;
 							}
 							else {  /* if (mode == M2MMAP_MODE_LOOP_NEAREST_POLYNOR) { */
@@ -1682,1

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list