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