Blender V5.3
bmesh_polygon.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
5#pragma once
6
10
11namespace blender {
12
13struct Heap;
15#include "BLI_compiler_attrs.hh"
17#include "BLI_span.hh"
18
22 * For tools that insist on using triangles, ideally we would cache this data.
23 *
24 * \param use_fixed_quad: When true,
25 * always split quad along (0 -> 2) regardless of concave corners,
26 * (as done in #BM_mesh_calc_tessellation).
27 * \param r_loops: Store face loop pointers, (f->len)
28 * \param r_index: Store triangle triples, indices into \a r_loops, `((f->len - 2) * 3)`
29 */
31 bool use_fixed_quad,
32 BMLoop **r_loops,
33 uint (*r_index)[3]);
34/**
35 * Return a point inside the face.
36 */
37void BM_face_calc_point_in_face(const BMFace *f, float r_co[3]);
40 * \brief BMESH UPDATE FACE NORMAL
41 *
42 * Updates the stored normal for the
43 * given face. Requires that a buffer
44 * of sufficient length to store projected
45 * coordinates for all of the face's vertices
46 * is passed in as well.
47 */
48float BM_face_calc_normal(const BMFace *f, float r_no[3]) ATTR_NONNULL();
49/* exact same as 'BM_face_calc_normal' but accepts vertex coords */
51 const BMFace *f,
52 float r_no[3],
57 */
59 BMVert **varr, int varr_len, float r_normal[3], float r_center[3], int *r_index_tangent);
60void BM_verts_calc_normal_from_cloud(BMVert **varr, int varr_len, float r_normal[3]);
62/**
63 * Calculates the face subset normal.
64 */
65float BM_face_calc_normal_subset(const BMLoop *l_first, const BMLoop *l_last, float r_no[3])
67/**
68 * get the area of the face
69 */
72 * Get the area of the face in world space.
73 */
74float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3]) ATTR_WARN_UNUSED_RESULT
90/**
91 * Calculate the perimeter of a ngon in world space.
92 */
94 const float mat3[3][3]) ATTR_WARN_UNUSED_RESULT
96/**
97 * Compute the tangent of the face, using the longest edge.
98 */
99void BM_face_calc_tangent_from_edge(const BMFace *f, float r_tangent[3]) ATTR_NONNULL();
101 float r_tangent_a[3],
102 float r_tangent_b[3]);
105 * Compute the tangent of the face, using the two longest disconnected edges.
107 * \param r_tangent: Calculated unit length tangent (return value).
108 */
109void BM_face_calc_tangent_from_edge_pair(const BMFace *f, float r_tangent[3]) ATTR_NONNULL();
110/**
111 * Compute the tangent of the face, using the edge farthest away from any vertex in the face.
113 * \param r_tangent: Calculated unit length tangent (return value).
114 */
117 * Compute the tangent of the face, using longest distance between vertices on the face.
119 * \note The logic is almost identical to #BM_face_calc_tangent_edge_diagonal
120 */
126 */
127void BM_face_calc_tangent_auto(const BMFace *f, float r_tangent[3]) ATTR_NONNULL();
129/**
130 * A version of BM_face_calc_tangent_auto that calculates two tangents.
131 * Useful when one may not be usable.
132 */
133void BM_face_calc_tangent_pair_auto(const BMFace *f, float r_tangent_a[3], float r_tangent_b[3])
138 */
139void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3]) ATTR_NONNULL();
140/**
141 * computes center of face in 3d. uses center of bounding box.
142 */
144 const BMFace *f,
145 float r_center[3],
146 Span<float3> vert_positions) ATTR_NONNULL();
148 * computes the center of a face, using the mean average
149 */
150void BM_face_calc_center_median(const BMFace *f, float r_center[3]) ATTR_NONNULL();
151/* exact same as 'BM_face_calc_normal' but accepts vertex coords */
153 const BMFace *f,
154 float r_center[3],
155 const Span<float3> vert_positions) ATTR_NONNULL();
158 * weighted by edge length
159 */
165void BM_face_calc_bounds_expand(const BMFace *f, float min[3], float max[3]);
169/**
170 * updates face and vertex normals incident on an edge
171 */
174bool BM_vert_calc_normal_ex(const BMVert *v, char hflag, float r_no[3]);
175bool BM_vert_calc_normal(const BMVert *v, float r_no[3]);
176/**
177 * update a vert normal (but not the faces incident on it)
178 */
183 * \brief Face Flip Normal
185 * Reverses the winding of a face.
186 * \note This updates the calculated normal.
187 */
189 BMFace *f,
190 int cd_loop_mdisp_offset,
191 bool use_loop_mdisp_flip) ATTR_NONNULL();
193
194/**
195 * BM POINT IN FACE
197 * Projects co onto face f, and returns true if it is inside
198 * the face bounds.
199 *
200 * \note this uses a best-axis projection test,
201 * instead of projecting co directly into f's orientation space,
202 * so there might be accuracy issues.
203 */
205 ATTR_NONNULL();
207/**
208 * \brief BMESH TRIANGULATE FACE
210 * Breaks all quads and ngons down to triangles.
211 * It uses poly-fill for the ngons splitting, and
212 * the beautify operator when use_beauty is true.
214 * \param r_faces_new: if non-null, must be an array of BMFace pointers,
215 * with a length equal to (f->len - 3). It will be filled with the new
216 * triangles (not including the original triangle).
218 * \param r_faces_double: When newly created faces are duplicates of existing faces,
219 * they're added to this list. Caller must handle de-duplication.
220 * This is done because its possible _all_ faces exist already,
221 * and in that case we would have to remove all faces including the one passed,
222 * which causes complications adding/removing faces while looking over them.
223 *
224 * \note The number of faces is _almost_ always (f->len - 3),
225 * However there may be faces that already occupying the
226 * triangles we would make, so the caller must check \a r_faces_new_tot.
228 * \note use_tag tags new flags and edges.
229 */
231 BMFace *f,
232 BMFace **r_faces_new,
233 int *r_faces_new_tot,
234 BMEdge **r_edges_new,
235 int *r_edges_new_tot,
236 struct LinkNode **r_faces_double,
237 int quad_method,
238 int ngon_method,
239 bool use_tag,
240 struct MemArena *pf_arena,
241 struct Heap *pf_heap) ATTR_NONNULL(1, 2);
243/**
244 * each pair of loops defines a new edge, a split. this function goes
245 * through and sets pairs that are geometrically invalid to null. a
246 * split is invalid, if it forms a concave angle or it intersects other
247 * edges in the face, or it intersects another split. in the case of
248 * intersecting splits, only the first of the set of intersecting
249 * splits survives
250 */
252/**
253 * This simply checks that the verts don't connect faces which would have more optimal splits.
254 * but _not_ check for correctness.
255 */
259 * Small utility functions for fast access
261 * faster alternative to:
262 * BM_iter_as_array(bm, BM_VERTS_OF_FACE, f, (void **)v, 3);
263 */
271/**
272 * Small utility functions for fast access
274 * faster alternative to:
275 * BM_iter_as_array(bm, BM_LOOPS_OF_FACE, f, (void **)l, 3);
276 */
279 * faster alternative to:
280 * BM_iter_as_array(bm, BM_LOOPS_OF_FACE, f, (void **)l, 4);
281 */
283
284/**
285 * Calculate a tangent from any 3 vertices.
287 * The tangent aligns to the most *unique* edge
288 * (the edge most unlike the other two).
290 * \param r_tangent: Calculated unit length tangent (return value).
291 */
292void BM_vert_tri_calc_tangent_from_edge(BMVert *verts[3], float r_tangent[3]);
294 float r_tangent_a[3],
295 float r_tangent_b[3]);
299
302 * \param r_tangent: Calculated unit length tangent (return value).
303 */
304void BM_vert_tri_calc_tangent_edge_pair(BMVert *verts[3], float r_tangent[3]);
306} // namespace blender
#define ATTR_NONNULL(...)
btScalar max
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
VecBase< float, 3 > float3
BMesh Iterators.
void BM_face_calc_tessellation(const BMFace *f, const bool use_fixed_quad, BMLoop **r_loops, uint(*r_index)[3])
void BM_face_calc_center_median(const BMFace *f, float r_cent[3])
float BM_face_calc_normal_subset(const BMLoop *l_first, const BMLoop *l_last, float r_no[3])
void BM_face_as_array_loop_quad(BMFace *f, BMLoop *r_loops[4])
void BM_face_normal_flip(BMesh *bm, BMFace *f)
unsigned int uint
Definition BKE_text.h:55
float BM_face_calc_perimeter_with_mat3(const BMFace *f, const float mat3[3][3])
void BM_face_as_array_vert_quad(BMFace *f, BMVert *r_verts[4])
float BM_face_calc_area_uv(const BMFace *f, int cd_loop_uv_offset)
void BM_face_calc_tangent_auto(const BMFace *f, float r_tangent[3])
void BM_face_calc_tangent_from_edge_diagonal(const BMFace *f, float r_tangent[3])
void BM_face_triangulate(BMesh *bm, BMFace *f, BMFace **r_faces_new, int *r_faces_new_tot, BMEdge **r_edges_new, int *r_edges_new_tot, LinkNode **r_faces_double, const int quad_method, const int ngon_method, const bool use_tag, MemArena *pf_arena, Heap *pf_heap)
BMESH TRIANGULATE FACE.
void BM_verts_calc_normal_from_cloud_ex(BMVert **varr, int varr_len, float r_normal[3], float r_center[3], int *r_index_tangent)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void BM_vert_tri_calc_tangent_edge_pair(BMVert *verts[3], float r_tangent[3])
void BM_verts_calc_normal_from_cloud(BMVert **varr, int varr_len, float r_normal[3])
void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3])
bool BM_face_point_inside_test(const BMFace *f, const float co[3])
void BM_vert_normal_update(BMVert *v)
void BM_face_calc_center_median_vcos(const BMesh *bm, const BMFace *f, float r_cent[3], const Span< float3 > vert_positions)
void BM_face_splits_check_optimal(BMFace *f, BMLoop *(*loops)[2], int len)
void BM_vert_tri_calc_tangent_pair_from_edge(BMVert *verts[3], float r_tangent_a[3], float r_tangent_b[3])
bool BM_vert_calc_normal_ex(const BMVert *v, const char hflag, float r_no[3])
float BM_face_calc_area(const BMFace *f)
void BM_face_normal_update(BMFace *f)
void BM_face_calc_tangent_pair_from_edge(const BMFace *f, float r_tangent_a[3], float r_tangent_b[3])
void BM_face_calc_center_bounds_vcos(const BMesh *bm, const BMFace *f, float r_cent[3], const Span< float3 > vert_positions)
void BM_vert_tri_calc_tangent_from_edge(BMVert *verts[3], float r_tangent[3])
void BM_vert_normal_update_all(BMVert *v)
void BM_face_calc_tangent_pair_auto(const BMFace *f, float r_tangent_a[3], float r_tangent_b[3])
float BM_face_calc_normal_vcos(const BMesh *bm, const BMFace *f, float r_no[3], const Span< float3 > vertexCos)
void BM_face_calc_tangent_from_vert_diagonal(const BMFace *f, float r_tangent[3])
void BM_edge_normals_update(BMEdge *e)
void BM_face_calc_point_in_face(const BMFace *f, float r_co[3])
float BM_face_calc_perimeter(const BMFace *f)
float BM_face_calc_area_uv_signed(const BMFace *f, int cd_loop_uv_offset)
void BM_face_calc_bounds_expand(const BMFace *f, float min[3], float max[3])
void BM_face_as_array_vert_tri(BMFace *f, BMVert *r_verts[3])
bool BM_vert_calc_normal(const BMVert *v, float r_no[3])
void BM_face_normal_flip_ex(BMesh *bm, BMFace *f, const int cd_loop_mdisp_offset, const bool use_loop_mdisp_flip)
Face Flip Normal.
float BM_face_calc_normal(const BMFace *f, float r_no[3])
BMESH UPDATE FACE NORMAL.
void BM_face_calc_tangent_from_edge_pair(const BMFace *f, float r_tangent[3])
bool ATTR_WARN_UNUSED_RESULT
void BM_face_as_array_loop_tri(BMFace *f, BMLoop *r_loops[3])
void ATTR_NONNULL(1, 2)
void BM_face_splits_check_legal(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len)
void BM_face_calc_center_median_weighted(const BMFace *f, float r_cent[3])
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BM_face_calc_tangent_from_edge(const BMFace *f, float r_tangent[3])
float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3])
#define min(a, b)
Definition sort.cc:38