Blender V4.3
editmesh_automerge.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
14#include "BKE_editmesh.hh"
15
16#include "DNA_object_types.h"
17
18#include "ED_mesh.hh"
19
21
22// #define DEBUG_TIME
23#ifdef DEBUG_TIME
24# include "BLI_time.h"
25#endif
26
27/* use bmesh operator flags for a few operators */
28#define BMO_ELE_TAG 1
29
30/* -------------------------------------------------------------------- */
36void EDBM_automerge(Object *obedit, bool update, const char hflag, const float dist)
37{
39 BMesh *bm = em->bm;
40 int totvert_prev = bm->totvert;
41
42 BMOperator findop, weldop;
43
44 /* Search for doubles among all vertices, but only merge non-VERT_KEEP
45 * vertices into VERT_KEEP vertices. */
47 &findop,
49 "find_doubles verts=%av keep_verts=%Hv dist=%f",
50 hflag,
51 dist);
52
53 BMO_op_exec(bm, &findop);
54
55 /* weld the vertices */
56 BMO_op_init(bm, &weldop, BMO_FLAG_DEFAULTS, "weld_verts");
57 BMO_slot_copy(&findop, slots_out, "targetmap.out", &weldop, slots_in, "targetmap");
58 BMO_op_exec(bm, &weldop);
59
60 BMO_op_finish(bm, &findop);
61 BMO_op_finish(bm, &weldop);
62
64 params.calc_looptris = true;
65 params.calc_normals = false;
66 params.is_destructive = true;
67 if ((totvert_prev != bm->totvert) && update) {
68 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
69 }
70}
71
74/* -------------------------------------------------------------------- */
81 const bool /*split_edges*/,
82 const bool split_faces,
83 const bool update,
84 const char hflag,
85 const float dist)
86{
87 bool ok = false;
88
90 BMesh *bm = em->bm;
91
92#ifdef DEBUG_TIME
93 em->bm = BM_mesh_copy(bm);
94
95 double t1 = BLI_time_now_seconds();
96 EDBM_automerge(obedit, false, hflag, dist);
97 t1 = BLI_time_now_seconds() - t1;
98
99 BM_mesh_free(em->bm);
100 em->bm = bm;
101 double t2 = BLI_time_now_seconds();
102#endif
103
104 BMOperator weldop;
105 BMOpSlot *slot_targetmap;
106
107 BMO_op_init(bm, &weldop, BMO_FLAG_DEFAULTS, "weld_verts");
108 slot_targetmap = BMO_slot_get(weldop.slots_in, "targetmap");
109
110 GHash *ghash_targetmap = BMO_SLOT_AS_GHASH(slot_targetmap);
111
112 ok = BM_mesh_intersect_edges(bm, hflag, dist, split_faces, ghash_targetmap);
113
114 if (ok) {
115 BMO_op_exec(bm, &weldop);
116 }
117
118 BMO_op_finish(bm, &weldop);
119
120#ifdef DEBUG_TIME
121 t2 = BLI_time_now_seconds() - t2;
122 printf("t1: %lf; t2: %lf; fac: %lf\n", t1, t2, t1 / t2);
123#endif
124
125 if (LIKELY(ok) && update) {
127 params.calc_looptris = true;
128 params.calc_normals = false;
129 params.is_destructive = true;
130 EDBM_update(static_cast<Mesh *>(obedit->data), &params);
131 }
132}
133
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:63
Platform independent time functions.
double BLI_time_now_seconds(void)
Definition time.c:65
#define LIKELY(x)
Object is a sort of wrapper for general info.
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
BMesh * BM_mesh_copy(BMesh *bm_old)
bool BM_mesh_intersect_edges(BMesh *bm, const char hflag, const float dist, const bool split_faces, GHash *r_targetmap)
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
#define BMO_slot_copy(op_src, slots_src, slot_name_src, op_dst, slots_dst, slot_name_dst)
#define BMO_SLOT_AS_GHASH(slot)
void BMO_op_init(BMesh *bm, BMOperator *op, int flag, const char *opname)
BMESH OPSTACK INIT OP.
bool BMO_op_initf(BMesh *bm, BMOperator *op, int flag, const char *fmt,...)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
#define BMO_FLAG_DEFAULTS
#define printf
void EDBM_automerge(Object *obedit, bool update, const char hflag, const float dist)
void EDBM_automerge_and_split(Object *obedit, const bool, const bool split_faces, const bool update, const char hflag, const float dist)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static void update(bNodeTree *ntree)
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
int totvert