Blender V5.0
mesh_validate.cc File Reference
#include <algorithm>
#include <climits>
#include <cstring>
#include "CLG_log.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_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 "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)
#define REMOVE_CORNER_TAG(corner)
#define REMOVE_FACE_TAG(_mf)
#define CHECK_FACE_VERT_INDEX(a, b)
#define CHECK_FACE_EDGE(a, b)

Typedefs

using float3

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 = {"geom.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)
i
Definition text_draw.cc:230

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 41 of file mesh_validate.cc.

Referenced by mesh_strip_edges(), and strip_loose_faces_corners().

◆ IS_REMOVED_EDGE

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

Referenced by BKE_mesh_validate_arrays().

◆ PRINT_ERR

#define PRINT_ERR ( ...)
Value:
do { \
is_valid = false; \
if (do_verbose) { \
CLOG_ERROR(&LOG, __VA_ARGS__); \
} \
} while (0)
#define LOG(level)
Definition log.h:97

Definition at line 154 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, __VA_ARGS__); \
} \
((void)0)

Definition at line 148 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().

Typedef Documentation

◆ float3

Definition at line 619 of file BLI_math_vector_types.hh.

Function Documentation

◆ BKE_mesh_is_valid()

bool BKE_mesh_is_valid ( Mesh * mesh)

◆ 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 )

Validate the mesh, do_fixes requires mesh to be non-null.

Returns
false if no changes needed to be made.

Definition at line 163 of file mesh_validate.cc.

References Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), b, Array< T, InlineBufferCapacity, Allocator >::begin(), BKE_defvert_remove_group(), BKE_mesh_strip_loose_faces(), BLI_assert, CHECK_FACE_EDGE, CHECK_FACE_VERT_INDEX, CLAMP, BitVector< InlineBufferCapacity, Allocator >::clear_and_shrink(), Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), SortFace::corner_start, Array< T, InlineBufferCapacity, Allocator >::data(), MDeformWeight::def_nr, MDeformVert::dw, edge_store_from_mface_quad(), edge_store_from_mface_tri(), Array< T, InlineBufferCapacity, Allocator >::end(), SortFaceLegacy::es, faces, blender::bke::AttributeWriter< T >::finish(), i, MSelect::index, SortFace::index, SortFaceLegacy::index, SortFace::invalid, IS_REMOVED_EDGE, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup(), ME_ESEL, ME_FSEL, ME_VSEL, MEM_freeN(), blender::bke::mesh_calc_edges(), mesh_strip_edges(), SortFace::numverts, blender::parallel_sort(), PRINT_ERR, PRINT_MSG, REMOVE_CORNER_TAG, REMOVE_EDGE_TAG, REMOVE_FACE_TAG, Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::reserve(), search_face_cmp(), search_face_corner_cmp(), search_legacy_face_cmp(), Array< T, InlineBufferCapacity, Allocator >::size(), strip_loose_faces_corners(), MSelect::type, v, MFace::v1, MFace::v2, v2, MFace::v3, MFace::v4, blender::bke::AttributeWriter< T >::varray, SortFace::verts, verts, MDeformWeight::weight, and zero_v3().

Referenced by BKE_mesh_is_valid(), BKE_mesh_runtime_is_valid(), BKE_mesh_validate(), and blo_do_versions_290().

◆ 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 1131 of file mesh_validate.cc.

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

◆ edge_store_assign()

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

Definition at line 72 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()

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

Definition at line 84 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()

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

◆ mesh_strip_edges()

◆ mesh_validate_customdata()

◆ search_face_cmp()

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

Definition at line 114 of file mesh_validate.cc.

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

Referenced by BKE_mesh_validate_arrays().

◆ search_face_corner_cmp()

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

Definition at line 132 of file mesh_validate.cc.

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

Referenced by BKE_mesh_validate_arrays().

◆ search_legacy_face_cmp()

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

Definition at line 100 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 = {"geom.mesh"}
static

Definition at line 43 of file mesh_validate.cc.