Blender V4.5
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
10
11#include "BLI_index_mask_fwd.hh"
13#include "BLI_offset_indices.hh"
14#include "BLI_string_ref.hh"
15
16#include "BKE_mesh.h" // IWYU pragma: export
17#include "BKE_mesh_types.hh" // IWYU pragma: export
18
19namespace blender::bke {
20
21enum class AttrDomain : int8_t;
23
24namespace mesh {
25/* -------------------------------------------------------------------- */
28
30float3 face_normal_calc(Span<float3> vert_positions, Span<int> face_verts);
31
32void corner_tris_calc(Span<float3> vert_positions,
34 Span<int> corner_verts,
35 MutableSpan<int3> corner_tris);
36
46 Span<int> corner_verts,
47 Span<float3> face_normals,
48 MutableSpan<int3> corner_tris);
49
51
56 Span<int3> corner_tris,
57 MutableSpan<int3> vert_tris);
58
61 Span<int> corner_verts,
62 Span<int> corner_edges,
63 const int3 &corner_tri);
64
66float3 face_center_calc(Span<float3> vert_positions, Span<int> face_verts);
67
69float face_area_calc(Span<float3> vert_positions, Span<int> face_verts);
70
72void face_angles_calc(Span<float3> vert_positions,
73 Span<int> face_verts,
74 MutableSpan<float> angles);
75
77
78/* -------------------------------------------------------------------- */
81
88void normals_calc_faces(Span<float3> vert_positions,
90 Span<int> corner_verts,
91 MutableSpan<float3> face_normals);
92
102void normals_calc_verts(Span<float3> vert_positions,
104 Span<int> corner_verts,
105 GroupedSpan<int> vert_to_face_map,
106 Span<float3> face_normals,
107 MutableSpan<float3> vert_normals);
108
110
111/* -------------------------------------------------------------------- */
114
148
182
184 const float3 &custom_lnor);
185
197void normals_calc_corners(Span<float3> vert_positions,
199 Span<int> corner_verts,
200 Span<int> corner_edges,
201 GroupedSpan<int> vert_to_face_map,
202 Span<float3> face_normals,
203 Span<bool> sharp_edges,
204 Span<bool> sharp_faces,
205 Span<short2> custom_normals,
206 CornerNormalSpaceArray *r_fan_spaces,
207 MutableSpan<float3> r_corner_normals);
208
212void normals_corner_custom_set(Span<float3> vert_positions,
214 Span<int> corner_verts,
215 Span<int> corner_edges,
216 GroupedSpan<int> vert_to_face_map,
217 Span<float3> vert_normals,
218 Span<float3> face_normals,
219 Span<bool> sharp_faces,
220 MutableSpan<bool> sharp_edges,
221 MutableSpan<float3> r_custom_corner_normals,
222 MutableSpan<short2> r_clnors_data);
223
229 Span<int> corner_verts,
230 Span<int> corner_edges,
231 GroupedSpan<int> vert_to_face_map,
232 Span<float3> vert_normals,
233 Span<float3> face_normals,
234 Span<bool> sharp_faces,
235 MutableSpan<bool> sharp_edges,
236 MutableSpan<float3> r_custom_vert_normals,
237 MutableSpan<short2> r_clnors_data);
238
248 Span<int> corner_verts,
249 Span<int> corner_edges,
250 Span<float3> face_normals,
251 Span<int> corner_to_face,
252 Span<bool> sharp_faces,
253 const float split_angle,
254 MutableSpan<bool> sharp_edges);
255
256} // namespace mesh
257
267
277
279
280/* -------------------------------------------------------------------- */
283
284namespace mesh {
285
290inline int face_corner_prev(const IndexRange face, const int corner)
291{
292 return corner - 1 + (corner == face.start()) * face.size();
293}
294
299inline int face_corner_next(const IndexRange face, const int corner)
300{
301 if (corner == face.last()) {
302 return face.start();
303 }
304 return corner + 1;
305}
306
312 const Span<int> corner_verts,
313 const int vert)
314{
315 return face[corner_verts.slice(face).first_index(vert)];
316}
317
323 const Span<int> corner_verts,
324 const int vert)
325{
326 const int corner = face_find_corner_from_vert(face, corner_verts, vert);
327 return {corner_verts[face_corner_prev(face, corner)],
328 corner_verts[face_corner_next(face, corner)]};
329}
330
334inline int face_triangles_num(const int face_size)
335{
336 BLI_assert(face_size > 2);
337 return face_size - 2;
338}
339
344{
345 const IndexRange face = faces[face_i];
346 /* This is the same as #poly_to_tri_count which is not included here. */
347 const int start_triangle = face.start() - face_i * 2;
348 return IndexRange(start_triangle, face_triangles_num(face.size()));
349}
350
354inline int edge_other_vert(const int2 edge, const int vert)
355{
356 BLI_assert(ELEM(vert, edge[0], edge[1]));
357 BLI_assert(edge[0] >= 0);
358 BLI_assert(edge[1] >= 0);
359 /* Order is important to avoid overflow. */
360 return (edge[0] - vert) + edge[1];
361}
362
364
365} // namespace mesh
366
368Mesh *mesh_new_no_attributes(int verts_num, int edges_num, int faces_num, int corners_num);
369
371void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges);
372
373void mesh_translate(Mesh &mesh, const float3 &translation, bool do_shape_keys);
374
375void mesh_transform(Mesh &mesh, const float4x4 &transform, bool do_shape_keys);
376
377void mesh_flip_faces(Mesh &mesh, const IndexMask &selection);
378
380
382void mesh_vert_normals_assign(Mesh &mesh, Span<float3> vert_normals);
383
385void mesh_vert_normals_assign(Mesh &mesh, Vector<float3> vert_normals);
386
387void mesh_smooth_set(Mesh &mesh, bool use_smooth, bool keep_sharp_edges = false);
388void mesh_sharp_edges_set_from_angle(Mesh &mesh, float angle, bool keep_sharp_edges = false);
389
393void mesh_edge_hide_from_vert(Span<int2> edges, Span<bool> hide_vert, MutableSpan<bool> hide_edge);
394
395/* Hide faces when any of their vertices are hidden. */
397 Span<int> corner_verts,
398 Span<bool> hide_vert,
399 MutableSpan<bool> hide_poly);
400
402void mesh_hide_vert_flush(Mesh &mesh);
404void mesh_hide_face_flush(Mesh &mesh);
405
407void mesh_select_vert_flush(Mesh &mesh);
409void mesh_select_edge_flush(Mesh &mesh);
411void mesh_select_face_flush(Mesh &mesh);
412
415 StringRef id,
416 AttrDomain domain,
417 eCustomDataType data_type);
418
419void mesh_data_update(Depsgraph &depsgraph,
420 const Scene &scene,
421 Object &ob,
422 const CustomData_MeshMasks &dataMask);
423
426
427const AttributeAccessorFunctions &mesh_attribute_accessor_functions();
428
429} // namespace blender::bke
#define BLI_assert(a)
Definition BLI_assert.h:46
#define ELEM(...)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
AttrDomain
BPy_StructRNA * depsgraph
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr int64_t start() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:137
constexpr int64_t first_index(const T &search_value) const
Definition BLI_span.hh:377
static char faces[256]
int edge_other_vert(const int2 edge, const int vert)
Definition BKE_mesh.hh:354
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:290
int face_triangles_num(const int face_size)
Definition BKE_mesh.hh:334
int face_find_corner_from_vert(const IndexRange face, const Span< int > corner_verts, const int vert)
Definition BKE_mesh.hh:311
void corner_tris_calc(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< int3 > corner_tris)
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:322
void normals_calc_corners(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, GroupedSpan< int > vert_to_face_map, Span< float3 > face_normals, Span< bool > sharp_edges, Span< bool > sharp_faces, Span< short2 > custom_normals, CornerNormalSpaceArray *r_fan_spaces, MutableSpan< float3 > r_corner_normals)
void vert_tris_from_corner_tris(Span< int > corner_verts, Span< int3 > corner_tris, MutableSpan< int3 > vert_tris)
void normals_corner_custom_set_from_verts(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, GroupedSpan< int > vert_to_face_map, 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)
IndexRange face_triangles_range(OffsetIndices< int > faces, int face_i)
Definition BKE_mesh.hh:343
float3 face_center_calc(Span< float3 > vert_positions, Span< int > face_verts)
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:299
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_corner_custom_set(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, GroupedSpan< int > vert_to_face_map, 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 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)
const AttributeAccessorFunctions & mesh_attribute_accessor_functions()
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_remove_invalid_attribute_strings(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_set_custom_normals_normalized(Mesh &mesh, MutableSpan< float3 > corner_normals)
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_transform(Mesh &mesh, const float4x4 &transform, bool do_shape_keys)
void mesh_set_custom_normals_from_verts(Mesh &mesh, MutableSpan< float3 > vert_normals)
void mesh_vert_normals_assign(Mesh &mesh, Span< float3 > vert_normals)
void mesh_set_custom_normals_from_verts_normalized(Mesh &mesh, MutableSpan< 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_set_custom_normals(Mesh &mesh, MutableSpan< float3 > corner_normals)
void mesh_select_face_flush(Mesh &mesh)
void mesh_translate(Mesh &mesh, const float3 &translation, bool do_shape_keys)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
std::mutex Mutex
Definition BLI_mutex.hh:47
VecBase< float, 3 > float3
blender::VecBase< int16_t, 2 > short2
Vector< Array< int > > corners_by_space
Definition BKE_mesh.hh:178
Vector< CornerNormalSpace > spaces
Definition BKE_mesh.hh:166