Blender V5.3
pbvh_uv_islands.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
21
22#pragma once
23
24#include <optional>
25
26#include "BLI_array.hh"
27#include "BLI_map.hh"
29#include "BLI_offset_indices.hh"
30#include "BLI_vector.hh"
31#include "BLI_vector_list.hh"
32
34
35struct UVBorder;
36struct UVEdge;
37struct UVIslandsMask;
38struct UVPrimitive;
39struct MeshData;
40struct UVIsland;
41struct UVVert;
42
84
85struct UVVert {
86 int vert;
87 /* Position in uv space. */
89
90 /* uv edges that share this UVVert. */
92
93 struct {
94 bool is_border : 1;
95 bool is_extended : 1;
97
98 explicit UVVert();
99 explicit UVVert(const MeshData &mesh_data, int corner);
100};
101
102struct UVEdge {
103 std::array<int, 2> verts;
105 bool is_border = false;
106
107 int get_other_uv_vert(const UVIsland &island, int vert);
108 bool has_same_verts(const UVIsland &island, const int2 &edge) const;
109
110 private:
111 bool has_same_verts(const UVIsland &island, int vert1, int vert2) const;
112};
113
119 std::array<int, 3> edges;
120
121 explicit UVPrimitive(int primitive_i);
122
126 int get_uv_vert(const UVIsland &island,
127 const MeshData &mesh_data,
128 uint8_t mesh_vert_index) const;
129
134 int get_uv_edge(const UVIsland &island, float2 uv1, float2 uv2) const;
135 int get_uv_edge(const UVIsland &island, int v1, int v2) const;
136
137 bool contains_uv_vert(const UVIsland &island, const int uv_vert) const;
138 int get_other_uv_vert(const UVIsland &island, const int v1, const int v2) const;
139};
140
143 /* Index into UVIsland::uv_primitives. */
145 /* Should the vertices of the edge be evaluated in reverse order. */
146 bool reverse_order = false;
147 bool removed = false;
148
149 /* Previous and next edge, forming a double linked list. */
150 UVBorderEdge *prev = nullptr;
151 UVBorderEdge *next = nullptr;
153 /* Stable ID for tie-break in the priority queue. */
155
156 explicit UVBorderEdge(int uv_edge_i, int uv_primitive);
157
158 int get_uv_vert(const UVIsland &island, int index) const;
159
163 int get_other_uv_vert(const UVIsland &island) const;
164
165 bool is_extendable(const UVIsland &island) const;
166
167 float length(const UVIsland &island) const;
168};
169
173 float angle;
174
176
183 float2 uv(const UVIsland &island, float factor, float min_uv_distance);
184
191 bool connected_in_mesh(const UVIsland &island) const;
192 void print_debug(const UVIsland &island) const;
193};
194
195struct UVBorder {
198 /* Edges added by border extension. */
200
204 bool is_ccw(const UVIsland &island) const;
205
209 void flip_order();
210
214 float outside_angle(const UVIsland &island, const UVBorderEdge &edge) const;
215
217 void setup_links(int64_t border_index);
218};
219
220struct UVIsland {
226 int id;
237
243
244 int lookup(const UVVert &vert);
245 int lookup_or_create(const UVVert &vert);
246 int lookup(const UVEdge &edge);
247 int lookup_or_create(const UVEdge &edge);
248
250 void extract_borders();
252 void extend_border(const MeshData &mesh_data, const UVIslandsMask &mask, short island_index);
253
255 void print_debug(const MeshData &mesh_data) const;
256};
257
259 GroupedSpan<int> tris_by_island,
260 const UVIslandsMask &uv_masks);
261
264
266 struct Tile {
271
273
275 bool is_masked(uint16_t island_index, float2 uv) const;
277 bool is_masked(const uint16_t island_index, const int mask_x, const int mask_y) const
278 {
279 return mask[int64_t(mask_y) * mask_resolution.x + mask_x] == island_index;
280 }
281 bool contains(float2 uv) const;
282 float get_pixel_size_in_uv_space() const;
283 };
284
286
287 void add_tile(float2 udim_offset, ushort2 resolution);
288
292 const Tile *find_tile(float2 uv) const;
293
300 bool is_masked(uint16_t island_index, float2 uv) const;
301
306 void add(const MeshData &mesh_data, GroupedSpan<int> tris_by_island);
307
308 void dilate(int max_iterations);
309};
310
311} // namespace blender::bke::pbvh::uv_islands
Tile()=default
Array< UVIsland > build_uv_islands(const MeshData &mesh_data, const GroupedSpan< int > tris_by_island, const UVIslandsMask &uv_masks)
__int64 int64_t
Definition BKE_text.h:90
unsigned short uint16_t
Definition BKE_text.h:80
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
unsigned char uint8_t
Definition BKE_text.h:79
VecBase< uint16_t, 2 > ushort2
ATTR_WARN_UNUSED_RESULT const BMVert * v2
bool is_edge_manifold(const int edge_id) const
MeshData(OffsetIndices< int > faces, Span< int3 > corner_tris, Span< int > corner_verts, Span< int > corner_edges, Span< int2 > mesh_edges, GroupedSpan< int > vert_to_face_map, Span< float2 > uv_map, Span< float3 > vert_positions)
void print_debug(const UVIsland &island) const
bool connected_in_mesh(const UVIsland &island) const
float2 uv(const UVIsland &island, float factor, float min_uv_distance)
UVBorderCorner(UVBorderEdge *first, UVBorderEdge *second, float angle)
int get_other_uv_vert(const UVIsland &island) const
UVBorderEdge(int uv_edge_i, int uv_primitive)
int get_uv_vert(const UVIsland &island, int index) const
bool is_extendable(const UVIsland &island) const
float length(const UVIsland &island) const
VectorList< UVBorderEdge > edges_extend_border
float outside_angle(const UVIsland &island, const UVBorderEdge &edge) const
bool is_ccw(const UVIsland &island) const
bool has_same_verts(const UVIsland &island, const int2 &edge) const
int get_other_uv_vert(const UVIsland &island, int vert)
void print_debug(const MeshData &mesh_data) const
void extend_border(const MeshData &mesh_data, const UVIslandsMask &mask, short island_index)
bool is_masked(uint16_t island_index, float2 uv) const
Tile(float2 udim_offset, ushort2 tile_resolution)
bool is_masked(const uint16_t island_index, const int mask_x, const int mask_y) const
bool is_masked(uint16_t island_index, float2 uv) const
void add(const MeshData &mesh_data, GroupedSpan< int > tris_by_island)
void add_tile(float2 udim_offset, ushort2 resolution)
int get_uv_vert(const UVIsland &island, const MeshData &mesh_data, uint8_t mesh_vert_index) const
int get_other_uv_vert(const UVIsland &island, const int v1, const int v2) const
bool contains_uv_vert(const UVIsland &island, const int uv_vert) const
int get_uv_edge(const UVIsland &island, float2 uv1, float2 uv2) const
struct blender::bke::pbvh::uv_islands::UVVert::@006002110014127050064304055317211247224121323337 flags