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