Blender  V2.93
bmo_symmetrize.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
23 #include "BLI_math.h"
24 #include "BLI_utildefines.h"
25 
26 #include "bmesh.h"
28 
29 #define ELE_OUT 1
30 
32 {
33  const float dist = BMO_slot_float_get(op->slots_in, "dist");
34  const int direction = BMO_slot_int_get(op->slots_in, "direction");
35  const int axis = direction % 3;
36 
37  BMOperator op_bisect;
38  BMOperator op_dupe;
39  BMOperator op_weld;
40 
41  BMOpSlot *slot_vertmap;
42  BMOpSlot *slot_targetmap;
43 
44  float plane_no[3];
45  float scale[3];
46 
47  BMOIter siter;
48  BMVert *v;
49 
50  copy_v3_fl(plane_no, 0.0f);
51  copy_v3_fl(scale, 1.0f);
52 
53  plane_no[axis] = direction > 2 ? -1.0f : 1.0f;
54  scale[axis] *= -1.0f;
55 
56  /* Cut in half */
58  &op_bisect,
59  op->flag,
60  "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b",
61  op,
62  "input",
63  plane_no,
64  dist,
65  true,
66  true);
67 
68  BMO_op_exec(bm, &op_bisect);
69 
70  /* Duplicate */
71  BMO_op_initf(bm, &op_dupe, op->flag, "duplicate geom=%S", &op_bisect, "geom.out");
72 
73  BMO_op_exec(bm, &op_dupe);
74 
75  /* Flag for output (some will be merged) */
78 
80  op->flag,
81  "scale verts=%S vec=%v use_shapekey=%s",
82  &op_dupe,
83  "geom.out",
84  scale,
85  op,
86  "use_shapekey");
87 
88  /* important 'flip_multires' is disabled,
89  * otherwise multi-res data will be reversed, see: T47788 */
90  BMO_op_callf(bm, op->flag, "reverse_faces faces=%S", &op_dupe, "geom.out");
91 
92  /* Weld verts */
93  BMO_op_init(bm, &op_weld, op->flag, "weld_verts");
94 
95  slot_vertmap = BMO_slot_get(op_dupe.slots_out, "vert_map.out");
96  slot_targetmap = BMO_slot_get(op_weld.slots_in, "targetmap");
97 
98  BMO_ITER (v, &siter, op_bisect.slots_out, "geom_cut.out", BM_VERT) {
99  BMVert *v_dupe = BMO_slot_map_elem_get(slot_vertmap, v);
100  BMO_slot_map_elem_insert(&op_weld, slot_targetmap, v_dupe, v);
101  }
102 
103  BMO_op_exec(bm, &op_weld);
104 
105  /* Cleanup */
106  BMO_op_finish(bm, &op_weld);
107 
108  BMO_op_finish(bm, &op_dupe);
109  BMO_op_finish(bm, &op_bisect);
110 
111  /* Create output */
113 }
MINLINE void copy_v3_fl(float r[3], float f)
#define BM_ALL_NOLOOP
Definition: bmesh_class.h:411
@ BM_VERT
Definition: bmesh_class.h:383
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BMO_slot_buffer_flag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char htype, const short oflag)
BMO_FLAG_BUFFER.
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
bool BMO_op_initf(BMesh *bm, BMOperator *op, const int flag, const char *fmt,...)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
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.
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const char htype, const short oflag)
void BMO_op_init(BMesh *bm, BMOperator *op, const int flag, const char *opname)
BMESH OPSTACK INIT OP.
bool BMO_op_callf(BMesh *bm, const 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]