1 #include "MEM_guardedalloc.h"
3 #include "DNA_listBase.h"
4 #include "DNA_customdata_types.h"
5 #include "DNA_mesh_types.h"
6 #include "DNA_meshdata_types.h"
7 #include "DNA_object_types.h"
8 #include "DNA_scene_types.h"
12 #include "BKE_customdata.h"
14 #include "BKE_global.h"
15 #include "BKE_DerivedMesh.h"
16 #include "BKE_cdderivedmesh.h"
17 #include "BKE_utildefines.h"
19 #include "BLI_editVert.h"
20 #include "mesh_intern.h"
24 #include "BLI_blenlib.h"
25 #include "BLI_edgehash.h"
26 #include "BLI_array.h"
27 #include "BLI_utildefines.h"
30 #include "bmesh_operators_private.h" /* own include */
41 void bmesh_mirror_exec(BMesh *bm, BMOperator *op) {
42 BMOperator dupeop, weldop;
45 BMVert *v, *v2, **vmap = NULL;
46 BLI_array_declare(vmap);
47 BMEdge /* *e, */ **emap = NULL;
48 BLI_array_declare(emap);
51 float scale[3] = {1.0f, 1.0f, 1.0f};
52 float dist = BMO_Get_Float(op, "mergedist");
53 int i, ototvert, ototedge, axis = BMO_Get_Int(op, "axis");
54 int mirroru = BMO_Get_Int(op, "mirror_u");
55 int mirrorv = BMO_Get_Int(op, "mirror_v");
57 ototvert = bm->totvert;
58 ototedge = bm->totedge;
60 BMO_Get_Mat4(op, "mat", mtx);
61 invert_m4_m4(imtx, mtx);
63 BMO_InitOpf(bm, &dupeop, "dupe geom=%s", op, "geom");
64 BMO_Exec_Op(bm, &dupeop);
66 BMO_Flag_Buffer(bm, &dupeop, "newout", ELE_NEW, BM_ALL);
68 /*create old -> new mapping*/
70 v2 = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);
71 BMO_ITER(v, &siter, bm, &dupeop, "newout", BM_VERT) {
72 BLI_array_growone(vmap);
76 v2 = BMIter_Step(&iter);
81 /*feed old data to transform bmop*/
83 BMO_CallOpf(bm, "transform verts=%fv mat=%m4", ELE_NEW, mtx);
84 BMO_CallOpf(bm, "scale verts=%fv vec=%v", ELE_NEW, scale);
85 BMO_CallOpf(bm, "transform verts=%fv mat=%m4", ELE_NEW, imtx);
87 BMO_Init_Op(&weldop, "weldverts");
89 v = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);
90 for (i=0; i<ototvert; i++) {
91 if (ABS(v->co[axis]) <= dist) {
92 BMO_Insert_MapPointer(bm, &weldop, "targetmap", vmap[i], v);
94 v = BMIter_Step(&iter);
97 if (mirroru || mirrorv) {
104 BMO_ITER(f, &siter, bm, &dupeop, "newout", BM_FACE) {
105 BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
106 totlayer = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV);
107 for (i=0; i<totlayer; i++) {
108 luv = CustomData_bmesh_get_n(&bm->ldata, l->head.data, CD_MLOOPUV, i);
110 luv->uv[0] = 1.0 - luv->uv[0];
112 luv->uv[1] = 1.0 - luv->uv[1];
118 BMO_Exec_Op(bm, &weldop);
120 BMO_Finish_Op(bm, &weldop);
121 BMO_Finish_Op(bm, &dupeop);
123 BMO_Flag_To_Slot(bm, op, "newout", ELE_NEW, BM_ALL);
125 BLI_array_free(vmap);
126 BLI_array_free(emap);