Blender
V3.3
|
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "CLG_log.h"
#include "BLI_bitmap.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 | |
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], 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) |
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, uint v1, uint 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, uint totvert, MEdge *medges, uint totedge, MFace *mfaces, uint totface, MLoop *mloops, uint totloop, MPoly *mpolys, uint totpoly, 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 *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) |
#define CHECK_FACE_EDGE | ( | a, | |
b | |||
) |
#define CHECK_FACE_VERT_INDEX | ( | a, | |
b | |||
) |
#define INVALID_LOOP_EDGE_MARKER 4294967295u |
Definition at line 36 of file mesh_validate.cc.
#define PRINT_ERR | ( | ... | ) |
Definition at line 195 of file mesh_validate.cc.
#define PRINT_MSG | ( | ... | ) |
Definition at line 189 of file mesh_validate.cc.
#define REMOVE_EDGE_TAG | ( | _me | ) |
#define REMOVE_LOOP_TAG | ( | _ml | ) |
#define REMOVE_POLY_TAG | ( | _mp | ) |
If the mesh is from a very old blender version, convert MFace.edcode to edge ME_EDGEDRAW.
Definition at line 1474 of file mesh_validate.cc.
References BKE_mesh_strip_loose_faces(), CD_ASSIGN, CD_MEDGE, CustomData_add_layer(), Mesh::edata, 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().
Definition at line 1505 of file mesh_validate.cc.
References MLoop::e, MEdge::flag, ME_EDGEDRAW, ME_LOOSEEDGE, Mesh::medge, mesh, Mesh::mloop, Mesh::totedge, and Mesh::totloop.
Referenced by blo_do_versions_280(), blender::nodes::node_geo_delete_geometry_cc::do_mesh_separation(), ED_mesh_update(), blender::io::obj::OBJMesh::ensure_mesh_edges(), and modifyMesh().
Calculate/create edges from tessface data
mesh | The mesh to add edges into |
Definition at line 1523 of file mesh_validate.cc.
References BLI_EDGEHASH_SIZE_GUESS_FROM_POLYS, BLI_edgeset_add(), BLI_edgeset_free(), BLI_edgeset_len(), BLI_edgeset_new_ex(), BLI_edgesetIterator_free(), BLI_edgesetIterator_getKey(), BLI_edgesetIterator_isDone(), BLI_edgesetIterator_new(), BLI_edgesetIterator_step(), CD_CALLOC, CD_MEDGE, CD_ORIGINDEX, CustomData_add_layer(), CustomData_free(), CustomData_get_layer(), CustomData_reset(), Mesh::edata, MEdge::flag, ME_EDGEDRAW, ME_EDGERENDER, Mesh::medge, mesh, Mesh::mface, ORIGINDEX_NONE, Mesh::totedge, Mesh::totface, MEdge::v1, MFace::v1, MEdge::v2, MFace::v2, MFace::v3, and MFace::v4.
Referenced by cutEdges(), and explodeMesh().
Checks if a Mesh is valid without any modification. This is always verbose.
Definition at line 1088 of file mesh_validate.cc.
References BKE_mesh_assert_normals_dirty_or_calculated(), BKE_mesh_validate_all_customdata(), BKE_mesh_validate_arrays(), BLI_assert, Mesh::dvert, Mesh::edata, is_valid, Mesh::ldata, Mesh::medge, Mesh::mface, Mesh::mloop, Mesh::mpoly, Mesh::mvert, Mesh::pdata, Mesh::totedge, Mesh::totface, Mesh::totloop, Mesh::totpoly, Mesh::totvert, and Mesh::vdata.
Referenced by blender::nodes::node_geo_extrude_mesh_cc::node_geo_exec().
Definition at line 1255 of file mesh_validate.cc.
References Freestyle::a, usdtokens::b(), CustomData_copy_data(), CustomData_free_elem(), BMLoop::e, e, Mesh::edata, INVALID_LOOP_EDGE_MARKER, l, Mesh::medge, MEM_freeN, MEM_mallocN, Mesh::mloop, and Mesh::totedge.
Referenced by BKE_mesh_validate_arrays().
Definition at line 1163 of file mesh_validate.cc.
References Freestyle::a, usdtokens::b(), CustomData_copy_data(), CustomData_free_elem(), Mesh::fdata, Mesh::mface, Mesh::totface, and MFace::v3.
Referenced by BKE_mesh_calc_edges_legacy(), BKE_mesh_validate_arrays(), and blo_do_versions_pre250().
Works on both loops and polys!
Definition at line 1184 of file mesh_validate.cc.
References Freestyle::a, usdtokens::b(), 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::pdata, Mesh::totloop, MPoly::totloop, and Mesh::totpoly.
Referenced by BKE_mesh_validate_arrays().
Validates and corrects a Mesh.
Definition at line 1043 of file mesh_validate.cc.
References BKE_mesh_validate_all_customdata(), BKE_mesh_validate_arrays(), CLOG_INFO, DEG_id_tag_update(), Mesh::dvert, Mesh::edata, Mesh::id, ID_RECALC_GEOMETRY_ALL_MODES, Mesh::ldata, LOG, Mesh::medge, Mesh::mface, Mesh::mloop, Mesh::mpoly, Mesh::mvert, ID::name, Mesh::pdata, Mesh::totedge, Mesh::totface, Mesh::totloop, Mesh::totpoly, Mesh::totvert, and Mesh::vdata.
Referenced by BKE_mesh_split_faces(), blender::io::obj::MeshFromGeometry::create_mesh(), MeshImporter::create_mesh_object(), Freestyle::BlenderStrokeRenderer::GenerateStrokeMesh(), blender::io::stl::importer_main(), blender::io::alembic::read_mpolys(), blender::io::alembic::AbcMeshReader::readObjectData(), blender::io::alembic::AbcSubDReader::readObjectData(), and blender::io::alembic::AbcPointsReader::readObjectData().
bool BKE_mesh_validate_all_customdata | ( | struct CustomData * | vdata, |
uint | totvert, | ||
struct CustomData * | edata, | ||
uint | totedge, | ||
struct CustomData * | ldata, | ||
uint | totloop, | ||
struct CustomData * | pdata, | ||
uint | totpoly, | ||
bool | check_meshmask, | ||
bool | do_verbose, | ||
bool | do_fixes, | ||
bool * | r_change | ||
) |
Definition at line 986 of file mesh_validate.cc.
References CD_MASK_MESH, CD_MASK_NORMAL, CD_MLOOPUV, CustomData_get_clone_layer(), CustomData_get_stencil_layer(), CustomData_number_of_layers(), CustomData_set_layer_clone(), CustomData_set_layer_stencil(), is_valid, mask(), MAX_MTFACE, mesh_validate_customdata(), and PRINT_ERR.
Referenced by BKE_mesh_is_valid(), BKE_mesh_runtime_is_valid(), and BKE_mesh_validate().
bool BKE_mesh_validate_arrays | ( | struct Mesh * | me, |
struct MVert * | mverts, | ||
unsigned int | totvert, | ||
struct MEdge * | medges, | ||
unsigned int | totedge, | ||
struct MFace * | mfaces, | ||
unsigned int | totface, | ||
struct MLoop * | mloops, | ||
unsigned int | totloop, | ||
struct MPoly * | mpolys, | ||
unsigned int | totpoly, | ||
struct MDeformVert * | dverts, | ||
bool | do_verbose, | ||
bool | do_fixes, | ||
bool * | r_change | ||
) |
Validate the mesh, do_fixes requires mesh to be non-null.
While zeroed normals are checked, these checks aren't comprehensive. Technically, to detect errors here a normal recalculation and comparison is necessary. However this function is mainly to prevent severe errors in geometry (invalid data that will crash Blender, or cause some features to behave incorrectly), not to detect subtle differences in the resulting normals which could be caused by importers that load normals (for example).
Definition at line 204 of file mesh_validate.cc.
References BKE_defvert_remove_group(), BKE_mesh_assert_normals_dirty_or_calculated(), BKE_mesh_calc_edges(), BKE_mesh_strip_loose_edges(), BKE_mesh_strip_loose_faces(), BKE_mesh_strip_loose_polysloops(), BKE_mesh_vertex_normals_are_dirty(), BKE_mesh_vertex_normals_ensure(), BLI_assert, BLI_BITMAP_DISABLE, BLI_BITMAP_ENABLE, BLI_BITMAP_NEW, BLI_BITMAP_TEST, BLI_edgehash_free(), BLI_edgehash_haskey(), BLI_edgehash_insert(), BLI_edgehash_lookup(), BLI_edgehash_new_ex(), CHECK_FACE_EDGE, CHECK_FACE_VERT_INDEX, CLAMP, MDeformWeight::def_nr, MDeformVert::dw, MLoop::e, edge_store_from_mface_quad(), edge_store_from_mface_tri(), SortFace::es, faces, float(), if(), SortFace::index, SortPoly::index, MSelect::index, int64_cmp(), int_cmp(), SortPoly::invalid, IS_REMOVED_EDGE, is_valid, is_zero_v3(), CCL_NAMESPACE_BEGIN::isfinite(), SortPoly::loopstart, ME_ESEL, ME_FSEL, ME_VSEL, MEM_callocN, MEM_freeN, MEM_mallocN, mesh, Mesh::mselect, normal, SortPoly::numverts, POINTER_AS_INT, POINTER_FROM_INT, PRINT_ERR, PRINT_MSG, blender::bke::attribute_accessor_functions::remove(), REMOVE_EDGE_TAG, REMOVE_FACE_TAG, REMOVE_LOOP_TAG, REMOVE_POLY_TAG, search_face_cmp(), search_poly_cmp(), search_polyloop_cmp(), Mesh::totedge, Mesh::totpoly, Mesh::totselect, Mesh::totvert, MSelect::type, v, MLoop::v, v1, MEdge::v1, MFace::v1, v2, MEdge::v2, MFace::v2, MFace::v3, MFace::v4, SortPoly::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().
Check all material indices of polygons are valid, invalid ones are set to 0.
Definition at line 1133 of file mesh_validate.cc.
References DEG_id_tag_update(), Mesh::id, ID_RECALC_GEOMETRY_ALL_MODES, is_valid, MPoly::mat_nr, max_ii(), Mesh::mpoly, Mesh::totcol, and Mesh::totpoly.
Definition at line 64 of file mesh_validate.cc.
Referenced by edge_store_from_mface_quad(), and edge_store_from_mface_tri().
Definition at line 76 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().
Definition at line 84 of file mesh_validate.cc.
References edge_store_assign(), UINT_MAX, MFace::v1, MFace::v2, MFace::v3, EdgeUUID::verts, and verts.
Referenced by BKE_mesh_validate_arrays().
Definition at line 92 of file mesh_validate.cc.
Referenced by BKE_mesh_validate_arrays().
Definition at line 144 of file mesh_validate.cc.
Referenced by BKE_mesh_validate_arrays().
|
static |
Definition at line 1342 of file mesh_validate.cc.
References Freestyle::a, BLI_edgehash_free(), BLI_edgehash_insert(), BLI_edgehash_lookup(), BLI_edgehash_new_ex(), MLoop::e, MFace::edcode, MEdge::flag, hash, EdgeSort::is_draw, EdgeSort::is_loose, MPoly::loopstart, ME_EDGEDRAW, ME_EDGERENDER, ME_LOOSEEDGE, ME_V1V2, ME_V2V3, ME_V3V1, ME_V3V4, ME_V4V1, MEM_callocN, MEM_freeN, MEM_mallocN, POINTER_AS_UINT, POINTER_FROM_UINT, SWAP, to_edgesort(), MPoly::totloop, MLoop::v, EdgeSort::v1, MEdge::v1, MFace::v1, EdgeSort::v2, v2, MEdge::v2, MFace::v2, MFace::v3, MFace::v4, and vergedgesort().
Referenced by BKE_mesh_calc_edges_legacy().
|
static |
Definition at line 928 of file mesh_validate.cc.
References CD_TYPE_AS_MASK, CustomData_free_layer(), CustomData_layer_validate(), CustomData_layertype_is_singleton(), CustomData_number_of_layers(), data, is_valid, mask(), PRINT_ERR, PRINT_MSG, and CustomDataLayer::type.
Referenced by BKE_mesh_validate_all_customdata().
Definition at line 107 of file mesh_validate.cc.
References EdgeUUID::edval, SortFace::es, v1, and v2.
Referenced by BKE_mesh_validate_arrays().
Definition at line 149 of file mesh_validate.cc.
References SortPoly::invalid, SortPoly::numverts, v1, v2, and SortPoly::verts.
Referenced by BKE_mesh_validate_arrays().
Definition at line 170 of file mesh_validate.cc.
References SortPoly::invalid, SortPoly::loopstart, v1, and v2.
Referenced by BKE_mesh_validate_arrays().
|
static |
Definition at line 1304 of file mesh_validate.cc.
References EdgeSort::is_draw, EdgeSort::is_loose, EdgeSort::v1, v1, EdgeSort::v2, and v2.
Referenced by mesh_calc_edges_mdata().
Definition at line 1318 of file mesh_validate.cc.
References EdgeSort::v1, v1, EdgeSort::v2, v2, and x2.
Referenced by mesh_calc_edges_mdata().
|
static |
Definition at line 38 of file mesh_validate.cc.
Referenced by BKE_mesh_validate().