[Bf-blender-cvs] [db0c2be] master: BKE mesh mapping: add new BKE_mesh_edge_loop_map_create().

Bastien Montagne noreply at git.blender.org
Thu Jul 21 16:55:34 CEST 2016


Commit: db0c2be55e8705f939c944430be1c9d55598a211
Author: Bastien Montagne
Date:   Thu Jul 21 16:30:57 2016 +0200
Branches: master
https://developer.blender.org/rBdb0c2be55e8705f939c944430be1c9d55598a211

BKE mesh mapping: add new BKE_mesh_edge_loop_map_create().

Maps edges to all their pair of loops.

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

M	source/blender/blenkernel/BKE_mesh_mapping.h
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 dff79b6..7689591 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -125,6 +125,11 @@ void BKE_mesh_vert_edge_map_create(
 void BKE_mesh_vert_edge_vert_map_create(
         MeshElemMap **r_map, int **r_mem,
         const struct MEdge *medge, int totvert, int totedge);
+void BKE_mesh_edge_loop_map_create(
+        MeshElemMap **r_map, int **r_mem,
+        const struct MEdge *medge, const int totedge,
+        const struct MPoly *mpoly, const int totpoly,
+        const struct MLoop *mloop, const int totloop);
 void BKE_mesh_edge_poly_map_create(
         MeshElemMap **r_map, int **r_mem,
         const struct MEdge *medge, const int totedge,
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index a472b6e..dc2e953 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -393,6 +393,60 @@ void BKE_mesh_vert_edge_vert_map_create(
 }
 
 /**
+ * Generates a map where the key is the edge and the value is a list of loops that use that edge.
+ * Loops indices of a same poly are contiguous and in winding order.
+ * The lists are allocated from one memory pool.
+ */
+void BKE_mesh_edge_loop_map_create(MeshElemMap **r_map, int **r_mem,
+                                   const MEdge *UNUSED(medge), const int totedge,
+                                   const MPoly *mpoly, const int totpoly,
+                                   const MLoop *mloop, const int totloop)
+{
+	MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)totedge, "edge-poly map");
+	int *indices = MEM_mallocN(sizeof(int) * (size_t)totloop * 2, "edge-poly map mem");
+	int *index_step;
+	const MPoly *mp;
+	int i;
+
+	/* count face users */
+	for (i = 0, mp = mpoly; i < totpoly; mp++, i++) {
+		const MLoop *ml;
+		int j = mp->totloop;
+		for (ml = &mloop[mp->loopstart]; j--; ml++) {
+			map[ml->e].count += 2;
+		}
+	}
+
+	/* create offsets */
+	index_step = indices;
+	for (i = 0; i < totedge; i++) {
+		map[i].indices = index_step;
+		index_step += map[i].count;
+
+		/* re-count, using this as an index below */
+		map[i].count = 0;
+	}
+
+	/* assign loop-edge users */
+	for (i = 0, mp = mpoly; i < totpoly; mp++, i++) {
+		const MLoop *ml;
+		MeshElemMap *map_ele;
+		const int max_loop = mp->loopstart + mp->totloop;
+		int j = mp->loopstart;
+		for (ml = &mloop[j]; j < max_loop; j++, ml++) {
+			map_ele = &map[ml->e];
+			map_ele->indices[map_ele->count++] = j;
+			map_ele->indices[map_ele->count++] = j + 1;
+		}
+		/* last edge/loop of poly, must point back to first loop! */
+		map_ele->indices[map_ele->count - 1] = mp->loopstart;
+	}
+
+	*r_map = map;
+	*r_mem = indices;
+}
+
+/**
  * Generates a map where the key is the edge and the value is a list of polygons that use that edge.
  * The lists are allocated from one memory pool.
  */




More information about the Bf-blender-cvs mailing list