Blender V4.3
bmo_symmetrize.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include "BLI_math_vector.h"
12#include "BLI_utildefines.h"
13
14#include "bmesh.hh"
16
17#define ELE_OUT 1
18
20{
21 const float dist = BMO_slot_float_get(op->slots_in, "dist");
22 const int direction = BMO_slot_int_get(op->slots_in, "direction");
23 const int axis = direction % 3;
24
25 BMOperator op_bisect;
26 BMOperator op_dupe;
27 BMOperator op_weld;
28
29 BMOpSlot *slot_vertmap;
30 BMOpSlot *slot_targetmap;
31
32 float plane_no[3];
33 float scale[3];
34
35 BMOIter siter;
36 BMVert *v;
37
38 copy_v3_fl(plane_no, 0.0f);
39 copy_v3_fl(scale, 1.0f);
40
41 plane_no[axis] = direction > 2 ? -1.0f : 1.0f;
42 scale[axis] *= -1.0f;
43
44 /* Cut in half */
46 &op_bisect,
47 op->flag,
48 "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b",
49 op,
50 "input",
51 plane_no,
52 dist,
53 true,
54 true);
55
56 BMO_op_exec(bm, &op_bisect);
57
58 /* Duplicate */
59 BMO_op_initf(bm, &op_dupe, op->flag, "duplicate geom=%S", &op_bisect, "geom.out");
60
61 BMO_op_exec(bm, &op_dupe);
62
63 /* Flag for output (some will be merged) */
66
68 op->flag,
69 "scale verts=%S vec=%v use_shapekey=%s",
70 &op_dupe,
71 "geom.out",
72 scale,
73 op,
74 "use_shapekey");
75
76 /* important 'flip_multires' is disabled,
77 * otherwise multi-res data will be reversed, see: #47788 */
78 BMO_op_callf(bm, op->flag, "reverse_faces faces=%S", &op_dupe, "geom.out");
79
80 /* Weld verts */
81 BMO_op_init(bm, &op_weld, op->flag, "weld_verts");
82
83 slot_vertmap = BMO_slot_get(op_dupe.slots_out, "vert_map.out");
84 slot_targetmap = BMO_slot_get(op_weld.slots_in, "targetmap");
85
86 BMO_ITER (v, &siter, op_bisect.slots_out, "geom_cut.out", BM_VERT) {
87 BMVert *v_dupe = static_cast<BMVert *>(BMO_slot_map_elem_get(slot_vertmap, v));
88 BMO_slot_map_elem_insert(&op_weld, slot_targetmap, v_dupe, v);
89 }
90
91 BMO_op_exec(bm, &op_weld);
92
93 /* Cleanup */
94 BMO_op_finish(bm, &op_weld);
95
96 BMO_op_finish(bm, &op_dupe);
97 BMO_op_finish(bm, &op_bisect);
98
99 /* Create output */
101}
MINLINE void copy_v3_fl(float r[3], float f)
#define BM_ALL_NOLOOP
ATTR_WARN_UNUSED_RESULT BMesh * bm
#define BM_VERT
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)
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.
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,...)
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]