Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-06-14 13:59:09 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-06-14 13:59:09 +0400
commit05ad8c2dc9c708580540e7aadb67b900a52e442e (patch)
tree908f03e9797b1f35afd586849c734b1ec64fdaa3 /source/blender/blenkernel/intern/mesh.c
parent49065fcbe8ddd90c3f8053ca87552433ddd1298d (diff)
expose smooth group calculation to python as Mesh.calc_smooth_groups()
Diffstat (limited to 'source/blender/blenkernel/intern/mesh.c')
-rw-r--r--source/blender/blenkernel/intern/mesh.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index aa45c8fd0aa..3bb2d6fdba4 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -3203,27 +3203,41 @@ static float mesh_calc_poly_planar_area_centroid(MPoly *mpoly, MLoop *loopstart,
return total_area;
}
-
+/**
+ * Calculate smooth groups from sharp edges.
+ *
+ * \param r_totgroup The total number of groups, 1 or more.
+ * \return Polygon aligned array of group index values (starting at 1)
+ */
int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
const MPoly *mpoly, const int totpoly,
- const MLoop *mloop, const int totloop)
+ const MLoop *mloop, const int totloop,
+ int *r_totgroup)
{
- int *poly_groups = MEM_callocN(sizeof(int) * totpoly, __func__);
- int *poly_stack = MEM_mallocN(sizeof(int) * totpoly, __func__);
+ int *poly_groups;
+ int *poly_stack;
STACK_DECLARE(poly_stack);
int poly_prev = 0;
- int poly_group_id = 1;
+ int poly_group_id = 0;
/* map vars */
MeshElemMap *edge_poly_map;
int *edge_poly_mem;
+ if (totpoly == 0) {
+ *r_totgroup = 0;
+ return NULL;
+ }
+
BKE_mesh_edge_poly_map_create(&edge_poly_map, &edge_poly_mem,
medge, totedge,
mpoly, totpoly,
mloop, totloop);
+ poly_groups = MEM_callocN(sizeof(int) * totpoly, __func__);
+ poly_stack = MEM_mallocN(sizeof(int) * totpoly, __func__);
+
STACK_INIT(poly_stack);
while (true) {
@@ -3243,6 +3257,9 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
/* start searching from here next time */
poly_prev = poly + 1;
+ /* group starts at 1 */
+ poly_group_id++;
+
poly_groups[poly] = poly_group_id;
STACK_PUSH(poly_stack, poly);
@@ -3273,8 +3290,6 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
}
}
}
-
- poly_group_id++;
}
MEM_freeN(edge_poly_map);
@@ -3283,6 +3298,8 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge,
STACK_FREE(poly_stack);
+ *r_totgroup = poly_group_id;
+
return poly_groups;
}