Blender  V2.93
Classes
mesh_mapping.c File Reference
#include "MEM_guardedalloc.h"
#include "DNA_meshdata_types.h"
#include "DNA_vec_types.h"
#include "BLI_bitmap.h"
#include "BLI_buffer.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BKE_customdata.h"
#include "BKE_mesh_mapping.h"
#include "BLI_memarena.h"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  MeshCheckIslandBoundaryUv
 

Functions

Mesh Connectivity Mapping
UvVertMapBKE_mesh_uv_vert_map_create (const MPoly *mpoly, const MLoop *mloop, const MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, const float limit[2], const bool selected, const bool use_winding)
 
UvMapVertBKE_mesh_uv_vert_map_get_vert (UvVertMap *vmap, unsigned int v)
 
void BKE_mesh_uv_vert_map_free (UvVertMap *vmap)
 
static void mesh_vert_poly_or_loop_map_create (MeshElemMap **r_map, int **r_mem, const MPoly *mpoly, const MLoop *mloop, int totvert, int totpoly, int totloop, const bool do_loops)
 
void BKE_mesh_vert_poly_map_create (MeshElemMap **r_map, int **r_mem, const MPoly *mpoly, const MLoop *mloop, int totvert, int totpoly, int totloop)
 
void BKE_mesh_vert_loop_map_create (MeshElemMap **r_map, int **r_mem, const MPoly *mpoly, const MLoop *mloop, int totvert, int totpoly, int totloop)
 
void BKE_mesh_vert_looptri_map_create (MeshElemMap **r_map, int **r_mem, const MVert *UNUSED(mvert), const int totvert, const MLoopTri *mlooptri, const int totlooptri, const MLoop *mloop, const int UNUSED(totloop))
 
void BKE_mesh_vert_edge_map_create (MeshElemMap **r_map, int **r_mem, const MEdge *medge, int totvert, int totedge)
 
void BKE_mesh_vert_edge_vert_map_create (MeshElemMap **r_map, int **r_mem, const MEdge *medge, int totvert, int totedge)
 
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)
 
void BKE_mesh_edge_poly_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)
 
void BKE_mesh_origindex_map_create (MeshElemMap **r_map, int **r_mem, const int totsource, const int *final_origindex, const int totfinal)
 
void BKE_mesh_origindex_map_create_looptri (MeshElemMap **r_map, int **r_mem, const MPoly *mpoly, const int mpoly_num, const MLoopTri *looptri, const int looptri_num)
 

Mesh loops/poly islands.

Used currently for UVs and 'smooth groups'.

#define MISLAND_DEFAULT_BUFSIZE   64
 
typedef bool(* MeshRemap_CheckIslandBoundary) (const struct MPoly *mpoly, const struct MLoop *mloop, const struct MEdge *medge, const int nbr_egde_users, const struct MPoly *mpoly_array, const struct MeshElemMap *edge_poly_map, void *user_data)
 
typedef struct MeshCheckIslandBoundaryUv MeshCheckIslandBoundaryUv
 
static void poly_edge_loop_islands_calc (const MEdge *medge, const int totedge, const MPoly *mpoly, const int totpoly, const MLoop *mloop, const int totloop, MeshElemMap *edge_poly_map, const bool use_bitflags, MeshRemap_CheckIslandBoundary edge_boundary_check, void *edge_boundary_check_data, int **r_poly_groups, int *r_totgroup, BLI_bitmap **r_edge_borders, int *r_totedgeborder)
 
static bool poly_is_island_boundary_smooth_cb (const MPoly *mp, const MLoop *UNUSED(ml), const MEdge *me, const int nbr_egde_users, const MPoly *mpoly_array, const MeshElemMap *edge_poly_map, void *UNUSED(user_data))
 
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, const bool use_bitflags)
 
void BKE_mesh_loop_islands_init (MeshIslandStore *island_store, const short item_type, const int items_num, const short island_type, const short innercut_type)
 
void BKE_mesh_loop_islands_clear (MeshIslandStore *island_store)
 
void BKE_mesh_loop_islands_free (MeshIslandStore *island_store)
 
void BKE_mesh_loop_islands_add (MeshIslandStore *island_store, const int item_num, const int *items_indices, const int num_island_items, int *island_item_indices, const int num_innercut_items, int *innercut_item_indices)
 
static bool mesh_check_island_boundary_uv (const MPoly *UNUSED(mp), const MLoop *ml, const MEdge *me, const int UNUSED(nbr_egde_users), const MPoly *UNUSED(mpoly_array), const MeshElemMap *UNUSED(edge_poly_map), void *user_data)
 
static bool mesh_calc_islands_loop_poly_uv (MVert *UNUSED(verts), const int UNUSED(totvert), MEdge *edges, const int totedge, MPoly *polys, const int totpoly, MLoop *loops, const int totloop, const MLoopUV *luvs, MeshIslandStore *r_island_store)
 
bool BKE_mesh_calc_islands_loop_poly_edgeseam (MVert *verts, const int totvert, MEdge *edges, const int totedge, MPoly *polys, const int totpoly, MLoop *loops, const int totloop, MeshIslandStore *r_island_store)
 
bool BKE_mesh_calc_islands_loop_poly_uvmap (MVert *verts, const int totvert, MEdge *edges, const int totedge, MPoly *polys, const int totpoly, MLoop *loops, const int totloop, const MLoopUV *luvs, MeshIslandStore *r_island_store)
 

Detailed Description

Functions for accessing mesh connectivity data. eg: polys connected to verts, UV's connected to verts.

Definition in file mesh_mapping.c.

Macro Definition Documentation

◆ MISLAND_DEFAULT_BUFSIZE

#define MISLAND_DEFAULT_BUFSIZE   64

Definition at line 890 of file mesh_mapping.c.

Typedef Documentation

◆ MeshCheckIslandBoundaryUv

◆ MeshRemap_CheckIslandBoundary

typedef bool(* MeshRemap_CheckIslandBoundary) (const struct MPoly *mpoly, const struct MLoop *mloop, const struct MEdge *medge, const int nbr_egde_users, const struct MPoly *mpoly_array, const struct MeshElemMap *edge_poly_map, void *user_data)

Callback deciding whether the given poly/loop/edge define an island boundary or not.

Definition at line 630 of file mesh_mapping.c.

Function Documentation

◆ BKE_mesh_calc_islands_loop_poly_edgeseam()

bool BKE_mesh_calc_islands_loop_poly_edgeseam ( MVert verts,
const int  totvert,
MEdge edges,
const int  totedge,
MPoly polys,
const int  totpoly,
MLoop loops,
const int  totloop,
MeshIslandStore r_island_store 
)

Calculate 'generic' UV islands, i.e. based only on actual geometry data (edge seams), not some UV layers coordinates.

Definition at line 1209 of file mesh_mapping.c.

References mesh_calc_islands_loop_poly_uv(), NULL, and verts.

Referenced by data_transfer_get_loop_islands_generator().

◆ BKE_mesh_calc_islands_loop_poly_uvmap()

bool BKE_mesh_calc_islands_loop_poly_uvmap ( MVert verts,
const int  totvert,
MEdge edges,
const int  totedge,
MPoly polys,
const int  totpoly,
MLoop loops,
const int  totloop,
const MLoopUV luvs,
MeshIslandStore r_island_store 
)

Calculate UV islands.

Note
If no MLoopUV layer is passed, we only consider edges tagged as seams as UV boundaries. This has the advantages of simplicity, and being valid/common to all UV maps. However, it means actual UV islands without matching UV seams will not be handled correctly... If a valid UV layer is passed as luvs parameter, UV coordinates are also used to detect islands boundaries.
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...

Definition at line 1236 of file mesh_mapping.c.

References BLI_assert, mesh_calc_islands_loop_poly_uv(), NULL, and verts.

◆ BKE_mesh_calc_smoothgroups()

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,
const bool  use_bitflags 
)

Calculate smooth groups from sharp edges.

Parameters
r_totgroupThe total number of groups, 1 or more.
Returns
Polygon aligned array of group index values (bitflags if use_bitflags is true), starting at 1 (0 being used as 'invalid' flag). Note it's callers's responsibility to MEM_freeN returned array.

Definition at line 861 of file mesh_mapping.c.

References NULL, poly_edge_loop_islands_calc(), and poly_is_island_boundary_smooth_cb().

◆ BKE_mesh_edge_loop_map_create()

void BKE_mesh_edge_loop_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MEdge UNUSEDmedge,
const int  totedge,
const MPoly mpoly,
const int  totpoly,
const MLoop mloop,
const int  totloop 
)

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.

Definition at line 426 of file mesh_mapping.c.

References MeshElemMap::count, MLoop::e, MeshElemMap::indices, indices, MPoly::loopstart, MEM_callocN, MEM_mallocN, and MPoly::totloop.

Referenced by mesh_calc_islands_loop_poly_uv().

◆ BKE_mesh_edge_poly_map_create()

void BKE_mesh_edge_poly_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MEdge UNUSEDmedge,
const int  totedge,
const MPoly mpoly,
const int  totpoly,
const MLoop mloop,
const int  totloop 
)

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.

Definition at line 484 of file mesh_mapping.c.

References MeshElemMap::count, MLoop::e, MeshElemMap::indices, indices, MPoly::loopstart, MEM_callocN, MEM_mallocN, and MPoly::totloop.

Referenced by mesh_calc_islands_loop_poly_uv(), and poly_edge_loop_islands_calc().

◆ BKE_mesh_loop_islands_add()

void BKE_mesh_loop_islands_add ( MeshIslandStore island_store,
const int  item_num,
const int *  items_indices,
const int  num_island_items,
int *  island_item_indices,
const int  num_innercut_items,
int *  innercut_item_indices 
)

◆ BKE_mesh_loop_islands_clear()

void BKE_mesh_loop_islands_clear ( MeshIslandStore island_store)

◆ BKE_mesh_loop_islands_free()

void BKE_mesh_loop_islands_free ( MeshIslandStore island_store)

Definition at line 946 of file mesh_mapping.c.

References BLI_memarena_free(), MeshIslandStore::mem, and NULL.

Referenced by BKE_mesh_remap_calc_loops_from_mesh().

◆ BKE_mesh_loop_islands_init()

void BKE_mesh_loop_islands_init ( MeshIslandStore island_store,
const short  item_type,
const int  items_num,
const short  island_type,
const short  innercut_type 
)

◆ BKE_mesh_origindex_map_create()

void BKE_mesh_origindex_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const int  totsource,
const int *  final_origindex,
const int  totfinal 
)

This function creates a map so the source-data (vert/edge/loop/poly) can loop over the destination data (using the destination arrays origindex).

This has the advantage that it can operate on any data-types.

Parameters
totsourceThe total number of elements the that final_origindex points to.
totfinalThe size of final_origindex
final_origindexThe size of the final array.
Note
totsource could be totpoly, totfinal could be tottessface and final_origindex its ORIGINDEX customdata. This would allow an MPoly to loop over its tessfaces.

Definition at line 546 of file mesh_mapping.c.

References BLI_assert, MeshElemMap::count, MeshElemMap::indices, indices, MEM_callocN, MEM_mallocN, and ORIGINDEX_NONE.

◆ BKE_mesh_origindex_map_create_looptri()

void BKE_mesh_origindex_map_create_looptri ( MeshElemMap **  r_map,
int **  r_mem,
const MPoly mpoly,
const int  mpoly_num,
const MLoopTri looptri,
const int  looptri_num 
)

A version of BKE_mesh_origindex_map_create that takes a looptri array. Making a poly -> looptri map.

Definition at line 591 of file mesh_mapping.c.

References MeshElemMap::count, MeshElemMap::indices, indices, ME_POLY_TRI_TOT, MEM_callocN, MEM_mallocN, and MLoopTri::poly.

◆ BKE_mesh_uv_vert_map_create()

UvVertMap* BKE_mesh_uv_vert_map_create ( const MPoly mpoly,
const MLoop mloop,
const MLoopUV mloopuv,
unsigned int  totpoly,
unsigned int  totvert,
const float  limit[2],
const bool  selected,
const bool  use_winding 
)

◆ BKE_mesh_uv_vert_map_free()

void BKE_mesh_uv_vert_map_free ( UvVertMap vmap)

◆ BKE_mesh_uv_vert_map_get_vert()

UvMapVert* BKE_mesh_uv_vert_map_get_vert ( UvVertMap vmap,
unsigned int  v 
)

Definition at line 179 of file mesh_mapping.c.

References v, and UvVertMap::vert.

Referenced by get_face_uv_map_vert(), precalc_uv_layer(), and ss_sync_from_uv().

◆ BKE_mesh_vert_edge_map_create()

void BKE_mesh_vert_edge_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MEdge medge,
int  totvert,
int  totedge 
)

Generates a map where the key is the vertex and the value is a list of edges that use that vertex as an endpoint. The lists are allocated from one memory pool.

Definition at line 339 of file mesh_mapping.c.

References MeshElemMap::count, MeshElemMap::indices, indices, MEM_callocN, MEM_mallocN, v, MEdge::v1, and MEdge::v2.

◆ BKE_mesh_vert_edge_vert_map_create()

void BKE_mesh_vert_edge_vert_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MEdge medge,
int  totvert,
int  totedge 
)

A version of BKE_mesh_vert_edge_map_create that references connected vertices directly (not their edges).

Definition at line 382 of file mesh_mapping.c.

References MeshElemMap::count, MeshElemMap::indices, indices, MEM_callocN, MEM_mallocN, v, MEdge::v1, and MEdge::v2.

◆ BKE_mesh_vert_loop_map_create()

void BKE_mesh_vert_loop_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MPoly mpoly,
const MLoop mloop,
int  totvert,
int  totpoly,
int  totloop 
)

Generates a map where the key is the vertex and the value is a list of loops that use that vertex as a corner. The lists are allocated from one memory pool.

Definition at line 274 of file mesh_mapping.c.

References mesh_vert_poly_or_loop_map_create().

◆ BKE_mesh_vert_looptri_map_create()

void BKE_mesh_vert_looptri_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MVert UNUSEDmvert,
const int  totvert,
const MLoopTri mlooptri,
const int  totlooptri,
const MLoop mloop,
const int   UNUSEDtotloop 
)

Generates a map where the key is the edge and the value is a list of looptris that use that edge. The lists are allocated from one memory pool.

Definition at line 290 of file mesh_mapping.c.

References MeshElemMap::count, MeshElemMap::indices, indices, MEM_callocN, MEM_mallocN, MLoopTri::tri, and MLoop::v.

◆ BKE_mesh_vert_poly_map_create()

void BKE_mesh_vert_poly_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MPoly mpoly,
const MLoop mloop,
int  totvert,
int  totpoly,
int  totloop 
)

Generates a map where the key is the vertex and the value is a list of polys that use that vertex as a corner. The lists are allocated from one memory pool.

Definition at line 258 of file mesh_mapping.c.

References mesh_vert_poly_or_loop_map_create().

◆ mesh_calc_islands_loop_poly_uv()

static bool mesh_calc_islands_loop_poly_uv ( MVert UNUSEDverts,
const int   UNUSEDtotvert,
MEdge edges,
const int  totedge,
MPoly polys,
const int  totpoly,
MLoop loops,
const int  totloop,
const MLoopUV luvs,
MeshIslandStore r_island_store 
)
static

◆ mesh_check_island_boundary_uv()

static bool mesh_check_island_boundary_uv ( const MPoly UNUSEDmp,
const MLoop ml,
const MEdge me,
const int   UNUSEDnbr_egde_users,
const MPoly UNUSEDmpoly_array,
const MeshElemMap UNUSEDedge_poly_map,
void *  user_data 
)
static

◆ mesh_vert_poly_or_loop_map_create()

static void mesh_vert_poly_or_loop_map_create ( MeshElemMap **  r_map,
int **  r_mem,
const MPoly mpoly,
const MLoop mloop,
int  totvert,
int  totpoly,
int  totloop,
const bool  do_loops 
)
static

Generates a map where the key is the vertex and the value is a list of polys or loops that use that vertex as a corner. The lists are allocated from one memory pool.

Wrapped by BKE_mesh_vert_poly_map_create & BKE_mesh_vert_loop_map_create

Definition at line 204 of file mesh_mapping.c.

References MeshElemMap::count, MeshElemMap::indices, indices, MPoly::loopstart, MEM_callocN, MEM_mallocN, MPoly::totloop, v, and MLoop::v.

Referenced by BKE_mesh_vert_loop_map_create(), and BKE_mesh_vert_poly_map_create().

◆ poly_edge_loop_islands_calc()

static void poly_edge_loop_islands_calc ( const MEdge medge,
const int  totedge,
const MPoly mpoly,
const int  totpoly,
const MLoop mloop,
const int  totloop,
MeshElemMap edge_poly_map,
const bool  use_bitflags,
MeshRemap_CheckIslandBoundary  edge_boundary_check,
void *  edge_boundary_check_data,
int **  r_poly_groups,
int *  r_totgroup,
BLI_bitmap **  r_edge_borders,
int *  r_totedgeborder 
)
static

◆ poly_is_island_boundary_smooth_cb()

static bool poly_is_island_boundary_smooth_cb ( const MPoly mp,
const MLoop UNUSEDml,
const MEdge me,
const int  nbr_egde_users,
const MPoly mpoly_array,
const MeshElemMap edge_poly_map,
void *  UNUSEDuser_data 
)
static