Ack... Followup to r59743: in fact, bitflags groups are not always wanted/needed...
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 2 Sep 2013 18:33:06 +0000 (18:33 +0000)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 2 Sep 2013 18:33:06 +0000 (18:33 +0000)
So now, their generation is controlled by a flag, else previous "simple values" group ids are generated (one per poly region, no need here to reduce the number of used IDs!).

Will update obj exporter too.

source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/intern/mesh.c
source/blender/makesrna/intern/rna_mesh_api.c

index 4f859c1ced0ad00fbce30889e5ecfd10d378d9b1..7d3fd8368360f91da64158f91eca6c18699e218a 100644 (file)
@@ -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,
index 05edeebfafc62cf3f07142008beb59e82f324a2a..459f7216d002a018933e6143242f99ab2d23bfb2 100644 (file)
@@ -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++) {
index ad9977fef509506e59e26be549b35c8d1feb9718..7fec4a1ff9c7a08fb6792a04b1c7fc02de65cd3e 100644 (file)
@@ -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);