Blender  V2.93
Classes | Typedefs | Functions
mesh_merge.c File Reference
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "BLI_edgehash.h"
#include "BLI_ghash.h"
#include "BLI_utildefines.h"
#include "BLI_utildefines_stack.h"
#include "BKE_customdata.h"
#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"

Go to the source code of this file.

Classes

struct  PolyKey
 

Typedefs

typedef struct PolyKey PolyKey
 

Functions

static int cddm_poly_compare (MLoop *mloop_array, MPoly *mpoly_source, MPoly *mpoly_target, const int *vtargetmap, const int direct_reverse)
 
static unsigned int poly_gset_hash_fn (const void *key)
 
static bool poly_gset_compare_fn (const void *k1, const void *k2)
 
MeshBKE_mesh_merge_verts (Mesh *mesh, const int *vtargetmap, const int tot_vtargetmap, const int merge_mode)
 

Typedef Documentation

◆ PolyKey

typedef struct PolyKey PolyKey

Function Documentation

◆ BKE_mesh_merge_verts()

Mesh* BKE_mesh_merge_verts ( Mesh mesh,
const int *  vtargetmap,
const int  tot_vtargetmap,
const int  merge_mode 
)

Merge Verts

This frees the given mesh and returns a new mesh.

Parameters
vtargetmapThe table that maps vertices to target vertices. a value of -1 indicates a vertex is a target, and is to be kept. This array is aligned with 'mesh->totvert'
Warning
vtargetmap must not contain any chained mapping (v1 -> v2 -> v3 etc.), this is not supported and will likely generate corrupted geometry.
Parameters
tot_vtargetmapThe number of non '-1' values in vtargetmap. (not the size)
merge_modeenum with two modes.
  • MESH_MERGE_VERTS_DUMP_IF_MAPPED When called by the Mirror Modifier, In this mode it skips any faces that have all vertices merged (to avoid creating pairs of faces sharing the same set of vertices)
  • MESH_MERGE_VERTS_DUMP_IF_EQUAL When called by the Array Modifier, In this mode, faces where all vertices are merged are double-checked, to see whether all target vertices actually make up a poly already. Indeed it could be that all of a poly's vertices are merged, but merged to vertices that do not make up a single poly, in which case the original poly should not be dumped. Actually this later behavior could apply to the Mirror Modifier as well, but the additional checks are costly and not necessary in the case of mirror, because each vertex is only merged to its own mirror.
Note
BKE_mesh_tessface_calc_ex has to run on the returned DM if you want to access tessfaces.

Definition at line 239 of file mesh_merge.c.

References BKE_mesh_vert_poly_map_create(), BLI_assert, BLI_edgehash_ensure_p(), BLI_edgehash_new_ex(), BLI_edgehash_remove(), BLI_gset_flag_set(), BLI_gset_haskey(), BLI_gset_insert(), BLI_gset_new_ex(), Freestyle::c, cddm_poly_compare(), MeshElemMap::count, MLoop::e, ELEM, GHASH_FLAG_ALLOW_DUPES, PolyKey::hash_sum, PolyKey::hash_xor, MeshElemMap::indices, LIKELY, MPoly::loopstart, ME_VERT_TMP_TAG, Mesh::medge, MEM_malloc_arrayN, mesh, MESH_MERGE_VERTS_DUMP_IF_EQUAL, MESH_MERGE_VERTS_DUMP_IF_MAPPED, Mesh::mloop, Mesh::mpoly, Mesh::mvert, NULL, POINTER_AS_INT, POINTER_FROM_INT, poly_gset_compare_fn(), poly_gset_hash_fn(), PolyKey::poly_index, result, STACK_DECLARE, STACK_DISCARD, STACK_INIT, STACK_PUSH, STACK_PUSH_RET_PTR, STACK_SIZE, Mesh::totedge, Mesh::totloop, MPoly::totloop, PolyKey::totloops, Mesh::totpoly, Mesh::totvert, UNLIKELY, MLoop::v, v1, MEdge::v1, v2, and MEdge::v2.

Referenced by arrayModifier_doArray(), BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(), and mesh_remove_doubles_on_axis().

◆ cddm_poly_compare()

static int cddm_poly_compare ( MLoop mloop_array,
MPoly mpoly_source,
MPoly mpoly_target,
const int *  vtargetmap,
const int  direct_reverse 
)
static

Poly compare with vtargetmap Function used by BKE_mesh_merge_verts. The function compares poly_source after applying vtargetmap, with poly_target. The two polys are identical if they share the same vertices in the same order, or in reverse order, but starting position loopstart may be different. The function is called with direct_reverse=1 for same order (i.e. same normal), and may be called again with direct_reverse=-1 for reverse order.

Returns
1 if polys are identical, 0 if polys are different.

Definition at line 50 of file mesh_merge.c.

References BLI_assert, ELEM, if(), MPoly::loopstart, MPoly::totloop, and MLoop::v.

Referenced by BKE_mesh_merge_verts().

◆ poly_gset_compare_fn()

static bool poly_gset_compare_fn ( const void *  k1,
const void *  k2 
)
static

Definition at line 194 of file mesh_merge.c.

References PolyKey::hash_sum, PolyKey::hash_xor, and PolyKey::totloops.

Referenced by BKE_mesh_merge_verts().

◆ poly_gset_hash_fn()

static unsigned int poly_gset_hash_fn ( const void *  key)
static

Definition at line 188 of file mesh_merge.c.

References PolyKey::hash_sum.

Referenced by BKE_mesh_merge_verts().