Blender V4.3
blender::bke::mesh Namespace Reference

Classes

struct  CornerNormalSpace
 
struct  CornerNormalSpaceArray
 
struct  CornerSplitTaskDataCommon
 
struct  LocalData
 

Functions

Array< intbuild_corner_to_face_map (OffsetIndices< int > faces)
 
GroupedSpan< intbuild_vert_to_edge_map (Span< int2 > edges, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
 
void build_vert_to_face_indices (OffsetIndices< int > faces, Span< int > corner_verts, OffsetIndices< int > offsets, MutableSpan< int > face_indices)
 
GroupedSpan< intbuild_vert_to_face_map (OffsetIndices< int > faces, Span< int > corner_verts, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
 
Array< intbuild_vert_to_corner_indices (Span< int > corner_verts, OffsetIndices< int > offsets)
 
GroupedSpan< intbuild_vert_to_corner_map (Span< int > corner_verts, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
 
GroupedSpan< intbuild_edge_to_corner_map (Span< int > corner_edges, int edges_num, Array< int > &r_offsets, Array< int > &r_indices)
 
GroupedSpan< intbuild_edge_to_face_map (OffsetIndices< int > faces, Span< int > corner_edges, int edges_num, Array< int > &r_offsets, Array< int > &r_indices)
 
static float3 face_center_calc_ngon (const Span< float3 > vert_positions, const Span< int > face_verts)
 
static float mesh_calc_face_volume_centroid_with_reference_center (const Span< float3 > positions, const Span< int > face_verts, const float3 &reference_center, float r_cent[3])
 
static float face_area_centroid_calc (const Span< float3 > positions, const Span< int > face_verts, float r_cent[3])
 
static Array< intcreate_reverse_offsets (const Span< int > indices, const int items_num)
 
static void sort_small_groups (const OffsetIndices< int > groups, const int grain_size, MutableSpan< int > indices)
 
static Array< intreverse_indices_in_groups (const Span< int > group_indices, const OffsetIndices< int > offsets)
 
static void reverse_group_indices_in_groups (const OffsetIndices< int > groups, const Span< int > group_to_elem, const OffsetIndices< int > offsets, MutableSpan< int > results)
 
static GroupedSpan< intgather_groups (const Span< int > group_indices, const int groups_num, Array< int > &r_offsets, Array< int > &r_indices)
 
static CornerNormalSpace corner_fan_space_define (const float3 &lnor, const float3 &vec_ref, const float3 &vec_other, const Span< float3 > edge_vectors)
 
static float3 corner_space_custom_data_to_normal (const CornerNormalSpace &lnor_space, const short2 clnor_data)
 
static void mesh_edges_sharp_tag (const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > corner_edges, const Span< int > corner_to_face_map, const Span< float3 > face_normals, const Span< bool > sharp_faces, const Span< bool > sharp_edges, const float split_angle, MutableSpan< int2 > edge_to_corners, MutableSpan< bool > r_sharp_edges)
 
static void build_edge_to_corner_map_with_flip_and_sharp (const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > corner_edges, const Span< bool > sharp_faces, const Span< bool > sharp_edges, MutableSpan< int2 > edge_to_corners)
 
static void corner_manifold_fan_around_vert_next (const Span< int > corner_verts, const OffsetIndices< int > faces, const Span< int > corner_to_face, const int2 e2lfan_curr, const int vert_pivot, int *r_fan_corner, int *r_vert_corner)
 
static void lnor_space_for_single_fan (CornerSplitTaskDataCommon *common_data, const int corner, const int space_index)
 
static void split_corner_normal_fan_do (CornerSplitTaskDataCommon *common_data, const int corner, const int space_index, Vector< float3, 16 > *edge_vectors)
 
static bool corner_split_generator_check_cyclic_smooth_fan (const Span< int > corner_verts, const Span< int > corner_edges, const OffsetIndices< int > faces, const Span< int2 > edge_to_corners, const Span< int > corner_to_face, const int2 e2l_prev, MutableBitSpan skip_corners, const int corner, const int corner_prev)
 
static void corner_split_generator (CornerSplitTaskDataCommon *common_data, Vector< int, 32 > &r_single_corners, Vector< int, 32 > &r_fan_corners)
 
static void mesh_normals_corner_custom_set (const Span< float3 > positions, const Span< int2 > edges, const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< int > corner_edges, const Span< float3 > vert_normals, const Span< float3 > face_normals, const Span< bool > sharp_faces, const bool use_vertices, MutableSpan< float3 > r_custom_corner_normals, MutableSpan< bool > sharp_edges, MutableSpan< short2 > r_clnors_data)
 
static void mesh_set_custom_normals (Mesh *mesh, float(*r_custom_nors)[3], const bool use_vertices)
 
Polygon Data Evaluation
float3 face_normal_calc (Span< float3 > vert_positions, Span< int > face_verts)
 
void corner_tris_calc (Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< int3 > corner_tris)
 
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)
 
void vert_tris_from_corner_tris (Span< int > corner_verts, Span< int3 > corner_tris, MutableSpan< int3 > vert_tris)
 
int3 corner_tri_get_real_edges (Span< int2 > edges, Span< int > corner_verts, Span< int > corner_edges, const int3 &corner_tri)
 
float3 face_center_calc (Span< float3 > vert_positions, Span< int > face_verts)
 
float face_area_calc (Span< float3 > vert_positions, Span< int > face_verts)
 
void face_angles_calc (Span< float3 > vert_positions, Span< int > face_verts, MutableSpan< float > angles)
 
Medium-Level Normals Calculation
void normals_calc_faces (Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< float3 > face_normals)
 
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)
 
Face Corner Normal Calculation
short2 corner_space_custom_normal_to_data (const CornerNormalSpace &lnor_space, const float3 &custom_lnor)
 
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)
 
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 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)
 
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)
 
Topology Queries
int face_corner_prev (const IndexRange face, const int corner)
 
int face_corner_next (const IndexRange face, const int corner)
 
int face_find_corner_from_vert (const IndexRange face, const Span< int > corner_verts, const int vert)
 
int2 face_find_adjacent_verts (const IndexRange face, const Span< int > corner_verts, const int vert)
 
int face_triangles_num (const int face_size)
 
IndexRange face_triangles_range (OffsetIndices< int > faces, int face_i)
 
int edge_other_vert (const int2 edge, const int vert)
 
Mesh Normal Calculation (Polygons)
static float3 normal_calc_ngon (const Span< float3 > vert_positions, const Span< int > face_verts)
 
Face Tessellation

Fill in Corner Triangle Array

BLI_INLINE void mesh_calc_tessellation_for_face_impl (const Span< int > corner_verts, const Span< float3 > positions, const int face_start, const int face_size, int3 *tri, MemArena **pf_arena_p, const bool face_normal, const float normal_precalc[3])
 
static void mesh_calc_tessellation_for_face (const Span< int > corner_verts, const Span< float3 > positions, const int face_start, const int face_size, int3 *tri, MemArena **pf_arena_p)
 
static void mesh_calc_tessellation_for_face_with_normal (const Span< int > corner_verts, const Span< float3 > positions, const int face_start, const int face_size, int3 *tri, MemArena **pf_arena_p, const float normal_precalc[3])
 
static void corner_tris_calc_impl (const Span< float3 > positions, const OffsetIndices< int > faces, const Span< int > corner_verts, const Span< float3 > face_normals, MutableSpan< int3 > corner_tris)
 

Function Documentation

◆ build_corner_to_face_map()

Array< int > blender::bke::mesh::build_corner_to_face_map ( OffsetIndices< int > faces)

◆ build_edge_to_corner_map()

GroupedSpan< int > blender::bke::mesh::build_edge_to_corner_map ( Span< int > corner_edges,
int edges_num,
Array< int > & r_offsets,
Array< int > & r_indices )

◆ build_edge_to_corner_map_with_flip_and_sharp()

static void blender::bke::mesh::build_edge_to_corner_map_with_flip_and_sharp ( const OffsetIndices< int > faces,
const Span< int > corner_verts,
const Span< int > corner_edges,
const Span< bool > sharp_faces,
const Span< bool > sharp_edges,
MutableSpan< int2 > edge_to_corners )
static

Builds a simplified map from edges to face corners, marking special values when it encounters sharp edges or borders between faces with flipped winding orders.

Definition at line 720 of file mesh_normals.cc.

References INDEX_INVALID, INDEX_UNSET, IS_EDGE_SHARP, and blender::Span< T >::is_empty().

Referenced by normals_calc_corners().

◆ build_edge_to_face_map()

◆ build_vert_to_corner_indices()

Array< int > blender::bke::mesh::build_vert_to_corner_indices ( Span< int > corner_verts,
OffsetIndices< int > offsets )

◆ build_vert_to_corner_map()

GroupedSpan< int > blender::bke::mesh::build_vert_to_corner_map ( Span< int > corner_verts,
int verts_num,
Array< int > & r_offsets,
Array< int > & r_indices )

Definition at line 433 of file mesh_mapping.cc.

References build_vert_to_corner_map(), and gather_groups().

Referenced by build_vert_to_corner_map().

◆ build_vert_to_edge_map()

◆ build_vert_to_face_indices()

void blender::bke::mesh::build_vert_to_face_indices ( OffsetIndices< int > faces,
Span< int > corner_verts,
OffsetIndices< int > offsets,
MutableSpan< int > face_indices )

◆ build_vert_to_face_map()

GroupedSpan< int > blender::bke::mesh::build_vert_to_face_map ( OffsetIndices< int > faces,
Span< int > corner_verts,
int verts_num,
Array< int > & r_offsets,
Array< int > & r_indices )

◆ corner_fan_space_define()

static CornerNormalSpace blender::bke::mesh::corner_fan_space_define ( const float3 & lnor,
const float3 & vec_ref,
const float3 & vec_other,
const Span< float3 > edge_vectors )
static

◆ corner_manifold_fan_around_vert_next()

static void blender::bke::mesh::corner_manifold_fan_around_vert_next ( const Span< int > corner_verts,
const OffsetIndices< int > faces,
const Span< int > corner_to_face,
const int2 e2lfan_curr,
const int vert_pivot,
int * r_fan_corner,
int * r_vert_corner )
static

◆ corner_space_custom_data_to_normal()

◆ corner_space_custom_normal_to_data()

◆ corner_split_generator()

◆ corner_split_generator_check_cyclic_smooth_fan()

static bool blender::bke::mesh::corner_split_generator_check_cyclic_smooth_fan ( const Span< int > corner_verts,
const Span< int > corner_edges,
const OffsetIndices< int > faces,
const Span< int2 > edge_to_corners,
const Span< int > corner_to_face,
const int2 e2l_prev,
MutableBitSpan skip_corners,
const int corner,
const int corner_prev )
static

Check whether given corner is part of an unknown-so-far cyclic smooth fan, or not. Needed because cyclic smooth fans have no obvious 'entry point', and yet we need to walk them once, and only once.

Definition at line 1027 of file mesh_normals.cc.

References BLI_assert, corner_manifold_fan_around_vert_next(), and IS_EDGE_SHARP.

Referenced by corner_split_generator().

◆ corner_tri_get_real_edges()

int3 blender::bke::mesh::corner_tri_get_real_edges ( Span< int2 > edges,
Span< int > corner_verts,
Span< int > corner_edges,
const int3 & corner_tri )

Return the triangle's three edge indices they are real edges, otherwise -1.

Definition at line 245 of file mesh_tessellate.cc.

References int.

Referenced by blender::bke::shrinkwrap::shrinkwrap_build_boundary_data().

◆ corner_tris_calc()

◆ corner_tris_calc_face_indices()

void blender::bke::mesh::corner_tris_calc_face_indices ( OffsetIndices< int > faces,
MutableSpan< int > tri_faces )

◆ corner_tris_calc_impl()

static void blender::bke::mesh::corner_tris_calc_impl ( const Span< float3 > positions,
const OffsetIndices< int > faces,
const Span< int > corner_verts,
const Span< float3 > face_normals,
MutableSpan< int3 > corner_tris )
static

◆ corner_tris_calc_with_normals()

void blender::bke::mesh::corner_tris_calc_with_normals ( Span< float3 > vert_positions,
OffsetIndices< int > faces,
Span< int > corner_verts,
Span< float3 > face_normals,
MutableSpan< int3 > corner_tris )

A version of corner_tris_calc which takes pre-calculated face normals (used to avoid having to calculate the face normal for NGON tessellation).

Note
Only use this function if normals have already been calculated, there is no need to calculate normals just to use this function.

Definition at line 226 of file mesh_tessellate.cc.

References BLI_assert, corner_tris_calc_impl(), corner_tris_calc_with_normals(), and blender::Span< T >::is_empty().

Referenced by corner_tris_calc_with_normals(), and mesh_calc_tri_tessface().

◆ create_reverse_offsets()

static Array< int > blender::bke::mesh::create_reverse_offsets ( const Span< int > indices,
const int items_num )
static

◆ edge_other_vert()

◆ edges_sharp_from_angle_set()

void blender::bke::mesh::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 )

Define sharp edges as needed to mimic 'autosmooth' from angle threshold.

Used when defining an empty custom corner normals data layer, to keep same shading as with auto-smooth!

Parameters
sharp_facesOptional array used to mark specific faces for sharp shading.

Definition at line 769 of file mesh_normals.cc.

References M_PI, mesh_edges_sharp_tag(), and blender::MutableSpan< T >::size().

Referenced by blender::bke::mesh_sharp_edges_set_from_angle().

◆ face_angles_calc()

void blender::bke::mesh::face_angles_calc ( Span< float3 > vert_positions,
Span< int > face_verts,
MutableSpan< float > angles )

Calculate the angles at each of the faces corners.

Definition at line 208 of file mesh_evaluate.cc.

References angle_normalized_v3v3(), copy_v3_v3(), normalize_v3(), blender::Span< T >::size(), and sub_v3_v3v3().

Referenced by wn_corner_angle(), and wn_face_with_angle().

◆ face_area_calc()

float blender::bke::mesh::face_area_calc ( Span< float3 > vert_positions,
Span< int > face_verts )

◆ face_area_centroid_calc()

static float blender::bke::mesh::face_area_centroid_calc ( const Span< float3 > positions,
const Span< int > face_verts,
float r_cent[3] )
static
Note
  • Results won't be correct if face is non-planar.
  • This has the advantage over mesh_calc_face_volume_centroid that it doesn't depend on solid geometry, instead it weights the surface by volume.

Definition at line 177 of file mesh_evaluate.cc.

References area_tri_signed_v3(), copy_v3_v3(), face_normal_calc(), madd_v3_v3fl(), mid_v3_v3v3v3(), mul_v3_fl(), blender::Span< T >::size(), v2, and zero_v3().

Referenced by BKE_mesh_center_of_surface().

◆ face_center_calc()

◆ face_center_calc_ngon()

static float3 blender::bke::mesh::face_center_calc_ngon ( const Span< float3 > vert_positions,
const Span< int > face_verts )
static

Definition at line 41 of file mesh_evaluate.cc.

References float, blender::Span< T >::index_range(), blender::Span< T >::size(), and w().

Referenced by face_center_calc().

◆ face_corner_next()

◆ face_corner_prev()

int blender::bke::mesh::face_corner_prev ( const IndexRange face,
const int corner )
inline

◆ face_find_adjacent_verts()

int2 blender::bke::mesh::face_find_adjacent_verts ( const IndexRange face,
const Span< int > corner_verts,
const int vert )
inline

Return the vertex indices on either side of the given vertex, ordered based on the winding direction of the face. The vertex must be in the face.

Definition at line 275 of file BKE_mesh.hh.

References face_corner_next(), face_corner_prev(), and face_find_corner_from_vert().

Referenced by blender::ed::sculpt_paint::vert_neighbors_get_mesh().

◆ face_find_corner_from_vert()

int blender::bke::mesh::face_find_corner_from_vert ( const IndexRange face,
const Span< int > corner_verts,
const int vert )
inline

Find the index of the corner in the face that uses the given vertex. The index is into the entire corners array, not just the face's corners.

Definition at line 264 of file BKE_mesh.hh.

References blender::Span< T >::first_index(), and blender::Span< T >::slice().

Referenced by adjacent_vertices_index_from_adjacent_edge(), blender::ed::sculpt_paint::color::color_vert_get(), do_vpaint_brush_blur_loops(), do_vpaint_brush_smear(), face_find_adjacent_verts(), and vpaint_do_draw().

◆ face_normal_calc()

◆ face_triangles_num()

int blender::bke::mesh::face_triangles_num ( const int face_size)
inline

Return the number of triangles needed to tessellate a face with face_size corners.

Definition at line 287 of file BKE_mesh.hh.

References BLI_assert.

Referenced by BKE_mesh_origindex_map_create_corner_tri(), corner_tris_no_hidden_map_get(), blender::draw::pbvh::create_tri_index_mesh(), face_triangles_range(), and blender::ed::sculpt_paint::trim::generate_geometry().

◆ face_triangles_range()

◆ gather_groups()

static GroupedSpan< int > blender::bke::mesh::gather_groups ( const Span< int > group_indices,
const int groups_num,
Array< int > & r_offsets,
Array< int > & r_indices )
static

◆ lnor_space_for_single_fan()

◆ mesh_calc_face_volume_centroid_with_reference_center()

static float blender::bke::mesh::mesh_calc_face_volume_centroid_with_reference_center ( const Span< float3 > positions,
const Span< int > face_verts,
const float3 & reference_center,
float r_cent[3] )
static

A version of mesh_calc_face_volume_centroid that takes an initial reference center, use this to increase numeric stability as the quality of the result becomes very low quality as the value moves away from 0.0, see: #65986.

Definition at line 147 of file mesh_evaluate.cc.

References copy_v3_v3(), blender::Span< T >::size(), sub_v3_v3v3(), volume_tri_tetrahedron_signed_v3_6x(), and zero_v3().

Referenced by BKE_mesh_center_of_volume().

◆ mesh_calc_tessellation_for_face()

static void blender::bke::mesh::mesh_calc_tessellation_for_face ( const Span< int > corner_verts,
const Span< float3 > positions,
const int face_start,
const int face_size,
int3 * tri,
MemArena ** pf_arena_p )
static

Definition at line 130 of file mesh_tessellate.cc.

References mesh_calc_tessellation_for_face_impl().

◆ mesh_calc_tessellation_for_face_impl()

BLI_INLINE void blender::bke::mesh::mesh_calc_tessellation_for_face_impl ( const Span< int > corner_verts,
const Span< float3 > positions,
const int face_start,
const int face_size,
int3 * tri,
MemArena ** pf_arena_p,
const bool face_normal,
const float normal_precalc[3] )

◆ mesh_calc_tessellation_for_face_with_normal()

static void blender::bke::mesh::mesh_calc_tessellation_for_face_with_normal ( const Span< int > corner_verts,
const Span< float3 > positions,
const int face_start,
const int face_size,
int3 * tri,
MemArena ** pf_arena_p,
const float normal_precalc[3] )
static

Definition at line 141 of file mesh_tessellate.cc.

References mesh_calc_tessellation_for_face_impl().

◆ mesh_edges_sharp_tag()

static void blender::bke::mesh::mesh_edges_sharp_tag ( const OffsetIndices< int > faces,
const Span< int > corner_verts,
const Span< int > corner_edges,
const Span< int > corner_to_face_map,
const Span< float3 > face_normals,
const Span< bool > sharp_faces,
const Span< bool > sharp_edges,
const float split_angle,
MutableSpan< int2 > edge_to_corners,
MutableSpan< bool > r_sharp_edges )
static

◆ mesh_normals_corner_custom_set()

static void blender::bke::mesh::mesh_normals_corner_custom_set ( const Span< float3 > positions,
const Span< int2 > edges,
const OffsetIndices< int > faces,
const Span< int > corner_verts,
const Span< int > corner_edges,
const Span< float3 > vert_normals,
const Span< float3 > face_normals,
const Span< bool > sharp_faces,
const bool use_vertices,
MutableSpan< float3 > r_custom_corner_normals,
MutableSpan< bool > sharp_edges,
MutableSpan< short2 > r_clnors_data )
static

Compute internal representation of given custom normals (as an array of float[2]). It also makes sure the mesh matches those custom normals, by setting sharp edges flag as needed to get a same custom lnor for all corners sharing the same smooth fan. If use_vertices if true, r_custom_corner_normals is assumed to be per-vertex, not per-corner (this allows to set whole vert's normals at once, useful in some cases). r_custom_corner_normals is expected to have normalized normals, or zero ones, in which case they will be replaced by default corner/vertex normal.

Definition at line 1273 of file mesh_normals.cc.

References build_corner_to_face_map(), copy_v3_v3(), corner_space_custom_normal_to_data(), blender::bke::mesh::CornerNormalSpaceArray::corner_space_indices, blender::bke::mesh::CornerNormalSpaceArray::corners_by_space, blender::bke::mesh::CornerNormalSpaceArray::create_corners_by_space, blender::MutableSpan< T >::data(), dot_v3v3(), face_corner_prev(), blender::bits::BitVector< InlineBufferCapacity, Allocator >::fill(), blender::MutableSpan< T >::fill_indices(), G, G_DEBUG, blender::Span< T >::index_range(), blender::Span< T >::is_empty(), is_zero_v3(), blender::IndexRange::last(), blender::Span< T >::last(), LNOR_SPACE_TRIGO_THRESHOLD, mesh_normals_corner_custom_set(), mul_v3_fl(), nor, normals_calc_corners(), printf, blender::Span< T >::size(), and blender::bke::mesh::CornerNormalSpaceArray::spaces.

Referenced by mesh_normals_corner_custom_set(), mesh_set_custom_normals(), normals_corner_custom_set(), and normals_corner_custom_set_from_verts().

◆ mesh_set_custom_normals()

◆ normal_calc_ngon()

static float3 blender::bke::mesh::normal_calc_ngon ( const Span< float3 > vert_positions,
const Span< int > face_verts )
static

◆ normals_calc_corners()

void blender::bke::mesh::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 )

Compute split normals, i.e. vertex normals associated with each face. Used to visualize sharp edges (or non-smooth faces) without actually modifying the geometry (splitting edges).

Parameters
sharp_edgesOptional array of sharp edge tags, used to split the evaluated normals on each side of the edge.
sharp_facesOptional array of sharp face tags, used to split the evaluated normals on the face's edges.
r_lnors_spacearrOptional return data filled with information about the custom normals spaces for each grouped fan of face corners.

Mapping edge -> corners. If that edge is used by more than two corners (faces), it is always sharp (and tagged as such, see below). We also use the second corner index as a kind of flag:

  • smooth edge: > 0.
  • sharp edge: < 0 (INDEX_INVALID || INDEX_UNSET).
  • unset: INDEX_UNSET.

Note that currently we only have two values for second corner of sharp edges. However, if needed, we can store the negated value of corner index instead of INDEX_INVALID to retrieve the real value later in code). Note also that loose edges always have both values set to 0!

Mapping edge -> corners. If that edge is used by more than two corners (faces), it is always sharp (and tagged as such, see below). We also use the second corner index as a kind of flag:

  • smooth edge: > 0.
  • sharp edge: < 0 (INDEX_INVALID || INDEX_UNSET).
  • unset: INDEX_UNSET.

Note that currently we only have two values for second corner of sharp edges. However, if needed, we can store the negated value of corner index instead of INDEX_INVALID to retrieve the real value later in code). Note also that loose edges always have both values set to 0!

Definition at line 1166 of file mesh_normals.cc.

References build_edge_to_corner_map_with_flip_and_sharp(), blender::bke::mesh::CornerSplitTaskDataCommon::clnors_data, blender::bke::mesh::CornerSplitTaskDataCommon::corner_edges, blender::bke::mesh::CornerSplitTaskDataCommon::corner_normals, blender::bke::mesh::CornerNormalSpaceArray::corner_space_indices, corner_split_generator(), blender::bke::mesh::CornerSplitTaskDataCommon::corner_to_face, blender::bke::mesh::CornerSplitTaskDataCommon::corner_verts, blender::bke::mesh::CornerNormalSpaceArray::corners_by_space, blender::bke::mesh::CornerNormalSpaceArray::create_corners_by_space, blender::bke::mesh::CornerSplitTaskDataCommon::edge_to_corners, blender::bke::mesh::CornerSplitTaskDataCommon::edges, blender::bke::mesh::CornerSplitTaskDataCommon::face_normals, blender::bke::mesh::CornerSplitTaskDataCommon::faces, faces, blender::array_utils::gather(), blender::Vector< T, InlineBufferCapacity, Allocator >::index_range(), blender::bke::mesh::CornerSplitTaskDataCommon::lnors_spacearr, blender::threading::parallel_for(), blender::bke::mesh::CornerSplitTaskDataCommon::positions, SCOPED_TIMER_AVERAGED, blender::Span< T >::size(), blender::Vector< T, InlineBufferCapacity, Allocator >::size(), blender::bke::mesh::CornerNormalSpaceArray::spaces, and blender::bke::mesh::CornerSplitTaskDataCommon::vert_normals.

Referenced by apply_weights_vertex_normal(), BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(), mesh_normals_corner_custom_set(), and normalEditModifier_do().

◆ normals_calc_faces()

void blender::bke::mesh::normals_calc_faces ( Span< float3 > vert_positions,
OffsetIndices< int > faces,
Span< int > corner_verts,
MutableSpan< float3 > face_normals )

Calculate face normals directly into a result array.

Note
Usually #Mesh::face_normals() is the preferred way to access face normals, since they may already be calculated and cached on the mesh.

Definition at line 145 of file mesh_normals.cc.

References BLI_assert, blender::threading::parallel_for(), and blender::MutableSpan< T >::size().

◆ normals_calc_verts()

void blender::bke::mesh::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 )

Calculate vertex normals directly into the result array.

Note
Vertex and face normals can be calculated at the same time with #normals_calc_faces_and_verts, which can have performance benefits in some cases.
Usually #Mesh::vert_normals() is the preferred way to access vertex normals, since they may already be calculated and cached on the mesh.

Definition at line 158 of file mesh_normals.cc.

References normals_calc_verts().

Referenced by normals_calc_verts().

◆ normals_corner_custom_set()

void blender::bke::mesh::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 )
Parameters
sharp_facesOptional array used to mark specific faces for sharp shading.

Definition at line 1478 of file mesh_normals.cc.

References mesh_normals_corner_custom_set(), and normals_corner_custom_set().

Referenced by apply_weights_vertex_normal(), data_transfer_dtdata_type_postprocess(), and normals_corner_custom_set().

◆ normals_corner_custom_set_from_verts()

void blender::bke::mesh::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 )
Parameters
sharp_facesOptional array used to mark specific faces for sharp shading.

Definition at line 1504 of file mesh_normals.cc.

References mesh_normals_corner_custom_set(), and normals_corner_custom_set_from_verts().

Referenced by apply_weights_vertex_normal(), and normals_corner_custom_set_from_verts().

◆ reverse_group_indices_in_groups()

static void blender::bke::mesh::reverse_group_indices_in_groups ( const OffsetIndices< int > groups,
const Span< int > group_to_elem,
const OffsetIndices< int > offsets,
MutableSpan< int > results )
static

◆ reverse_indices_in_groups()

◆ sort_small_groups()

static void blender::bke::mesh::sort_small_groups ( const OffsetIndices< int > groups,
const int grain_size,
MutableSpan< int > indices )
static

◆ split_corner_normal_fan_do()

static void blender::bke::mesh::split_corner_normal_fan_do ( CornerSplitTaskDataCommon * common_data,
const int corner,
const int space_index,
Vector< float3, 16 > * edge_vectors )
static

Definition at line 879 of file mesh_normals.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), blender::Array< T, InlineBufferCapacity, Allocator >::as_mutable_span(), blender::Vector< T, InlineBufferCapacity, Allocator >::as_span(), BLI_assert, blender::Vector< T, InlineBufferCapacity, Allocator >::clear(), blender::bke::mesh::CornerSplitTaskDataCommon::clnors_data, blender::bke::mesh::CornerSplitTaskDataCommon::corner_edges, corner_fan_space_define(), corner_manifold_fan_around_vert_next(), blender::bke::mesh::CornerSplitTaskDataCommon::corner_normals, corner_space_custom_data_to_normal(), blender::bke::mesh::CornerNormalSpaceArray::corner_space_indices, blender::bke::mesh::CornerSplitTaskDataCommon::corner_to_face, blender::bke::mesh::CornerSplitTaskDataCommon::corner_verts, blender::bke::mesh::CornerNormalSpaceArray::corners_by_space, blender::math::dot(), edge_other_vert(), blender::bke::mesh::CornerSplitTaskDataCommon::edge_to_corners, blender::bke::mesh::CornerSplitTaskDataCommon::edges, face_corner_prev(), blender::bke::mesh::CornerSplitTaskDataCommon::face_normals, blender::bke::mesh::CornerSplitTaskDataCommon::faces, blender::MutableSpan< T >::fill_indices(), IS_EDGE_SHARP, blender::Span< T >::is_empty(), length(), LIKELY, blender::bke::mesh::CornerSplitTaskDataCommon::lnors_spacearr, blender::math::normalize(), blender::math::normalize_and_get_length(), blender::bke::mesh::CornerSplitTaskDataCommon::positions, blender::math::safe_acos_approx(), blender::Vector< T, InlineBufferCapacity, Allocator >::size(), blender::bke::mesh::CornerNormalSpaceArray::spaces, and UNLIKELY.

◆ vert_tris_from_corner_tris()

void blender::bke::mesh::vert_tris_from_corner_tris ( Span< int > corner_verts,
Span< int3 > corner_tris,
MutableSpan< int3 > vert_tris )

Convert triangles encoded as face corner indices to triangles encoded as vertex indices.

Definition at line 238 of file mesh_tessellate.cc.

References blender::MutableSpan< T >::cast(), blender::Span< T >::cast(), and vert_tris_from_corner_tris().

Referenced by cloth_from_mesh(), blender::io::hydra::copy_submesh(), deform_verts(), blender::bke::pbvh::pixels::update_geom_primitives(), and vert_tris_from_corner_tris().