Blender V4.3
mesh_validate.cc File Reference
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include "CLG_log.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "BLI_map.hh"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_ordered_edge.hh"
#include "BLI_sort.hh"
#include "BLI_sys_types.h"
#include "BLI_utildefines.h"
#include "BLI_vector_set.hh"
#include "BKE_attribute.hh"
#include "BKE_customdata.hh"
#include "BKE_deform.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_runtime.hh"
#include "DEG_depsgraph.hh"
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Classes

union  EdgeUUID
 
struct  SortFaceLegacy
 
struct  SortFace
 

Macros

#define INVALID_CORNER_EDGE_MARKER   4294967295u
 
#define REMOVE_EDGE_TAG(_me)
 
#define IS_REMOVED_EDGE(_me)   (_me[0] == _me[1])
 
#define REMOVE_CORNER_TAG(corner)
 
#define REMOVE_FACE_TAG(_mf)
 
#define CHECK_FACE_VERT_INDEX(a, b)
 
#define CHECK_FACE_EDGE(a, b)
 

Functions

Mesh Stripping (removing invalid data)
void strip_loose_faces_corners (Mesh *mesh, blender::BitSpan faces_to_remove)
 
void mesh_strip_edges (Mesh *mesh)
 
Internal functions
static void edge_store_assign (uint32_t verts[2], const uint32_t v1, const uint32_t v2)
 
static void edge_store_from_mface_quad (EdgeUUID es[4], const MFace *mf)
 
static void edge_store_from_mface_tri (EdgeUUID es[4], const MFace *mf)
 
static bool search_legacy_face_cmp (const SortFaceLegacy &sfa, const SortFaceLegacy &sfb)
 
static bool search_face_cmp (const SortFace &sp1, const SortFace &sp2)
 
static bool search_face_corner_cmp (const SortFace &sp1, const SortFace &sp2)
 

Variables

static CLG_LogRef LOG = {"bke.mesh"}
 

Mesh Validation

#define PRINT_MSG(...)
 
#define PRINT_ERR(...)
 
bool BKE_mesh_validate_arrays (Mesh *mesh, float(*vert_positions)[3], uint verts_num, blender::int2 *edges, uint edges_num, MFace *legacy_faces, uint legacy_faces_num, const int *corner_verts, int *corner_edges, uint corners_num, const int *face_offsets, uint faces_num, MDeformVert *dverts, const bool do_verbose, const bool do_fixes, bool *r_changed)
 
static bool mesh_validate_customdata (CustomData *data, eCustomDataMask mask, const uint totitems, const bool do_verbose, const bool do_fixes, bool *r_change)
 
bool BKE_mesh_validate_all_customdata (CustomData *vert_data, const uint verts_num, CustomData *edge_data, const uint edges_num, CustomData *corner_data, const uint corners_num, CustomData *face_data, const uint faces_num, const bool check_meshmask, const bool do_verbose, const bool do_fixes, bool *r_change)
 
bool BKE_mesh_validate (Mesh *mesh, const bool do_verbose, const bool cddata_check_mask)
 
bool BKE_mesh_is_valid (Mesh *mesh)
 
bool BKE_mesh_validate_material_indices (Mesh *mesh)
 

Macro Definition Documentation

◆ CHECK_FACE_EDGE

#define CHECK_FACE_EDGE ( a,
b )
Value:
if (!edge_hash.contains({mf->a, mf->b})) { \
PRINT_ERR(" face %u: edge " STRINGIFY(a) "/" STRINGIFY(b) " (%u,%u) is missing edge data", \
i, \
mf->a, \
mf->b); \
recalc_flag.edges = do_fixes; \
} \
(void)0
#define STRINGIFY(x)
local_group_size(16, 16) .push_constant(Type b

Referenced by BKE_mesh_validate_arrays().

◆ CHECK_FACE_VERT_INDEX

#define CHECK_FACE_VERT_INDEX ( a,
b )
Value:
if (mf->a == mf->b) { \
PRINT_ERR(" face %u: verts invalid, " STRINGIFY(a) "/" STRINGIFY(b) " both %u", i, mf->a); \
remove = do_fixes; \
} \
(void)0

Referenced by BKE_mesh_validate_arrays().

◆ INVALID_CORNER_EDGE_MARKER

#define INVALID_CORNER_EDGE_MARKER   4294967295u

Definition at line 44 of file mesh_validate.cc.

Referenced by mesh_strip_edges(), and strip_loose_faces_corners().

◆ IS_REMOVED_EDGE

#define IS_REMOVED_EDGE ( _me)    (_me[0] == _me[1])

◆ PRINT_ERR

#define PRINT_ERR ( ...)
Value:
do { \
is_valid = false; \
if (do_verbose) { \
CLOG_ERROR(&LOG, __VA_ARGS__); \
} \
} while (0)
static CLG_LogRef LOG

Definition at line 157 of file mesh_validate.cc.

Referenced by BKE_mesh_validate_all_customdata(), BKE_mesh_validate_arrays(), and mesh_validate_customdata().

◆ PRINT_MSG

#define PRINT_MSG ( ...)
Value:
if (do_verbose) { \
CLOG_INFO(&LOG, 1, __VA_ARGS__); \
} \
((void)0)

Definition at line 151 of file mesh_validate.cc.

Referenced by BKE_mesh_validate_arrays(), and mesh_validate_customdata().

◆ REMOVE_CORNER_TAG

#define REMOVE_CORNER_TAG ( corner)
Value:
{ \
corner_edges[corner] = INVALID_CORNER_EDGE_MARKER; \
free_flag.face_corners = do_fixes; \
} \
(void)0
#define INVALID_CORNER_EDGE_MARKER

Referenced by BKE_mesh_validate_arrays().

◆ REMOVE_EDGE_TAG

#define REMOVE_EDGE_TAG ( _me)
Value:
{ \
_me[0] = _me[1]; \
free_flag.edges = do_fixes; \
} \
(void)0

Referenced by BKE_mesh_validate_arrays().

◆ REMOVE_FACE_TAG

#define REMOVE_FACE_TAG ( _mf)
Value:
{ \
_mf->v3 = 0; \
free_flag.faces = do_fixes; \
} \
(void)0

Referenced by BKE_mesh_validate_arrays().

Function Documentation

◆ BKE_mesh_is_valid()

bool BKE_mesh_is_valid ( Mesh * mesh)

Checks if a Mesh is valid without any modification. This is always verbose.

Returns
True if the mesh is valid.

Definition at line 1081 of file mesh_validate.cc.

References BKE_mesh_validate_all_customdata(), BKE_mesh_validate_arrays(), BLI_assert, CD_MDEFORMVERT, CD_MFACE, CustomData_get_layer_for_write(), blender::MutableSpan< T >::data(), blender::Span< T >::data(), is_valid, and blender::Span< T >::size().

◆ BKE_mesh_validate()

◆ BKE_mesh_validate_all_customdata()

bool BKE_mesh_validate_all_customdata ( CustomData * vert_data,
uint verts_num,
CustomData * edge_data,
uint edges_num,
CustomData * corner_data,
uint corners_num,
CustomData * face_data,
uint faces_num,
bool check_meshmask,
bool do_verbose,
bool do_fixes,
bool * r_change )

◆ BKE_mesh_validate_arrays()

bool BKE_mesh_validate_arrays ( Mesh * mesh,
float(*) vert_positions[3],
unsigned int verts_num,
blender::int2 * edges,
unsigned int edges_num,
MFace * legacy_faces,
unsigned int legacy_faces_num,
const int * corner_verts,
int * corner_edges,
unsigned int corners_num,
const int * face_offsets,
unsigned int faces_num,
MDeformVert * dverts,
bool do_verbose,
bool do_fixes,
bool * r_change )

◆ BKE_mesh_validate_material_indices()

bool BKE_mesh_validate_material_indices ( Mesh * mesh)

Check all material indices of faces are valid, invalid ones are set to 0.

Returns
True if the material indices are valid.

Definition at line 1134 of file mesh_validate.cc.

References DEG_id_tag_update(), blender::bke::AttributeWriter< T >::finish(), ID_RECALC_GEOMETRY_ALL_MODES, is_valid, max_ii(), and blender::bke::AttributeWriter< T >::varray.

◆ edge_store_assign()

static void edge_store_assign ( uint32_t verts[2],
const uint32_t v1,
const uint32_t v2 )
static

Definition at line 75 of file mesh_validate.cc.

References v2, and verts.

Referenced by edge_store_from_mface_quad(), and edge_store_from_mface_tri().

◆ edge_store_from_mface_quad()

static void edge_store_from_mface_quad ( EdgeUUID es[4],
const MFace * mf )
static

Definition at line 87 of file mesh_validate.cc.

References edge_store_assign(), MFace::v1, MFace::v2, MFace::v3, MFace::v4, and verts.

Referenced by BKE_mesh_validate_arrays().

◆ edge_store_from_mface_tri()

static void edge_store_from_mface_tri ( EdgeUUID es[4],
const MFace * mf )
static

◆ mesh_strip_edges()

◆ mesh_validate_customdata()

static bool mesh_validate_customdata ( CustomData * data,
eCustomDataMask mask,
const uint totitems,
const bool do_verbose,
const bool do_fixes,
bool * r_change )
static

◆ search_face_cmp()

static bool search_face_cmp ( const SortFace & sp1,
const SortFace & sp2 )
static

Definition at line 117 of file mesh_validate.cc.

References SortFace::invalid, SortFace::numverts, and SortFace::verts.

Referenced by BKE_mesh_validate_arrays().

◆ search_face_corner_cmp()

static bool search_face_corner_cmp ( const SortFace & sp1,
const SortFace & sp2 )
static

Definition at line 135 of file mesh_validate.cc.

References SortFace::corner_start, and SortFace::invalid.

Referenced by BKE_mesh_validate_arrays().

◆ search_legacy_face_cmp()

static bool search_legacy_face_cmp ( const SortFaceLegacy & sfa,
const SortFaceLegacy & sfb )
static

Definition at line 103 of file mesh_validate.cc.

References EdgeUUID::edval, and SortFaceLegacy::es.

Referenced by BKE_mesh_validate_arrays().

◆ strip_loose_faces_corners()

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"bke.mesh"}
static

Definition at line 46 of file mesh_validate.cc.

Referenced by BKE_mesh_validate().