1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "DNA_customdata_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include <string.h>
#include "BKE_customdata.h"
#include "BKE_mesh.h"
#include "BKE_global.h"
#include "BKE_DerivedMesh.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_utildefines.h"
#include "BLI_editVert.h"
#include "mesh_intern.h"
#include "ED_mesh.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BLI_edgehash.h"
#include "BLI_array.h"
#include "BLI_utildefines.h"
#include "bmesh.h"
#include "bmesh_operators_private.h" /* own include */
/*
* MIRROR.C
*
* mirror bmop.
*
*/
#define ELE_NEW 1
void bmesh_mirror_exec(BMesh *bm, BMOperator *op)
{
BMOperator dupeop, weldop;
BMOIter siter;
BMIter iter;
BMVert *v, *v2, **vmap = NULL;
BLI_array_declare(vmap);
BMEdge /* *e, */ **emap = NULL;
BLI_array_declare(emap);
float mtx[4][4];
float imtx[4][4];
float scale[3] = {1.0f, 1.0f, 1.0f};
float dist = BMO_Get_Float(op, "mergedist");
int i, ototvert, ototedge, axis = BMO_Get_Int(op, "axis");
int mirroru = BMO_Get_Int(op, "mirror_u");
int mirrorv = BMO_Get_Int(op, "mirror_v");
ototvert = bm->totvert;
ototedge = bm->totedge;
BMO_Get_Mat4(op, "mat", mtx);
invert_m4_m4(imtx, mtx);
BMO_InitOpf(bm, &dupeop, "dupe geom=%s", op, "geom");
BMO_Exec_Op(bm, &dupeop);
BMO_Flag_Buffer(bm, &dupeop, "newout", ELE_NEW, BM_ALL);
/*create old -> new mapping*/
i = 0;
v2 = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);
BMO_ITER(v, &siter, bm, &dupeop, "newout", BM_VERT) {
BLI_array_growone(vmap);
vmap[i] = v;
BM_SetIndex(v2, i);
v2 = BMIter_Step(&iter);
i += 1;
}
/*feed old data to transform bmop*/
scale[axis] = -1.0f;
BMO_CallOpf(bm, "transform verts=%fv mat=%m4", ELE_NEW, mtx);
BMO_CallOpf(bm, "scale verts=%fv vec=%v", ELE_NEW, scale);
BMO_CallOpf(bm, "transform verts=%fv mat=%m4", ELE_NEW, imtx);
BMO_Init_Op(&weldop, "weldverts");
v = BMIter_New(&iter, bm, BM_VERTS_OF_MESH, NULL);
for (i=0; i<ototvert; i++) {
if (ABS(v->co[axis]) <= dist) {
BMO_Insert_MapPointer(bm, &weldop, "targetmap", vmap[i], v);
}
v = BMIter_Step(&iter);
}
if (mirroru || mirrorv) {
BMFace *f;
BMLoop *l;
MLoopUV *luv;
int totlayer;
BMIter liter;
BMO_ITER(f, &siter, bm, &dupeop, "newout", BM_FACE) {
BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
totlayer = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV);
for (i=0; i<totlayer; i++) {
luv = CustomData_bmesh_get_n(&bm->ldata, l->head.data, CD_MLOOPUV, i);
if (mirroru)
luv->uv[0]= 1.0f - luv->uv[0];
if (mirrorv)
luv->uv[1]= 1.0f - luv->uv[1];
}
}
}
}
BMO_Exec_Op(bm, &weldop);
BMO_Finish_Op(bm, &weldop);
BMO_Finish_Op(bm, &dupeop);
BMO_Flag_To_Slot(bm, op, "newout", ELE_NEW, BM_ALL);
BLI_array_free(vmap);
BLI_array_free(emap);
}
|