diff options
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 24 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh_api.c | 6 |
3 files changed, 19 insertions, 13 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 4f859c1ced0..7d3fd836836 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -108,7 +108,7 @@ void BKE_mesh_calc_poly_angles(struct MPoly *mpoly, struct MLoop *loopstart, int *BKE_mesh_calc_smoothgroups(const struct MEdge *medge, const int totedge, const struct MPoly *mpoly, const int totpoly, const struct MLoop *mloop, const int totloop, - int *r_totgroup); + int *r_totgroup, const bool use_bitflags); void BKE_mesh_calc_relative_deform( const struct MPoly *mpoly, const int totpoly, diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 05edeebfafc..459f7216d00 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -3312,12 +3312,12 @@ static float mesh_calc_poly_planar_area_centroid(MPoly *mpoly, MLoop *loopstart, * 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 (bitflags, starting at 1). + * \return Polygon aligned array of group index values (bitflags if use_bitflags is true), 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, - int *r_totgroup) + int *r_totgroup, const bool use_bitflags) { int *poly_groups; int *poly_stack; @@ -3348,6 +3348,7 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge, while (true) { int poly; int bit_poly_group_mask = 0; + int poly_group_id; int ps_curr_idx = 0, ps_end_idx = 0; /* stack indices */ for (poly = poly_prev; poly < totpoly; poly++) { @@ -3361,10 +3362,12 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge, break; } + poly_group_id = use_bitflags ? temp_poly_group_id : ++tot_group; + /* start searching from here next time */ poly_prev = poly + 1; - poly_groups[poly] = temp_poly_group_id; + poly_groups[poly] = poly_group_id; poly_stack[ps_end_idx++] = poly; while (ps_curr_idx != ps_end_idx) { @@ -3373,7 +3376,7 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge, int j; poly = poly_stack[ps_curr_idx++]; - BLI_assert(poly_groups[poly] == temp_poly_group_id); + BLI_assert(poly_groups[poly] == poly_group_id); mp = &mpoly[poly]; for (ml = &mloop[mp->loopstart], j = mp->totloop; j--; ml++) { @@ -3384,19 +3387,19 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge, if (!(medge[ml->e].flag & ME_SHARP)) { for (; i--; p++) { /* if we meet other non initialized its a bug */ - BLI_assert(ELEM(poly_groups[*p], 0, temp_poly_group_id)); + BLI_assert(ELEM(poly_groups[*p], 0, poly_group_id)); if (poly_groups[*p] == 0) { - poly_groups[*p] = temp_poly_group_id; + poly_groups[*p] = poly_group_id; poly_stack[ps_end_idx++] = *p; } } } - else { + else if (use_bitflags) { /* Find contiguous smooth groups already assigned, these are the values we can't reuse! */ for (; i--; p++) { int bit = poly_groups[*p]; - if (!ELEM3(bit, 0, temp_poly_group_id, poly_group_id_overflowed) && + if (!ELEM3(bit, 0, poly_group_id, poly_group_id_overflowed) && !(bit_poly_group_mask & bit)) { bit_poly_group_mask |= bit; @@ -3408,8 +3411,9 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge, /* And now, we have all our poly from current group in poly_stack (from 0 to (ps_end_idx - 1)), as well as * all smoothgroups bits we can't use in bit_poly_group_mask. */ - { - int i, *p, gid_bit = 0, poly_group_id = 1; + if (use_bitflags) { + int i, *p, gid_bit = 0; + poly_group_id = 1; /* Find first bit available! */ for (; (poly_group_id & bit_poly_group_mask) && (gid_bit < 32); gid_bit++) { diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index ad9977fef50..7fec4a1ff9c 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -57,14 +57,15 @@ static const char *rna_Mesh_unit_test_compare(struct Mesh *mesh, bContext *C, st return ret; } -void rna_Mesh_calc_smooth_groups(struct Mesh *mesh, int *r_poly_group_len, int **r_poly_group, int *r_group_total) +void rna_Mesh_calc_smooth_groups(struct Mesh *mesh, int use_bitflags, int *r_poly_group_len, + int **r_poly_group, int *r_group_total) { *r_poly_group_len = mesh->totpoly; *r_poly_group = BKE_mesh_calc_smoothgroups( mesh->medge, mesh->totedge, mesh->mpoly, mesh->totpoly, mesh->mloop, mesh->totloop, - r_group_total); + r_group_total, use_bitflags); } #else @@ -87,6 +88,7 @@ void RNA_api_mesh(StructRNA *srna) func = RNA_def_function(srna, "calc_smooth_groups", "rna_Mesh_calc_smooth_groups"); RNA_def_function_ui_description(func, "Calculate smooth groups from sharp edges"); + RNA_def_boolean(func, "use_bitflags", false, "", "Produce bitflags groups instead of simple numeric values"); /* return values */ parm = RNA_def_int_array(func, "poly_groups", 1, NULL, 0, 0, "", "Smooth Groups", 0, 0); RNA_def_property_flag(parm, PROP_DYNAMIC | PROP_OUTPUT); |