Blender  V3.3
BKE_mesh_remap.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 struct CustomData;
15 struct MVert;
16 struct MemArena;
17 struct Mesh;
18 
19 /* Generic ways to map some geometry elements from a source mesh to a dest one. */
20 
21 typedef struct MeshPairRemapItem {
23  int *indices_src; /* NULL if no source found. */
24  float *weights_src; /* NULL if no source found, else, always normalized! */
25  /* UNUSED (at the moment). */
26  // float hit_dist; /* FLT_MAX if irrelevant or no source found. */
27  int island; /* For loops only. */
29 
30 /* All mapping computing func return this. */
31 typedef struct MeshPairRemap {
32  int items_num;
33  MeshPairRemapItem *items; /* array, one item per dest element. */
34 
35  struct MemArena *mem; /* memory arena, internal use only. */
37 
38 /* Helpers! */
39 void BKE_mesh_remap_init(MeshPairRemap *map, int items_num);
41 
43 
44 /* TODO:
45  * Add other 'from/to' mapping sources, like e.g. using a UVMap, etc.
46  * https://blenderartists.org/t/619105
47  *
48  * We could also use similar topology mappings inside a same mesh
49  * (cf. Campbell's 'select face islands from similar topology' wip work).
50  * Also, users will have to check, whether we can get rid of some modes here,
51  * not sure all will be useful!
52  */
53 enum {
54  MREMAP_USE_VERT = 1 << 4,
55  MREMAP_USE_EDGE = 1 << 5,
56  MREMAP_USE_LOOP = 1 << 6,
57  MREMAP_USE_POLY = 1 << 7,
58 
61  MREMAP_USE_INTERP = 1 << 10,
62  MREMAP_USE_NORMAL = 1 << 11,
63 
64  /* ***** Target's vertices ***** */
65  MREMAP_MODE_VERT = 1 << 24,
66  /* Nearest source vert. */
68 
69  /* Nearest vertex of nearest edge. */
71  /* This one uses two verts of selected edge (weighted interpolation). */
72  /* Nearest point on nearest edge. */
75 
76  /* Nearest vertex of nearest poly. */
78  /* Those two use all verts of selected poly (weighted interpolation). */
79  /* Nearest point on nearest poly. */
82  /* Point on nearest face hit by ray from target vertex's normal. */
85 
86  /* ***** Target's edges ***** */
87  MREMAP_MODE_EDGE = 1 << 25,
88 
89  /* Source edge which both vertices are nearest of dest ones. */
91 
92  /* Nearest source edge (using mid-point). */
94 
95  /* Nearest edge of nearest poly (using mid-point). */
97 
98  /* Cast a set of rays from along dest edge,
99  * interpolating its vertices' normals, and use hit source edges. */
102 
103  /* ***** Target's loops ***** */
104  /* NOTE: when islands are given to loop mapping func,
105  * all loops from the same destination face will always be mapped
106  * to loops of source faces within a same island, regardless of mapping mode. */
107  MREMAP_MODE_LOOP = 1 << 26,
108 
109  /* Best normal-matching loop from nearest vert. */
112  /* Loop from best normal-matching poly from nearest vert. */
115 
116  /* Loop from nearest vertex of nearest poly. */
118  /* Those two use all verts of selected poly (weighted interpolation). */
119  /* Nearest point on nearest poly. */
122  /* Point on nearest face hit by ray from target loop's normal. */
125 
126  /* ***** Target's polygons ***** */
127  MREMAP_MODE_POLY = 1 << 27,
128 
129  /* Nearest source poly. */
131  /* Source poly from best normal-matching dest poly. */
133 
134  /* Project dest poly onto source mesh using its normal,
135  * and use interpolation of all intersecting source polys. */
138 
139  /* ***** Same topology, applies to all four elements types. ***** */
141 };
142 
144  int vert_mode,
145  int edge_mode,
146  int loop_mode,
147  int poly_mode,
148  struct CustomData_MeshMasks *cddata_mask);
149 
160 float BKE_mesh_remap_calc_difference_from_mesh(const struct SpaceTransform *space_transform,
161  const struct MVert *verts_dst,
162  int numverts_dst,
163  struct Mesh *me_src);
164 
168 void BKE_mesh_remap_find_best_match_from_mesh(const struct MVert *verts_dst,
169  int numverts_dst,
170  struct Mesh *me_src,
171  struct SpaceTransform *r_space_transform);
172 
174  const struct SpaceTransform *space_transform,
175  float max_dist,
176  float ray_radius,
177  const struct MVert *verts_dst,
178  int numverts_dst,
179  bool dirty_nors_dst,
180  struct Mesh *me_src,
181  struct Mesh *me_dst,
182  MeshPairRemap *r_map);
183 
185  const struct SpaceTransform *space_transform,
186  float max_dist,
187  float ray_radius,
188  const struct MVert *verts_dst,
189  int numverts_dst,
190  const struct MEdge *edges_dst,
191  int numedges_dst,
192  bool dirty_nors_dst,
193  struct Mesh *me_src,
194  struct Mesh *me_dst,
195  MeshPairRemap *r_map);
196 
198  const struct SpaceTransform *space_transform,
199  float max_dist,
200  float ray_radius,
201  struct Mesh *mesh_dst,
202  struct MVert *verts_dst,
203  int numverts_dst,
204  struct MEdge *edges_dst,
205  int numedges_dst,
206  struct MLoop *loops_dst,
207  int numloops_dst,
208  struct MPoly *polys_dst,
209  int numpolys_dst,
210  struct CustomData *ldata_dst,
211  bool use_split_nors_dst,
212  float split_angle_dst,
213  bool dirty_nors_dst,
214  struct Mesh *me_src,
215  MeshRemapIslandsCalc gen_islands_src,
216  float islands_precision_src,
217  struct MeshPairRemap *r_map);
218 
220  const struct SpaceTransform *space_transform,
221  float max_dist,
222  float ray_radius,
223  struct Mesh *mesh_dst,
224  struct MVert *verts_dst,
225  struct MLoop *loops_dst,
226  struct MPoly *polys_dst,
227  int numpolys_dst,
228  struct Mesh *me_src,
229  struct MeshPairRemap *r_map);
230 
231 #ifdef __cplusplus
232 }
233 #endif
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)
void BKE_mesh_remap_init(MeshPairRemap *map, int items_num)
Definition: mesh_remap.c:326
void BKE_mesh_remap_calc_edges_from_mesh(int mode, const struct SpaceTransform *space_transform, float max_dist, float ray_radius, const struct MVert *verts_dst, int numverts_dst, const struct MEdge *edges_dst, int numedges_dst, bool dirty_nors_dst, struct Mesh *me_src, struct Mesh *me_dst, MeshPairRemap *r_map)
struct MeshPairRemapItem MeshPairRemapItem
struct MeshPairRemap MeshPairRemap
void BKE_mesh_remap_calc_verts_from_mesh(int mode, const struct SpaceTransform *space_transform, float max_dist, float ray_radius, const struct MVert *verts_dst, int numverts_dst, bool dirty_nors_dst, struct Mesh *me_src, struct Mesh *me_dst, MeshPairRemap *r_map)
float BKE_mesh_remap_calc_difference_from_mesh(const struct SpaceTransform *space_transform, const struct MVert *verts_dst, int numverts_dst, struct Mesh *me_src)
void BKE_mesh_remap_free(MeshPairRemap *map)
Definition: mesh_remap.c:338
void BKE_mesh_remap_find_best_match_from_mesh(const struct MVert *verts_dst, int numverts_dst, struct Mesh *me_src, struct SpaceTransform *r_space_transform)
void BKE_mesh_remap_item_define_invalid(MeshPairRemap *map, int index)
Definition: mesh_remap.c:379
void BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(int vert_mode, int edge_mode, int loop_mode, int poly_mode, struct CustomData_MeshMasks *cddata_mask)
void BKE_mesh_remap_calc_polys_from_mesh(int mode, const struct SpaceTransform *space_transform, float max_dist, float ray_radius, struct Mesh *mesh_dst, struct MVert *verts_dst, struct MLoop *loops_dst, struct MPoly *polys_dst, int numpolys_dst, struct Mesh *me_src, struct MeshPairRemap *r_map)
void BKE_mesh_remap_calc_loops_from_mesh(int mode, const struct SpaceTransform *space_transform, float max_dist, float ray_radius, struct Mesh *mesh_dst, struct MVert *verts_dst, int numverts_dst, struct MEdge *edges_dst, int numedges_dst, struct MLoop *loops_dst, int numloops_dst, struct MPoly *polys_dst, int numpolys_dst, struct CustomData *ldata_dst, bool use_split_nors_dst, float split_angle_dst, bool dirty_nors_dst, struct Mesh *me_src, MeshRemapIslandsCalc gen_islands_src, float islands_precision_src, struct MeshPairRemap *r_map)
@ MREMAP_MODE_VERT_EDGE_NEAREST
@ MREMAP_MODE_LOOP_POLYINTERP_NEAREST
@ MREMAP_MODE_VERT_POLYINTERP_VNORPROJ
@ MREMAP_MODE_LOOP
@ MREMAP_MODE_EDGE_POLY_NEAREST
@ MREMAP_MODE_POLY
@ MREMAP_MODE_VERT_EDGEINTERP_NEAREST
@ MREMAP_MODE_VERT_NEAREST
@ MREMAP_MODE_LOOP_NEAREST_POLYNOR
@ MREMAP_MODE_EDGE_VERT_NEAREST
@ MREMAP_USE_NORMAL
@ MREMAP_USE_LOOP
@ MREMAP_USE_INTERP
@ MREMAP_MODE_TOPOLOGY
@ MREMAP_MODE_VERT
@ MREMAP_USE_POLY
@ MREMAP_USE_NEAREST
@ MREMAP_MODE_EDGE
@ MREMAP_MODE_EDGE_NEAREST
@ MREMAP_MODE_POLY_NOR
@ MREMAP_USE_EDGE
@ MREMAP_MODE_LOOP_POLYINTERP_LNORPROJ
@ MREMAP_MODE_LOOP_NEAREST_LOOPNOR
@ MREMAP_MODE_LOOP_POLY_NEAREST
@ MREMAP_USE_NORPROJ
@ MREMAP_MODE_EDGE_EDGEINTERP_VNORPROJ
@ MREMAP_USE_VERT
@ MREMAP_MODE_POLY_POLYINTERP_PNORPROJ
@ MREMAP_MODE_VERT_POLY_NEAREST
@ MREMAP_MODE_POLY_NEAREST
@ MREMAP_MODE_VERT_POLYINTERP_NEAREST
SocketIndexByIdentifierMap * map
MeshPairRemapItem * items
struct MemArena * mem