Blender  V2.93
Classes | Macros | Variables
mesh_validate.c File Reference
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "CLG_log.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "BLI_sys_types.h"
#include "BLI_edgehash.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "BKE_customdata.h"
#include "BKE_deform.h"
#include "BKE_mesh.h"
#include "DEG_depsgraph.h"
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Classes

union  EdgeUUID
 
struct  SortFace
 
struct  SortPoly
 
struct  EdgeSort
 

Macros

#define INVALID_LOOP_EDGE_MARKER   4294967295u
 
#define REMOVE_EDGE_TAG(_me)
 
#define IS_REMOVED_EDGE(_me)   (_me->v2 == _me->v1)
 
#define REMOVE_LOOP_TAG(_ml)
 
#define REMOVE_POLY_TAG(_mp)
 
#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 BKE_mesh_strip_loose_faces (Mesh *me)
 
void BKE_mesh_strip_loose_polysloops (Mesh *me)
 
void BKE_mesh_strip_loose_edges (Mesh *me)
 
Mesh Edge Calculation
static void to_edgesort (struct EdgeSort *ed, unsigned int v1, unsigned int v2, char is_loose, short is_draw)
 
static int vergedgesort (const void *v1, const void *v2)
 
static void mesh_calc_edges_mdata (MVert *UNUSED(allvert), MFace *allface, MLoop *allloop, MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly, const bool use_old, MEdge **r_medge, int *r_totedge)
 
void BKE_mesh_calc_edges_legacy (Mesh *me, const bool use_old)
 
void BKE_mesh_calc_edges_loose (Mesh *mesh)
 
void BKE_mesh_calc_edges_tessface (Mesh *mesh)
 

Variables

static CLG_LogRef LOG = {"bke.mesh"}
 

Mesh Validation

#define PRINT_MSG(...)
 
#define PRINT_ERR(...)
 
bool BKE_mesh_validate_arrays (Mesh *mesh, MVert *mverts, unsigned int totvert, MEdge *medges, unsigned int totedge, MFace *mfaces, unsigned int totface, MLoop *mloops, unsigned int totloop, MPoly *mpolys, unsigned int totpoly, MDeformVert *dverts, const bool do_verbose, const bool do_fixes, bool *r_changed)
 
static bool mesh_validate_customdata (CustomData *data, CustomDataMask mask, const uint totitems, const bool do_verbose, const bool do_fixes, bool *r_change)
 
bool BKE_mesh_validate_all_customdata (CustomData *vdata, const uint totvert, CustomData *edata, const uint totedge, CustomData *ldata, const uint totloop, CustomData *pdata, const uint totpoly, const bool check_meshmask, const bool do_verbose, const bool do_fixes, bool *r_change)
 
bool BKE_mesh_validate (Mesh *me, const bool do_verbose, const bool cddata_check_mask)
 
bool BKE_mesh_is_valid (Mesh *me)
 
bool BKE_mesh_validate_material_indices (Mesh *me)
 

Internal functions

typedef struct SortFace SortFace
 
typedef struct SortPoly SortPoly
 
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], MFace *mf)
 
static void edge_store_from_mface_tri (EdgeUUID es[4], MFace *mf)
 
static int int64_cmp (const void *v1, const void *v2)
 
static int search_face_cmp (const void *v1, const void *v2)
 
static int int_cmp (const void *v1, const void *v2)
 
static int search_poly_cmp (const void *v1, const void *v2)
 
static int search_polyloop_cmp (const void *v1, const void *v2)
 

Macro Definition Documentation

◆ CHECK_FACE_EDGE

#define CHECK_FACE_EDGE (   a,
 
)
Value:
if (!BLI_edgehash_haskey(edge_hash, 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
bool BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:426
#define STRINGIFY(x)
static unsigned a[3]
Definition: RandGen.cpp:92

◆ CHECK_FACE_VERT_INDEX

#define CHECK_FACE_VERT_INDEX (   a,
 
)
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

◆ INVALID_LOOP_EDGE_MARKER

#define INVALID_LOOP_EDGE_MARKER   4294967295u

Definition at line 51 of file mesh_validate.c.

◆ IS_REMOVED_EDGE

#define IS_REMOVED_EDGE (   _me)    (_me->v2 == _me->v1)

◆ 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: mesh_validate.c:53

Definition at line 208 of file mesh_validate.c.

◆ PRINT_MSG

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

Definition at line 202 of file mesh_validate.c.

◆ REMOVE_EDGE_TAG

#define REMOVE_EDGE_TAG (   _me)
Value:
{ \
_me->v2 = _me->v1; \
free_flag.edges = do_fixes; \
} \
(void)0

◆ REMOVE_FACE_TAG

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

◆ REMOVE_LOOP_TAG

#define REMOVE_LOOP_TAG (   _ml)
Value:
{ \
free_flag.polyloops = do_fixes; \
} \
(void)0
#define INVALID_LOOP_EDGE_MARKER
Definition: mesh_validate.c:51

◆ REMOVE_POLY_TAG

#define REMOVE_POLY_TAG (   _mp)
Value:
{ \
_mp->totloop *= -1; \
free_flag.polyloops = do_fixes; \
} \
(void)0

Typedef Documentation

◆ SortFace

typedef struct SortFace SortFace

◆ SortPoly

typedef struct SortPoly SortPoly

Function Documentation

◆ BKE_mesh_calc_edges_legacy()

void BKE_mesh_calc_edges_legacy ( Mesh me,
const bool  use_old 
)

If the mesh is from a very old blender version, convert mface->edcode to edge drawflags

Definition at line 1499 of file mesh_validate.c.

References BKE_mesh_strip_loose_faces(), CD_ASSIGN, CD_MEDGE, CustomData_add_layer(), Mesh::medge, mesh_calc_edges_mdata(), Mesh::mface, Mesh::mloop, Mesh::mpoly, Mesh::mvert, Mesh::totedge, Mesh::totface, Mesh::totloop, Mesh::totpoly, and Mesh::totvert.

Referenced by blo_do_versions_pre250().

◆ BKE_mesh_calc_edges_loose()

void BKE_mesh_calc_edges_loose ( Mesh mesh)

◆ BKE_mesh_calc_edges_tessface()

void BKE_mesh_calc_edges_tessface ( Mesh mesh)

◆ BKE_mesh_is_valid()

bool BKE_mesh_is_valid ( Mesh me)

◆ BKE_mesh_strip_loose_edges()

void BKE_mesh_strip_loose_edges ( Mesh me)

◆ BKE_mesh_strip_loose_faces()

void BKE_mesh_strip_loose_faces ( Mesh me)

◆ BKE_mesh_strip_loose_polysloops()

void BKE_mesh_strip_loose_polysloops ( Mesh me)

Works on both loops and polys!

Note
It won't try to guess which loops of an invalid poly to remove! this is the work of the caller, to mark those loops... See e.g. BKE_mesh_validate_arrays().

Definition at line 1206 of file mesh_validate.c.

References Freestyle::a, CustomData_copy_data(), CustomData_free_elem(), BMLoop::e, INVALID_LOOP_EDGE_MARKER, l, Mesh::ldata, MPoly::loopstart, MEM_freeN, MEM_mallocN, Mesh::mloop, Mesh::mpoly, Mesh::totloop, MPoly::totloop, and Mesh::totpoly.

Referenced by BKE_mesh_validate_arrays().

◆ BKE_mesh_validate()

bool BKE_mesh_validate ( Mesh me,
const bool  do_verbose,
const bool  cddata_check_mask 
)

◆ BKE_mesh_validate_all_customdata()

bool BKE_mesh_validate_all_customdata ( CustomData vdata,
const uint  totvert,
CustomData edata,
const uint  totedge,
CustomData ldata,
const uint  totloop,
CustomData pdata,
const uint  totpoly,
const bool  check_meshmask,
const bool  do_verbose,
const bool  do_fixes,
bool *  r_change 
)

◆ BKE_mesh_validate_arrays()

bool BKE_mesh_validate_arrays ( Mesh mesh,
MVert mverts,
unsigned int  totvert,
MEdge medges,
unsigned int  totedge,
MFace mfaces,
unsigned int  totface,
MLoop mloops,
unsigned int  totloop,
MPoly mpolys,
unsigned int  totpoly,
MDeformVert dverts,
const bool  do_verbose,
const bool  do_fixes,
bool *  r_changed 
)

◆ BKE_mesh_validate_material_indices()

bool BKE_mesh_validate_material_indices ( Mesh me)

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

Returns
is_valid.

Definition at line 1148 of file mesh_validate.c.

References DEG_id_tag_update(), Mesh::id, ID_RECALC_GEOMETRY, is_valid, MPoly::mat_nr, max_ii(), Mesh::mpoly, Mesh::totcol, and Mesh::totpoly.

◆ edge_store_assign()

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

Definition at line 79 of file mesh_validate.c.

References v1, 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],
MFace mf 
)
static

Definition at line 91 of file mesh_validate.c.

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],
MFace mf 
)
static

◆ int64_cmp()

static int int64_cmp ( const void *  v1,
const void *  v2 
)
static

Definition at line 107 of file mesh_validate.c.

References v1, v2, and x2.

Referenced by BKE_mesh_validate_arrays().

◆ int_cmp()

static int int_cmp ( const void *  v1,
const void *  v2 
)
static

Definition at line 158 of file mesh_validate.c.

References v1, and v2.

Referenced by BKE_mesh_validate_arrays().

◆ mesh_calc_edges_mdata()

static void mesh_calc_edges_mdata ( MVert UNUSEDallvert,
MFace allface,
MLoop allloop,
MPoly allpoly,
int   UNUSEDtotvert,
int  totface,
int   UNUSEDtotloop,
int  totpoly,
const bool  use_old,
MEdge **  r_medge,
int *  r_totedge 
)
static

◆ mesh_validate_customdata()

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

◆ search_face_cmp()

static int search_face_cmp ( const void *  v1,
const void *  v2 
)
static

Definition at line 122 of file mesh_validate.c.

References EdgeUUID::edval, SortFace::es, v1, and v2.

Referenced by BKE_mesh_validate_arrays().

◆ search_poly_cmp()

static int search_poly_cmp ( const void *  v1,
const void *  v2 
)
static

Definition at line 163 of file mesh_validate.c.

References SortPoly::invalid, SortPoly::numverts, v1, v2, and SortPoly::verts.

Referenced by BKE_mesh_validate_arrays().

◆ search_polyloop_cmp()

static int search_polyloop_cmp ( const void *  v1,
const void *  v2 
)
static

Definition at line 184 of file mesh_validate.c.

References SortPoly::invalid, SortPoly::loopstart, v1, and v2.

Referenced by BKE_mesh_validate_arrays().

◆ to_edgesort()

static void to_edgesort ( struct EdgeSort ed,
unsigned int  v1,
unsigned int  v2,
char  is_loose,
short  is_draw 
)
static

Definition at line 1325 of file mesh_validate.c.

References EdgeSort::is_draw, EdgeSort::is_loose, EdgeSort::v1, v1, EdgeSort::v2, and v2.

Referenced by mesh_calc_edges_mdata().

◆ vergedgesort()

static int vergedgesort ( const void *  v1,
const void *  v2 
)
static

Definition at line 1340 of file mesh_validate.c.

References EdgeSort::v1, v1, EdgeSort::v2, v2, and x2.

Referenced by mesh_calc_edges_mdata().

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"bke.mesh"}
static

Definition at line 53 of file mesh_validate.c.

Referenced by BKE_mesh_validate().