Blender  V3.3
bmo_symmetrize.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include "BLI_math.h"
10 #include "BLI_utildefines.h"
11 
12 #include "bmesh.h"
14 
15 #define ELE_OUT 1
16 
18 {
19  const float dist = BMO_slot_float_get(op->slots_in, "dist");
20  const int direction = BMO_slot_int_get(op->slots_in, "direction");
21  const int axis = direction % 3;
22 
23  BMOperator op_bisect;
24  BMOperator op_dupe;
25  BMOperator op_weld;
26 
27  BMOpSlot *slot_vertmap;
28  BMOpSlot *slot_targetmap;
29 
30  float plane_no[3];
31  float scale[3];
32 
33  BMOIter siter;
34  BMVert *v;
35 
36  copy_v3_fl(plane_no, 0.0f);
37  copy_v3_fl(scale, 1.0f);
38 
39  plane_no[axis] = direction > 2 ? -1.0f : 1.0f;
40  scale[axis] *= -1.0f;
41 
42  /* Cut in half */
44  &op_bisect,
45  op->flag,
46  "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b",
47  op,
48  "input",
49  plane_no,
50  dist,
51  true,
52  true);
53 
54  BMO_op_exec(bm, &op_bisect);
55 
56  /* Duplicate */
57  BMO_op_initf(bm, &op_dupe, op->flag, "duplicate geom=%S", &op_bisect, "geom.out");
58 
59  BMO_op_exec(bm, &op_dupe);
60 
61  /* Flag for output (some will be merged) */
64 
66  op->flag,
67  "scale verts=%S vec=%v use_shapekey=%s",
68  &op_dupe,
69  "geom.out",
70  scale,
71  op,
72  "use_shapekey");
73 
74  /* important 'flip_multires' is disabled,
75  * otherwise multi-res data will be reversed, see: T47788 */
76  BMO_op_callf(bm, op->flag, "reverse_faces faces=%S", &op_dupe, "geom.out");
77 
78  /* Weld verts */
79  BMO_op_init(bm, &op_weld, op->flag, "weld_verts");
80 
81  slot_vertmap = BMO_slot_get(op_dupe.slots_out, "vert_map.out");
82  slot_targetmap = BMO_slot_get(op_weld.slots_in, "targetmap");
83 
84  BMO_ITER (v, &siter, op_bisect.slots_out, "geom_cut.out", BM_VERT) {
85  BMVert *v_dupe = BMO_slot_map_elem_get(slot_vertmap, v);
86  BMO_slot_map_elem_insert(&op_weld, slot_targetmap, v_dupe, v);
87  }
88 
89  BMO_op_exec(bm, &op_weld);
90 
91  /* Cleanup */
92  BMO_op_finish(bm, &op_weld);
93 
94  BMO_op_finish(bm, &op_dupe);
95  BMO_op_finish(bm, &op_bisect);
96 
97  /* Create output */
99 }
MINLINE void copy_v3_fl(float r[3], float f)
#define BM_ALL_NOLOOP
Definition: bmesh_class.h:411
@ BM_VERT
Definition: bmesh_class.h:383
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BMO_slot_buffer_flag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
BMO_FLAG_BUFFER.
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
void BMO_op_init(BMesh *bm, BMOperator *op, int flag, const char *opname)
BMESH OPSTACK INIT OP.
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
bool BMO_op_initf(BMesh *bm, BMOperator *op, int flag, const char *fmt,...)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
bool BMO_op_callf(BMesh *bm, int flag, const char *fmt,...)
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void bmo_symmetrize_exec(BMesh *bm, BMOperator *op)
#define ELE_OUT
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]