Blender V5.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
10
11#include "BLI_math_vector_c.hh"
12
13#include "bmesh.hh"
15
16namespace blender {
17
18#define ELE_OUT 1
19
21{
22 const float dist = BMO_slot_float_get(op->slots_in, "dist");
23 const int direction = BMO_slot_int_get(op->slots_in, "direction");
24 const int axis = direction % 3;
25
26 BMOperator op_bisect;
27 BMOperator op_dupe;
28 BMOperator op_weld;
29
30 BMOpSlot *slot_vertmap;
31 BMOpSlot *slot_targetmap;
32
33 float plane_no[3];
34 float scale[3];
35
36 BMOIter siter;
37 BMVert *v;
38
39 copy_v3_fl(plane_no, 0.0f);
40 copy_v3_fl(scale, 1.0f);
41
42 plane_no[axis] = direction > 2 ? -1.0f : 1.0f;
43 scale[axis] *= -1.0f;
44
45 /* Cut in half */
47 &op_bisect,
48 op->flag,
49 "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b",
50 op,
51 "input",
52 plane_no,
53 dist,
54 true,
55 true);
56
57 BMO_op_exec(bm, &op_bisect);
58
59 /* Duplicate */
60 BMO_op_initf(bm, &op_dupe, op->flag, "duplicate geom=%S", &op_bisect, "geom.out");
61
62 BMO_op_exec(bm, &op_dupe);
63
64 /* Flag for output (some will be merged) */
67
69 op->flag,
70 "scale verts=%S vec=%v use_shapekey=%s",
71 &op_dupe,
72 "geom.out",
73 scale,
74 op,
75 "use_shapekey");
76
77 /* important 'flip_multires' is disabled,
78 * otherwise multi-res data will be reversed, see: #47788 */
79 BMO_op_callf(bm, op->flag, "reverse_faces faces=%S", &op_dupe, "geom.out");
80
81 /* Weld verts */
82 BMO_op_init(bm, &op_weld, op->flag, "weld_verts");
83
84 slot_vertmap = BMO_slot_get(op_dupe.slots_out, "vert_map.out");
85 slot_targetmap = BMO_slot_get(op_weld.slots_in, "targetmap");
86
87 BMO_ITER (v, &siter, op_bisect.slots_out, "geom_cut.out", BM_VERT) {
88 BMVert *v_dupe = static_cast<BMVert *>(BMO_slot_map_elem_get(slot_vertmap, v));
89 BMO_slot_map_elem_insert(&op_weld, slot_targetmap, v_dupe, v);
90 }
91
92 BMO_op_exec(bm, &op_weld);
93
94 /* Cleanup */
95 BMO_op_finish(bm, &op_weld);
96
97 BMO_op_finish(bm, &op_dupe);
98 BMO_op_finish(bm, &op_bisect);
99
100 /* Create output */
102}
103
104} // namespace blender
#define BM_ALL_NOLOOP
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
#define ELE_OUT
Definition bmo_create.cc:22
float3x3 scale(float3x3 mat, float2 scale)
BMesh Iterators.
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
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.
bool BMO_op_initf(BMesh *bm, BMOperator *op, int flag, const char *fmt,...)
ATTR_WARN_UNUSED_RESULT const BMVert * v
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)
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.
MINLINE void copy_v3_fl(float r[3], float f)
void BMO_op_init(BMesh *bm, BMOperator *op, int flag, const char *opname)
BMESH OPSTACK INIT OP.
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val)
void bmo_symmetrize_exec(BMesh *bm, BMOperator *op)
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]