Commit: f4ab36bd74adfee34e63b0294c8d5611791d2096
Author: Bastien Montagne
Date:   Tue Oct 14 15:23:36 2014 +0200
Branches: mesh-transfer-data
https://developer.blender.org/rBf4ab36bd74adfee34e63b0294c8d5611791d2096

Clean up/slight rework of mesh islands data.

Now it should be ready for future more generic usage - we might actually want 
to support
islands for arbitrary mesh elem types, not only loops for UVs/splitnors.

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

M       source/blender/blenkernel/BKE_mesh_mapping.h
M       source/blender/blenkernel/intern/mesh_mapping.c
M       source/blender/editors/object/object_transfer_data.c

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

diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h 
b/source/blender/blenkernel/BKE_mesh_mapping.h
index b3410b6..cd8c800 100644
--- a/source/blender/blenkernel/BKE_mesh_mapping.h
+++ b/source/blender/blenkernel/BKE_mesh_mapping.h
@@ -137,32 +137,36 @@ int *BKE_mesh_calc_smoothgroups(
         int *r_totgroup, const bool use_bitflags);
 
 /* Loop islands data helpers. */
-/* TODO: this ended up being the same as MeshElemMap... Should we use this 
generic struct instead? */
-typedef struct MeshIslandItem {
-       int *polys_idx;
-       int nbr_polys;
-} MeshIslandItem;
-
-/* For loops, to which poly island each loop belongs.
- * Island definition can vary based on data type (UVs, loop normals, etc.). */
+enum {
+       MISLAND_TYPE_VERT = 1,
+       MISLAND_TYPE_EDGE = 2,
+       MISLAND_TYPE_POLY = 3,
+       MISLAND_TYPE_LOOP = 4,
+};
+
 typedef struct MeshIslands {
-       int nbr_loops;
-       int *loops_to_islands_idx;
+       short item_type;  /* MISLAND_TYPE_... */
+       short island_type;  /* MISLAND_TYPE_... */
+
+       int nbr_items;
+       int *items_to_islands_idx;
+
        int nbr_islands;
-       MeshIslandItem *islands;  /* Array, one item per island. */
+       MeshElemMap *islands;  /* Array, one item per island. */
+
        void *mem;  /* Memory handler, internal use only. */
 } MeshIslands;
 
-void BKE_loop_islands_init(MeshIslands *islands, const int num_loops);
+void BKE_loop_islands_init(MeshIslands *islands, const short item_type, const 
int num_items, const short island_type);
 void BKE_loop_islands_free(MeshIslands *islands);
-void BKE_loop_islands_add_island(MeshIslands *islands, const int num_loops, 
int *loop_indices,
-                                 const int num_polys, int *poly_indices);
+void BKE_loop_islands_add_island(MeshIslands *islands, const int num_items, 
int *item_indices,
+                                 const int num_island_items, int 
*island_item_indices);
 
 typedef bool (*loop_island_compute)(struct DerivedMesh *dm, MeshIslands 
*r_islands);
 /* Above vert/UV mapping stuff does not do what we need here, but does things 
we do not need here.
  * So better keep them separated for now, I think.
  */
-bool BKE_loop_island_compute_uv(struct DerivedMesh *dm, MeshIslands 
*r_islands);
+bool BKE_loop_poly_island_compute_uv(struct DerivedMesh *dm, MeshIslands 
*r_islands);
 
 /* Generic ways to map some geometry elements from a source mesh to a dest 
one. */
 
@@ -176,8 +180,9 @@ typedef struct Mesh2MeshMappingItem {
 
 /* All mapping computing func return this. */
 typedef struct Mesh2MeshMapping {
-       Mesh2MeshMappingItem *items;  /* Array, one item per dest element. */
        int nbr_items;
+       Mesh2MeshMappingItem *items;  /* Array, one item per dest element. */
+
        void *mem;  /* Memory handler, internal use only. */
 } Mesh2MeshMapping;
 
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c 
b/source/blender/blenkernel/intern/mesh_mapping.c
index 409dad0..e52418c 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -384,25 +384,6 @@ void BKE_mesh_origindex_map_create(MeshElemMap **r_map, 
int **r_mem,
 typedef bool (*check_island_boundary)(const MPoly *mpoly, const MLoop *mloop, 
const MEdge *medge,
                                       const int nbr_egde_users);
 
-static bool bke_check_island_boundary_smooth(const MPoly *mp, const MLoop 
*UNUSED(ml), const MEdge *me,
-                                             const int nbr_egde_users)
-{
-       /* Edge is sharp if its poly is sharp, or edge itself is sharp, or edge 
is not used by exactly two polygons. */
-       return (!(mp->flag & ME_SMOOTH) || (me->flag & ME_SHARP) || 
(nbr_egde_users != 2));
-}
-
-/* TODO: I'm not sure edge seam flag is enough to define UV islands? Maybe we 
should also consider UVmaps values
- *       themselves (i.e. different UV-edges for a same mesh-edge => boun dary 
edge too?).
- *       Would make things much more complex though, and each UVMap would then 
need its own mesh mapping,
- *       not sure we want that at all!
- */
-static bool bke_check_island_boundary_uv(const MPoly *UNUSED(mp), const MLoop 
*UNUSED(ml), const MEdge *me,
-                                         const int UNUSED(nbr_egde_users))
-{
-       /* Edge is UV boundary if tagged as seam. */
-       return (me->flag & ME_SEAM) != 0;
-}
-
 static void bke_poly_loop_islands_compute(const MEdge *medge, const int 
totedge, const MPoly *mpoly, const int totpoly,
                                           const MLoop *mloop, const int 
totloop, const bool use_bitflags,
                                           check_island_boundary 
edge_boundary_check,
@@ -554,6 +535,13 @@ static void bke_poly_loop_islands_compute(const MEdge 
*medge, const int totedge,
        *r_poly_groups = poly_groups;
 }
 
+static bool bke_check_island_boundary_smooth(const MPoly *mp, const MLoop 
*UNUSED(ml), const MEdge *me,
+                                             const int nbr_egde_users)
+{
+       /* Edge is sharp if its poly is sharp, or edge itself is sharp, or edge 
is not used by exactly two polygons. */
+       return (!(mp->flag & ME_SMOOTH) || (me->flag & ME_SHARP) || 
(nbr_egde_users != 2));
+}
+
 /**
  * Calculate smooth groups from sharp edges.
  *
@@ -575,11 +563,20 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const 
int totedge,
        return poly_groups;
 }
 
-void BKE_loop_islands_init(MeshIslands *islands, const int num_loops)
+
+void BKE_loop_islands_init(MeshIslands *islands, const short item_type, const 
int num_items, const short island_type)
 {
-       islands->loops_to_islands_idx = 
MEM_mallocN(sizeof(*islands->loops_to_islands_idx) * (size_t)num_loops, 
__func__);
-       islands->islands = NULL;
+       BLI_assert(ELEM(item_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, 
MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
+       BLI_assert(ELEM(island_type, MISLAND_TYPE_VERT, MISLAND_TYPE_EDGE, 
MISLAND_TYPE_POLY, MISLAND_TYPE_LOOP));
+
+       islands->item_type = item_type;
+       islands->nbr_items = num_items;
+       islands->items_to_islands_idx = 
MEM_mallocN(sizeof(*islands->items_to_islands_idx) * (size_t)num_items, 
__func__);
+
+       islands->island_type = island_type;
        islands->nbr_islands = 0;
+       islands->islands = NULL;
+
        islands->mem = NULL;
 }
 
@@ -590,34 +587,38 @@ void BKE_loop_islands_free(MeshIslands *islands)
 
        if (i) {
                while (i--) {
-                       MeshIslandItem *it = &islands->islands[i];
-                       if (it->nbr_polys) {
-                               MEM_freeN(it->polys_idx);
+                       MeshElemMap *it = &islands->islands[i];
+                       if (it->count) {
+                               MEM_freeN(it->indices);
                        }
                }
 
                MEM_freeN(islands->islands);
-               MEM_freeN(islands->loops_to_islands_idx);
+               MEM_freeN(islands->items_to_islands_idx);
        }
 
-       islands->nbr_loops = 0;
-       islands->loops_to_islands_idx = NULL;
+       islands->item_type = 0;
+       islands->nbr_items = 0;
+       islands->items_to_islands_idx = NULL;
+
+       islands->island_type = 0;
        islands->nbr_islands = 0;
        islands->islands = NULL;
+
        islands->mem = NULL;
 }
 
-void BKE_loop_islands_add_island(MeshIslands *islands, const int num_loops, 
int *loop_indices,
-                                 const int num_polys, int *poly_indices)
+void BKE_loop_islands_add_island(MeshIslands *islands, const int num_items, 
int *items_indices,
+                                 const int num_island_items, int 
*island_item_indices)
 {
-       MeshIslandItem *isl;
+       MeshElemMap *isl;
        const int curr_island_idx = islands->nbr_islands++;
        const size_t curr_num_islands = (size_t)islands->nbr_islands;
-       int i = num_loops;
+       int i = num_items;
 
-       islands->nbr_loops = num_loops;
+       islands->nbr_items = num_items;
        while (i--) {
-               islands->loops_to_islands_idx[loop_indices[i]] = 
curr_island_idx;
+               islands->items_to_islands_idx[items_indices[i]] = 
curr_island_idx;
        }
 
        /* XXX TODO UGLY!!! Quick code, to be done better. */
@@ -629,14 +630,26 @@ void BKE_loop_islands_add_island(MeshIslands *islands, 
const int num_loops, int
        islands->islands = isl;
 
        isl = &isl[curr_island_idx];
-       isl->nbr_polys = num_polys;
-       isl->polys_idx = MEM_mallocN(sizeof(*isl->polys_idx) * 
(size_t)num_polys, __func__);
-       memcpy(isl->polys_idx, poly_indices, sizeof(*isl->polys_idx) * 
(size_t)num_polys);
+       isl->count = num_island_items;
+       isl->indices = MEM_mallocN(sizeof(*isl->indices) * 
(size_t)num_island_items, __func__);
+       memcpy(isl->indices, island_item_indices, sizeof(*isl->indices) * 
(size_t)num_island_items);
+}
+
+/* TODO: I'm not sure edge seam flag is enough to define UV islands? Maybe we 
should also consider UVmaps values
+ *       themselves (i.e. different UV-edges for a same mesh-edge => boundary 
edge too?).
+ *       Would make things much more complex though, and each UVMap would then 
need its own mesh mapping,
+ *       not sure we want that at all!
+ */
+static bool bke_check_island_boundary_uv(const MPoly *UNUSED(mp), const MLoop 
*UNUSED(ml), const MEdge *me,
+                                         const int UNUSED(nbr_egde_users))
+{
+       /* Edge is UV boundary if tagged as seam. */
+       return (me->flag & ME_SEAM) != 0;
 }
 
 /* Note: all this could be optimized... Not sure it would be worth the more 
complex code, though, those loops
  *       are supposed to be really quick to do... */
-bool BKE_loop_island_compute_uv(struct DerivedMesh *dm, MeshIslands *r_islands)
+bool BKE_loop_poly_island_compute_uv(struct DerivedMesh *dm, MeshIslands 
*r_islands)
 {
        MEdge *edges = dm->getEdgeArray(dm);
        MPoly *polys = dm->getPolyArray(dm);
@@ -655,7 +668,7 @@ bool BKE_loop_island_compute_uv(struct DerivedMesh *dm, 
MeshIslands *r_islands)
        int grp_idx, p_idx, pl_idx, l_idx;
 
        BKE_loop_islands_free(r_islands);
-       BKE_loop_islands_init(r_islands, num_loops);
+       BKE_loop_islands_init(r_islands, MISLAND_TYPE_LOOP, num_loops, 
MISLAND_TYPE_POLY);
 
        bke_poly_loop_islands_compute(edges, num_edges, polys, num_polys, 
loops, num_loops, false,
                                      bke_check_island_boundary_uv, 
&poly_groups, &num_poly_groups);
@@ -1603,7 +1616,12 @@ void BKE_dm2mesh_mapping_loops_compute(
                        use_islands = gen_islands_src(dm_src, &islands);
                        num_trees = use_islands ? islands.nbr_islands : 1;
                        treedata = MEM_callocN(sizeof(*treedata) * 
(size_t)num_trees, __func__);
-                       printf("num trees/islands: %d (%d)\n", num_trees, 
use_islands);
+
+                       if (use_islands) {
+                               /* We expect our islands to contain poly 
indices, and a mapping lo

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to