Blender V4.3
BKE_mesh.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
11#include "BLI_index_mask_fwd.hh"
12#include "BLI_offset_indices.hh"
13#include "BLI_string_ref.hh"
14
15#include "BKE_mesh.h"
16#include "BKE_mesh_types.hh"
17
18namespace blender::bke {
19
20enum class AttrDomain : int8_t;
21
22namespace mesh {
23/* -------------------------------------------------------------------- */
28float3 face_normal_calc(Span<float3> vert_positions, Span<int> face_verts);
29
30void corner_tris_calc(Span<float3> vert_positions,
32 Span<int> corner_verts,
33 MutableSpan<int3> corner_tris);
34
44 Span<int> corner_verts,
45 Span<float3> face_normals,
46 MutableSpan<int3> corner_tris);
47
49
54 Span<int3> corner_tris,
55 MutableSpan<int3> vert_tris);
56
59 Span<int> corner_verts,
60 Span<int> corner_edges,
61 const int3 &corner_tri);
62
64float3 face_center_calc(Span<float3> vert_positions, Span<int> face_verts);
65
67float face_area_calc(Span<float3> vert_positions, Span<int> face_verts);
68
70void face_angles_calc(Span<float3> vert_positions,
71 Span<int> face_verts,
72 MutableSpan<float> angles);
73
76/* -------------------------------------------------------------------- */
86void normals_calc_faces(Span<float3> vert_positions,
88 Span<int> corner_verts,
89 MutableSpan<float3> face_normals);
90
100void normals_calc_verts(Span<float3> vert_positions,
101 OffsetIndices<int> faces,
102 Span<int> corner_verts,
103 GroupedSpan<int> vert_to_face_map,
104 Span<float3> face_normals,
105 MutableSpan<float3> vert_normals);
106
109/* -------------------------------------------------------------------- */
130
157
159 const float3 &custom_lnor);
160
172void normals_calc_corners(Span<float3> vert_positions,
173 Span<int2> edges,
174 OffsetIndices<int> faces,
175 Span<int> corner_verts,
176 Span<int> corner_edges,
177 Span<int> corner_to_face_map,
178 Span<float3> vert_normals,
179 Span<float3> face_normals,
180 Span<bool> sharp_edges,
181 Span<bool> sharp_faces,
182 const short2 *clnors_data,
183 CornerNormalSpaceArray *r_lnors_spacearr,
184 MutableSpan<float3> r_corner_normals);
185
189void normals_corner_custom_set(Span<float3> vert_positions,
190 Span<int2> edges,
191 OffsetIndices<int> faces,
192 Span<int> corner_verts,
193 Span<int> corner_edges,
194 Span<float3> vert_normals,
195 Span<float3> face_normals,
196 Span<bool> sharp_faces,
197 MutableSpan<bool> sharp_edges,
198 MutableSpan<float3> r_custom_corner_normals,
199 MutableSpan<short2> r_clnors_data);
200
205 Span<int2> edges,
206 OffsetIndices<int> faces,
207 Span<int> corner_verts,
208 Span<int> corner_edges,
209 Span<float3> vert_normals,
210 Span<float3> face_normals,
211 Span<bool> sharp_faces,
212 MutableSpan<bool> sharp_edges,
213 MutableSpan<float3> r_custom_vert_normals,
214 MutableSpan<short2> r_clnors_data);
215
225 Span<int> corner_verts,
226 Span<int> corner_edges,
227 Span<float3> face_normals,
228 Span<int> corner_to_face,
229 Span<bool> sharp_faces,
230 const float split_angle,
231 MutableSpan<bool> sharp_edges);
232
235/* -------------------------------------------------------------------- */
243inline int face_corner_prev(const IndexRange face, const int corner)
244{
245 return corner - 1 + (corner == face.start()) * face.size();
246}
247
252inline int face_corner_next(const IndexRange face, const int corner)
253{
254 if (corner == face.last()) {
255 return face.start();
256 }
257 return corner + 1;
258}
259
265 const Span<int> corner_verts,
266 const int vert)
267{
268 return face[corner_verts.slice(face).first_index(vert)];
269}
270
276 const Span<int> corner_verts,
277 const int vert)
278{
279 const int corner = face_find_corner_from_vert(face, corner_verts, vert);
280 return {corner_verts[face_corner_prev(face, corner)],
281 corner_verts[face_corner_next(face, corner)]};
282}
283
287inline int face_triangles_num(const int face_size)
288{
289 BLI_assert(face_size > 2);
290 return face_size - 2;
291}
292
297{
298 const IndexRange face = faces[face_i];
299 /* This is the same as #poly_to_tri_count which is not included here. */
300 const int start_triangle = face.start() - face_i * 2;
301 return IndexRange(start_triangle, face_triangles_num(face.size()));
302}
303
307inline int edge_other_vert(const int2 edge, const int vert)
308{
309 BLI_assert(ELEM(vert, edge[0], edge[1]));
310 BLI_assert(edge[0] >= 0);
311 BLI_assert(edge[1] >= 0);
312 /* Order is important to avoid overflow. */
313 return (edge[0] - vert) + edge[1];
314}
315
318} // namespace mesh
319
321Mesh *mesh_new_no_attributes(int verts_num, int edges_num, int faces_num, int corners_num);
322
324void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges);
325
326void mesh_flip_faces(Mesh &mesh, const IndexMask &selection);
327
329
331void mesh_vert_normals_assign(Mesh &mesh, Span<float3> vert_normals);
332
334void mesh_vert_normals_assign(Mesh &mesh, Vector<float3> vert_normals);
335
336void mesh_smooth_set(Mesh &mesh, bool use_smooth, bool keep_sharp_edges = false);
337void mesh_sharp_edges_set_from_angle(Mesh &mesh, float angle, bool keep_sharp_edges = false);
338
342void mesh_edge_hide_from_vert(Span<int2> edges, Span<bool> hide_vert, MutableSpan<bool> hide_edge);
343
344/* Hide faces when any of their vertices are hidden. */
346 Span<int> corner_verts,
347 Span<bool> hide_vert,
348 MutableSpan<bool> hide_poly);
349
351void mesh_hide_vert_flush(Mesh &mesh);
353void mesh_hide_face_flush(Mesh &mesh);
354
356void mesh_select_vert_flush(Mesh &mesh);
358void mesh_select_edge_flush(Mesh &mesh);
360void mesh_select_face_flush(Mesh &mesh);
361
364 StringRef id,
365 AttrDomain domain,
366 eCustomDataType data_type);
367
368void mesh_data_update(Depsgraph &depsgraph,
369 const Scene &scene,
370 Object &ob,
371 const CustomData_MeshMasks &dataMask);
372
373} // namespace blender::bke
#define BLI_assert(a)
Definition BLI_assert.h:50
#define ELEM(...)
constexpr int64_t start() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:138
constexpr int64_t first_index(const T &search_value) const
Definition BLI_span.hh:378
const Depsgraph * depsgraph
void normals_corner_custom_set_from_verts(Span< float3 > vert_positions, Span< int2 > edges, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, Span< float3 > vert_normals, Span< float3 > face_normals, Span< bool > sharp_faces, MutableSpan< bool > sharp_edges, MutableSpan< float3 > r_custom_vert_normals, MutableSpan< short2 > r_clnors_data)
int edge_other_vert(const int2 edge, const int vert)
Definition BKE_mesh.hh:307
void face_angles_calc(Span< float3 > vert_positions, Span< int > face_verts, MutableSpan< float > angles)
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
float face_area_calc(Span< float3 > vert_positions, Span< int > face_verts)
int face_corner_prev(const IndexRange face, const int corner)
Definition BKE_mesh.hh:243
int face_triangles_num(const int face_size)
Definition BKE_mesh.hh:287
int face_find_corner_from_vert(const IndexRange face, const Span< int > corner_verts, const int vert)
Definition BKE_mesh.hh:264
void corner_tris_calc(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< int3 > corner_tris)
void normals_calc_corners(Span< float3 > vert_positions, Span< int2 > edges, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, Span< int > corner_to_face_map, Span< float3 > vert_normals, Span< float3 > face_normals, Span< bool > sharp_edges, Span< bool > sharp_faces, const short2 *clnors_data, CornerNormalSpaceArray *r_lnors_spacearr, MutableSpan< float3 > r_corner_normals)
int3 corner_tri_get_real_edges(Span< int2 > edges, Span< int > corner_verts, Span< int > corner_edges, const int3 &corner_tri)
int2 face_find_adjacent_verts(const IndexRange face, const Span< int > corner_verts, const int vert)
Definition BKE_mesh.hh:275
void vert_tris_from_corner_tris(Span< int > corner_verts, Span< int3 > corner_tris, MutableSpan< int3 > vert_tris)
IndexRange face_triangles_range(OffsetIndices< int > faces, int face_i)
Definition BKE_mesh.hh:296
float3 face_center_calc(Span< float3 > vert_positions, Span< int > face_verts)
void normals_corner_custom_set(Span< float3 > vert_positions, Span< int2 > edges, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, Span< float3 > vert_normals, Span< float3 > face_normals, Span< bool > sharp_faces, MutableSpan< bool > sharp_edges, MutableSpan< float3 > r_custom_corner_normals, MutableSpan< short2 > r_clnors_data)
void corner_tris_calc_with_normals(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< float3 > face_normals, MutableSpan< int3 > corner_tris)
void corner_tris_calc_face_indices(OffsetIndices< int > faces, MutableSpan< int > tri_faces)
short2 corner_space_custom_normal_to_data(const CornerNormalSpace &lnor_space, const float3 &custom_lnor)
void edges_sharp_from_angle_set(OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, Span< float3 > face_normals, Span< int > corner_to_face, Span< bool > sharp_faces, const float split_angle, MutableSpan< bool > sharp_edges)
int face_corner_next(const IndexRange face, const int corner)
Definition BKE_mesh.hh:252
void normals_calc_verts(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face_map, Span< float3 > face_normals, MutableSpan< float3 > vert_normals)
void normals_calc_faces(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< float3 > face_normals)
void mesh_select_vert_flush(Mesh &mesh)
void mesh_sharp_edges_set_from_angle(Mesh &mesh, float angle, bool keep_sharp_edges=false)
void mesh_face_hide_from_vert(OffsetIndices< int > faces, Span< int > corner_verts, Span< bool > hide_vert, MutableSpan< bool > hide_poly)
void mesh_hide_vert_flush(Mesh &mesh)
void mesh_hide_face_flush(Mesh &mesh)
void mesh_smooth_set(Mesh &mesh, bool use_smooth, bool keep_sharp_edges=false)
void mesh_ensure_default_color_attribute_on_add(Mesh &mesh, StringRef id, AttrDomain domain, eCustomDataType data_type)
void mesh_flip_faces(Mesh &mesh, const IndexMask &selection)
void mesh_select_edge_flush(Mesh &mesh)
Mesh * mesh_new_no_attributes(int verts_num, int edges_num, int faces_num, int corners_num)
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
void mesh_vert_normals_assign(Mesh &mesh, Span< float3 > vert_normals)
void mesh_ensure_required_data_layers(Mesh &mesh)
void mesh_data_update(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask)
void mesh_edge_hide_from_vert(Span< int2 > edges, Span< bool > hide_vert, MutableSpan< bool > hide_edge)
void mesh_select_face_flush(Mesh &mesh)
signed char int8_t
Definition stdint.h:75
Array< CornerNormalSpace > spaces
Definition BKE_mesh.hh:141