Blender  V3.3
BKE_mesh_mapping.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 #pragma once
4 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 struct MEdge;
14 struct MLoop;
15 struct MLoopTri;
16 struct MLoopUV;
17 struct MPoly;
18 struct MVert;
19 
20 /* map from uv vertex to face (for select linked, stitch, uv suburf) */
21 
22 /* UvVertMap */
23 #define STD_UV_CONNECT_LIMIT 0.0001f
24 
25 typedef struct UvVertMap {
26  struct UvMapVert **vert;
27  struct UvMapVert *buf;
29 
30 typedef struct UvMapVert {
31  struct UvMapVert *next;
32  unsigned int poly_index;
33  unsigned short loop_of_poly_index;
34  bool separate;
36 
37 /* UvElement stores per uv information so that we can quickly access information for a uv.
38  * it is actually an improved UvMapVert, including an island and a direct pointer to the face
39  * to avoid initializing face arrays */
40 typedef struct UvElement {
41  /* Next UvElement corresponding to same vertex */
42  struct UvElement *next;
43  /* Face the element belongs to */
44  struct BMLoop *l;
45  /* index in loop. */
46  unsigned short loop_of_poly_index;
47  /* Whether this element is the first of coincident elements */
48  bool separate;
49  /* general use flag */
50  unsigned char flag;
51  /* If generating element map with island sorting, this stores the island index */
52  unsigned int island;
54 
55 /* UvElementMap is a container for UvElements of a mesh. It stores some UvElements belonging to the
56  * same uv island in sequence and the number of uvs per island so it is possible to access all uvs
57  * belonging to an island directly by iterating through the buffer.
58  */
59 typedef struct UvElementMap {
60  /* address UvElements by their vertex */
61  struct UvElement **vert;
62  /* UvElement Store */
63  struct UvElement *buf;
64  /* Total number of UVs in the layer. Useful to know */
65  int totalUVs;
66  /* Number of Islands in the mesh */
68  /* Stores the starting index in buf where each island begins */
71 
72 /* Connectivity data */
73 typedef struct MeshElemMap {
74  int *indices;
75  int count;
77 
78 /* mapping */
80  const struct MLoop *mloop,
81  const struct MLoopUV *mloopuv,
82  unsigned int totpoly,
83  unsigned int totvert,
84  const float limit[2],
85  bool selected,
86  bool use_winding);
89 
96  int **r_mem,
97  const struct MPoly *mpoly,
98  const struct MLoop *mloop,
99  int totvert,
100  int totpoly,
101  int totloop);
108  int **r_mem,
109  const struct MPoly *mpoly,
110  const struct MLoop *mloop,
111  int totvert,
112  int totpoly,
113  int totloop);
120  int **r_mem,
121  const struct MVert *mvert,
122  int totvert,
123  const struct MLoopTri *mlooptri,
124  int totlooptri,
125  const struct MLoop *mloop,
126  int totloop);
133  MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, int totvert, int totedge);
139  MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, int totvert, int totedge);
146  int **r_mem,
147  const struct MEdge *medge,
148  int totedge,
149  const struct MPoly *mpoly,
150  int totpoly,
151  const struct MLoop *mloop,
152  int totloop);
159  int **r_mem,
160  const struct MEdge *medge,
161  int totedge,
162  const struct MPoly *mpoly,
163  int totpoly,
164  const struct MLoop *mloop,
165  int totloop);
181  MeshElemMap **r_map, int **r_mem, int totsource, const int *final_origindex, int totfinal);
187  int **r_mem,
188  const struct MPoly *mpoly,
189  int mpoly_num,
190  const struct MLoopTri *looptri,
191  int looptri_num);
192 
193 /* islands */
194 
195 /* Loop islands data helpers. */
196 enum {
202 };
203 
204 typedef struct MeshIslandStore {
205  short item_type; /* MISLAND_TYPE_... */
206  short island_type; /* MISLAND_TYPE_... */
207  short innercut_type; /* MISLAND_TYPE_... */
208 
210  int *items_to_islands; /* map the item to the island index */
211 
214  struct MeshElemMap **islands; /* Array of pointers, one item per island. */
215  struct MeshElemMap **innercuts; /* Array of pointers, one item per island. */
216 
217  struct MemArena *mem; /* Memory arena, internal use only. */
219 
221  short item_type,
222  int items_num,
223  short island_type,
224  short innercut_type);
225 void BKE_mesh_loop_islands_clear(MeshIslandStore *island_store);
226 void BKE_mesh_loop_islands_free(MeshIslandStore *island_store);
227 void BKE_mesh_loop_islands_add(MeshIslandStore *island_store,
228  int item_num,
229  const int *items_indices,
230  int num_island_items,
231  int *island_item_indices,
232  int num_innercut_items,
233  int *innercut_item_indices);
234 
236  int totvert,
237  struct MEdge *edges,
238  int totedge,
239  struct MPoly *polys,
240  int totpoly,
241  struct MLoop *loops,
242  int totloop,
243  struct MeshIslandStore *r_island_store);
244 
245 /* Above vert/UV mapping stuff does not do what we need here, but does things we do not need here.
246  * So better keep them separated for now, I think. */
247 
253  int totvert,
254  struct MEdge *edges,
255  int totedge,
256  struct MPoly *polys,
257  int totpoly,
258  struct MLoop *loops,
259  int totloop,
260  MeshIslandStore *r_island_store);
261 
276  int totvert,
277  struct MEdge *edges,
278  int totedge,
279  struct MPoly *polys,
280  int totpoly,
281  struct MLoop *loops,
282  int totloop,
283  const struct MLoopUV *luvs,
284  MeshIslandStore *r_island_store);
285 
294 int *BKE_mesh_calc_smoothgroups(const struct MEdge *medge,
295  int totedge,
296  const struct MPoly *mpoly,
297  int totpoly,
298  const struct MLoop *mloop,
299  int totloop,
300  int *r_totgroup,
301  bool use_bitflags);
302 
303 /* use on looptri vertex values */
304 #define BKE_MESH_TESSTRI_VINDEX_ORDER(_tri, _v) \
305  ((CHECK_TYPE_ANY( \
306  _tri, unsigned int *, int *, int[3], const unsigned int *, const int *, const int[3]), \
307  CHECK_TYPE_ANY(_v, unsigned int, const unsigned int, int, const int)), \
308  (((_tri)[0] == _v) ? 0 : \
309  ((_tri)[1] == _v) ? 1 : \
310  ((_tri)[2] == _v) ? 2 : \
311  -1))
312 
313 #ifdef __cplusplus
314 }
315 #endif
void BKE_mesh_vert_edge_vert_map_create(MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, int totvert, int totedge)
UvMapVert * BKE_mesh_uv_vert_map_get_vert(UvVertMap *vmap, unsigned int v)
Definition: mesh_mapping.c:162
void BKE_mesh_loop_islands_init(MeshIslandStore *island_store, short item_type, int items_num, short island_type, short innercut_type)
Definition: mesh_mapping.c:815
struct MeshElemMap MeshElemMap
struct UvVertMap UvVertMap
int * BKE_mesh_calc_smoothgroups(const struct MEdge *medge, int totedge, const struct MPoly *mpoly, int totpoly, const struct MLoop *mloop, int totloop, int *r_totgroup, bool use_bitflags)
void BKE_mesh_loop_islands_add(MeshIslandStore *island_store, int item_num, const int *items_indices, int num_island_items, int *island_item_indices, int num_innercut_items, int *innercut_item_indices)
Definition: mesh_mapping.c:877
void BKE_mesh_vert_loop_map_create(MeshElemMap **r_map, int **r_mem, const struct MPoly *mpoly, const struct MLoop *mloop, int totvert, int totpoly, int totloop)
struct UvElement UvElement
void BKE_mesh_vert_poly_map_create(MeshElemMap **r_map, int **r_mem, const struct MPoly *mpoly, const struct MLoop *mloop, int totvert, int totpoly, int totloop)
UvVertMap * BKE_mesh_uv_vert_map_create(const struct MPoly *mpoly, const struct MLoop *mloop, const struct MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, const float limit[2], bool selected, bool use_winding)
void BKE_mesh_vert_looptri_map_create(MeshElemMap **r_map, int **r_mem, const struct MVert *mvert, int totvert, const struct MLoopTri *mlooptri, int totlooptri, const struct MLoop *mloop, int totloop)
void BKE_mesh_origindex_map_create(MeshElemMap **r_map, int **r_mem, int totsource, const int *final_origindex, int totfinal)
Definition: mesh_mapping.c:481
void BKE_mesh_loop_islands_clear(MeshIslandStore *island_store)
Definition: mesh_mapping.c:849
struct UvMapVert UvMapVert
@ MISLAND_TYPE_POLY
@ MISLAND_TYPE_VERT
@ MISLAND_TYPE_LOOP
@ MISLAND_TYPE_EDGE
@ MISLAND_TYPE_NONE
void BKE_mesh_uv_vert_map_free(UvVertMap *vmap)
Definition: mesh_mapping.c:167
struct UvElementMap UvElementMap
struct MeshIslandStore MeshIslandStore
void BKE_mesh_vert_edge_map_create(MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, int totvert, int totedge)
void BKE_mesh_edge_loop_map_create(MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, int totedge, const struct MPoly *mpoly, int totpoly, const struct MLoop *mloop, int totloop)
bool(* MeshRemapIslandsCalc)(struct MVert *verts, int totvert, struct MEdge *edges, int totedge, struct MPoly *polys, int totpoly, struct MLoop *loops, int totloop, struct MeshIslandStore *r_island_store)
bool BKE_mesh_calc_islands_loop_poly_edgeseam(struct MVert *verts, int totvert, struct MEdge *edges, int totedge, struct MPoly *polys, int totpoly, struct MLoop *loops, int totloop, MeshIslandStore *r_island_store)
void BKE_mesh_origindex_map_create_looptri(MeshElemMap **r_map, int **r_mem, const struct MPoly *mpoly, int mpoly_num, const struct MLoopTri *looptri, int looptri_num)
void BKE_mesh_loop_islands_free(MeshIslandStore *island_store)
Definition: mesh_mapping.c:869
void BKE_mesh_edge_poly_map_create(MeshElemMap **r_map, int **r_mem, const struct MEdge *medge, int totedge, const struct MPoly *mpoly, int totpoly, const struct MLoop *mloop, int totloop)
bool BKE_mesh_calc_islands_loop_poly_uvmap(struct MVert *verts, int totvert, struct MEdge *edges, int totedge, struct MPoly *polys, int totpoly, struct MLoop *loops, int totloop, const struct MLoopUV *luvs, MeshIslandStore *r_island_store)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static float verts[][3]
struct MemArena * mem
struct MeshElemMap ** innercuts
struct MeshElemMap ** islands
struct UvElement * buf
struct UvElement ** vert
unsigned char flag
unsigned int island
unsigned short loop_of_poly_index
struct UvElement * next
struct BMLoop * l
struct UvMapVert * next
unsigned short loop_of_poly_index
unsigned int poly_index
struct UvMapVert * buf
struct UvMapVert ** vert