Blender V5.3
bmo_mirror.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_base_c.hh"
12
13#include "BKE_customdata.hh"
14
15#include "bmesh.hh"
16#include "intern/bmesh_operators_private.hh" /* own include */
17
18namespace blender {
19
20#define ELE_NEW 1
21
23{
24 BMOperator dupeop, weldop;
25 BMOIter siter;
26 BMVert *v;
27 float scale[3] = {1.0f, 1.0f, 1.0f};
28 float dist = BMO_slot_float_get(op->slots_in, "merge_dist");
29 int i;
30 int axis = BMO_slot_int_get(op->slots_in, "axis");
31 bool mirror_u = BMO_slot_bool_get(op->slots_in, "mirror_u");
32 bool mirror_v = BMO_slot_bool_get(op->slots_in, "mirror_v");
33 bool mirror_udim = BMO_slot_bool_get(op->slots_in, "mirror_udim");
34 BMOpSlot *slot_targetmap;
35 BMOpSlot *slot_vertmap;
36
37 BMO_op_initf(bm, &dupeop, op->flag, "duplicate geom=%s", op, "geom");
38 BMO_op_exec(bm, &dupeop);
39
41
42 /* feed old data to transform bmo */
43 scale[axis] = -1.0f;
45 op->flag,
46 "scale verts=%fv vec=%v space=%s use_shapekey=%s",
47 ELE_NEW,
48 scale,
49 op,
50 "matrix",
51 op,
52 "use_shapekey");
53
54 BMO_op_init(bm, &weldop, op->flag, "weld_verts");
55
56 slot_targetmap = BMO_slot_get(weldop.slots_in, "targetmap");
57 slot_vertmap = BMO_slot_get(dupeop.slots_out, "vert_map.out");
58
59 BMO_ITER (v, &siter, op->slots_in, "geom", BM_VERT) {
60 if (fabsf(v->co[axis]) <= dist) {
61 BMVert *v_new = static_cast<BMVert *>(BMO_slot_map_elem_get(slot_vertmap, v));
62 BLI_assert(v_new != nullptr);
63 BMO_slot_map_elem_insert(&weldop, slot_targetmap, v_new, v);
64 }
65 }
66
67 if (mirror_u || mirror_v) {
68 BMFace *f;
69 BMLoop *l;
70 float *luv;
71 const int totlayer = CustomData_number_of_layers(&bm->ldata, CD_PROP_FLOAT2);
72 BMIter liter;
73
74 BMO_ITER (f, &siter, dupeop.slots_out, "geom.out", BM_FACE) {
75 BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
76 for (i = 0; i < totlayer; i++) {
77 luv = static_cast<float *>(
79 if (mirror_u) {
80 float uv_u = luv[0];
81 if (mirror_udim) {
82 luv[0] = ceilf(uv_u) - fmodf(uv_u, 1.0f);
83 }
84 else {
85 luv[0] = 1.0f - uv_u;
86 }
87 }
88 if (mirror_v) {
89 float uv_v = luv[1];
90 if (mirror_udim) {
91 luv[1] = ceilf(uv_v) - fmodf(uv_v, 1.0f);
92 }
93 else {
94 luv[1] = 1.0f - uv_v;
95 }
96 }
97 }
98 }
99 }
100 }
101
102 BMO_op_exec(bm, &weldop);
103
104 BMO_op_finish(bm, &weldop);
105 BMO_op_finish(bm, &dupeop);
106
108}
109
110} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
#define BM_ALL_NOLOOP
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
#define ELE_NEW
#define fmodf(x, y)
float3x3 scale(float3x3 mat, float2 scale)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
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_mirror_exec(BMesh *bm, BMOperator *op)
Definition bmo_mirror.cc:22
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.
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
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 * CustomData_bmesh_get_n(const CustomData *data, void *block, eCustomDataType type, int n)
#define fabsf
#define ceilf
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]