Blender  V3.3
editmesh_automerge.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. All rights reserved. */
3 
13 #include "BKE_editmesh.h"
14 
15 #include "DNA_object_types.h"
16 
17 #include "ED_mesh.h"
18 
20 
21 //#define DEBUG_TIME
22 #ifdef DEBUG_TIME
23 # include "PIL_time.h"
24 #endif
25 
26 /* use bmesh operator flags for a few operators */
27 #define BMO_ELE_TAG 1
28 
29 /* -------------------------------------------------------------------- */
35 void EDBM_automerge(Object *obedit, bool update, const char hflag, const float dist)
36 {
38  BMesh *bm = em->bm;
39  int totvert_prev = bm->totvert;
40 
41  BMOperator findop, weldop;
42 
43  /* Search for doubles among all vertices, but only merge non-VERT_KEEP
44  * vertices into VERT_KEEP vertices. */
46  &findop,
48  "find_doubles verts=%av keep_verts=%Hv dist=%f",
49  hflag,
50  dist);
51 
52  BMO_op_exec(bm, &findop);
53 
54  /* weld the vertices */
55  BMO_op_init(bm, &weldop, BMO_FLAG_DEFAULTS, "weld_verts");
56  BMO_slot_copy(&findop, slots_out, "targetmap.out", &weldop, slots_in, "targetmap");
57  BMO_op_exec(bm, &weldop);
58 
59  BMO_op_finish(bm, &findop);
60  BMO_op_finish(bm, &weldop);
61 
62  if ((totvert_prev != bm->totvert) && update) {
63  EDBM_update(obedit->data,
64  &(const struct EDBMUpdate_Params){
65  .calc_looptri = true,
66  .calc_normals = false,
67  .is_destructive = true,
68  });
69  }
70 }
71 
74 /* -------------------------------------------------------------------- */
81  const bool UNUSED(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 = PIL_check_seconds_timer();
96  EDBM_automerge(obedit, false, hflag, dist);
97  t1 = PIL_check_seconds_timer() - t1;
98 
99  BM_mesh_free(em->bm);
100  em->bm = bm;
101  double t2 = PIL_check_seconds_timer();
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 = PIL_check_seconds_timer() - t2;
122  printf("t1: %lf; t2: %lf; fac: %lf\n", t1, t2, t1 / t2);
123 #endif
124 
125  if (LIKELY(ok) && update) {
126  EDBM_update(obedit->data,
127  &(const struct EDBMUpdate_Params){
128  .calc_looptri = true,
129  .calc_normals = false,
130  .is_destructive = true,
131  });
132  }
133 }
134 
BMEditMesh * BKE_editmesh_from_object(struct Object *ob)
Return the BMEditMesh for a given object.
Definition: editmesh.c:58
#define UNUSED(x)
#define LIKELY(x)
Object is a sort of wrapper for general info.
void EDBM_update(struct Mesh *me, const struct EDBMUpdate_Params *params)
Platform independent time functions.
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.
Definition: bmesh_mesh.cc:258
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.
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
#define BMO_FLAG_DEFAULTS
void EDBM_automerge_and_split(Object *obedit, const bool UNUSED(split_edges), const bool split_faces, const bool update, const char hflag, const float dist)
void EDBM_automerge(Object *obedit, bool update, const char hflag, const float dist)
static void update(bNodeTree *ntree)
struct BMesh * bm
Definition: BKE_editmesh.h:40
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
int totvert
Definition: bmesh_class.h:297
void * data
double PIL_check_seconds_timer(void)
Definition: time.c:64