2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): (mar-2001 nzc)
25 * ***** END GPL LICENSE BLOCK *****
27 #ifndef __BKE_MESH_MAPPING_H__
28 #define __BKE_MESH_MAPPING_H__
30 /** \file BKE_mesh_mapping.h
41 /* map from uv vertex to face (for select linked, stitch, uv suburf) */
44 #define STD_UV_CONNECT_LIMIT 0.0001f
46 typedef struct UvVertMap {
47 struct UvMapVert **vert;
48 struct UvMapVert *buf;
51 typedef struct UvMapVert {
52 struct UvMapVert *next;
53 unsigned int poly_index;
54 unsigned short loop_of_poly_index;
56 /* Zero-ed by map creation, left for use by specific areas. Is not
57 * initialized to anything. */
61 /* UvElement stores per uv information so that we can quickly access information for a uv.
62 * it is actually an improved UvMapVert, including an island and a direct pointer to the face
63 * to avoid initializing face arrays */
64 typedef struct UvElement {
65 /* Next UvElement corresponding to same vertex */
66 struct UvElement *next;
67 /* Face the element belongs to */
70 unsigned short loop_of_poly_index;
71 /* Whether this element is the first of coincident elements */
73 /* general use flag */
75 /* If generating element map with island sorting, this stores the island index */
80 /* UvElementMap is a container for UvElements of a mesh. It stores some UvElements belonging to the
81 * same uv island in sequence and the number of uvs per island so it is possible to access all uvs
82 * belonging to an island directly by iterating through the buffer.
84 typedef struct UvElementMap {
85 /* address UvElements by their vertex */
86 struct UvElement **vert;
88 struct UvElement *buf;
89 /* Total number of UVs in the layer. Useful to know */
91 /* Number of Islands in the mesh */
93 /* Stores the starting index in buf where each island begins */
97 #define INVALID_ISLAND ((unsigned int)-1)
99 /* Connectivity data */
100 typedef struct MeshElemMap {
106 UvVertMap *BKE_mesh_uv_vert_map_create(
107 const struct MPoly *mpoly, const struct MLoop *mloop, const struct MLoopUV *mloopuv,
108 unsigned int totpoly, unsigned int totvert, const float limit[2],
109 const bool selected, const bool use_winding);
110 UvMapVert *BKE_mesh_uv_vert_map_get_vert(UvVertMap *vmap, unsigned int v);
111 void BKE_mesh_uv_vert_map_free(UvVertMap *vmap);
113 void BKE_mesh_vert_poly_map_create(
114 MeshElemMap **r_map, int **r_mem,
115 const struct MPoly *mface, const struct MLoop *mloop,
116 int totvert, int totface, int totloop);
117 void BKE_mesh_vert_loop_map_create(
118 MeshElemMap **r_map, int **r_mem,
119 const struct MPoly *mface, const struct MLoop *mloop,
120 int totvert, int totface, int totloop);
121 void BKE_mesh_vert_looptri_map_create(
122 MeshElemMap **r_map, int **r_mem,
123 const struct MVert *mvert, const int totvert,
124 const struct MLoopTri *mlooptri, const int totlooptri,
125 const struct MLoop *mloop, const int totloop);
126 void BKE_mesh_vert_edge_map_create(
127 MeshElemMap **r_map, int **r_mem,
128 const struct MEdge *medge, int totvert, int totedge);
129 void BKE_mesh_vert_edge_vert_map_create(
130 MeshElemMap **r_map, int **r_mem,
131 const struct MEdge *medge, int totvert, int totedge);
132 void BKE_mesh_edge_loop_map_create(
133 MeshElemMap **r_map, int **r_mem,
134 const struct MEdge *medge, const int totedge,
135 const struct MPoly *mpoly, const int totpoly,
136 const struct MLoop *mloop, const int totloop);
137 void BKE_mesh_edge_poly_map_create(
138 MeshElemMap **r_map, int **r_mem,
139 const struct MEdge *medge, const int totedge,
140 const struct MPoly *mpoly, const int totpoly,
141 const struct MLoop *mloop, const int totloop);
142 void BKE_mesh_origindex_map_create(
143 MeshElemMap **r_map, int **r_mem,
145 const int *final_origindex, const int totfinal);
146 void BKE_mesh_origindex_map_create_looptri(
147 MeshElemMap **r_map, int **r_mem,
148 const struct MPoly *mpoly, const int mpoly_num,
149 const struct MLoopTri *looptri, const int looptri_num);
153 /* Loop islands data helpers. */
155 MISLAND_TYPE_NONE = 0,
156 MISLAND_TYPE_VERT = 1,
157 MISLAND_TYPE_EDGE = 2,
158 MISLAND_TYPE_POLY = 3,
159 MISLAND_TYPE_LOOP = 4,
162 typedef struct MeshIslandStore {
163 short item_type; /* MISLAND_TYPE_... */
164 short island_type; /* MISLAND_TYPE_... */
165 short innercut_type; /* MISLAND_TYPE_... */
167 int items_to_islands_num;
168 int *items_to_islands; /* map the item to the island index */
171 size_t islands_num_alloc;
172 struct MeshElemMap **islands; /* Array of pointers, one item per island. */
173 struct MeshElemMap **innercuts; /* Array of pointers, one item per island. */
175 struct MemArena *mem; /* Memory arena, internal use only. */
178 void BKE_mesh_loop_islands_init(
179 MeshIslandStore *island_store,
180 const short item_type, const int item_num, const short island_type, const short innercut_type);
181 void BKE_mesh_loop_islands_clear(MeshIslandStore *island_store);
182 void BKE_mesh_loop_islands_free(MeshIslandStore *island_store);
183 void BKE_mesh_loop_islands_add(
184 MeshIslandStore *islands, const int item_num, int *item_indices,
185 const int num_island_items, int *island_item_indices,
186 const int num_innercut_items, int *innercut_item_indices);
188 typedef bool (*MeshRemapIslandsCalc)(
189 struct MVert *verts, const int totvert,
190 struct MEdge *edges, const int totedge,
191 struct MPoly *polys, const int totpoly,
192 struct MLoop *loops, const int totloop,
193 struct MeshIslandStore *r_island_store);
195 /* Above vert/UV mapping stuff does not do what we need here, but does things we do not need here.
196 * So better keep them separated for now, I think.
198 bool BKE_mesh_calc_islands_loop_poly_edgeseam(
199 struct MVert *verts, const int totvert,
200 struct MEdge *edges, const int totedge,
201 struct MPoly *polys, const int totpoly,
202 struct MLoop *loops, const int totloop,
203 MeshIslandStore *r_island_store);
205 bool BKE_mesh_calc_islands_loop_poly_uvmap(
206 struct MVert *verts, const int totvert,
207 struct MEdge *edges, const int totedge,
208 struct MPoly *polys, const int totpoly,
209 struct MLoop *loops, const int totloop,
210 const struct MLoopUV *luvs,
211 MeshIslandStore *r_island_store);
213 int *BKE_mesh_calc_smoothgroups(
214 const struct MEdge *medge, const int totedge,
215 const struct MPoly *mpoly, const int totpoly,
216 const struct MLoop *mloop, const int totloop,
217 int *r_totgroup, const bool use_bitflags);
219 /* No good (portable) way to have exported inlined functions... */
220 #define BKE_MESH_TESSFACE_VINDEX_ORDER(_mf, _v) ( \
221 (CHECK_TYPE_INLINE(_mf, MFace *), \
222 CHECK_TYPE_INLINE(&(_v), unsigned int *)), \
223 ((_mf->v1 == _v) ? 0 : \
224 (_mf->v2 == _v) ? 1 : \
225 (_mf->v3 == _v) ? 2 : \
226 (_mf->v4 && _mf->v4 == _v) ? 3 : -1) \
229 /* use on looptri vertex values */
230 #define BKE_MESH_TESSTRI_VINDEX_ORDER(_tri, _v) ( \
231 (CHECK_TYPE_ANY(_tri, unsigned int *, int *, int[3], \
232 const unsigned int *, const int *, const int[3]), \
233 CHECK_TYPE_ANY(_v, unsigned int, const unsigned int, int, const int)), \
234 (((_tri)[0] == _v) ? 0 : \
235 ((_tri)[1] == _v) ? 1 : \
236 ((_tri)[2] == _v) ? 2 : -1) \
239 #endif /* __BKE_MESH_MAPPING_H__ */