2012-02-19 18:31:04 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Joseph Eagar.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2012-04-06 09:21:19 +00:00
|
|
|
/** \file blender/bmesh/operators/bmo_mirror.c
|
|
|
|
* \ingroup bmesh
|
2013-03-30 08:54:50 +00:00
|
|
|
*
|
|
|
|
* Basic mirror, optionally with UVs's.
|
2012-04-06 09:21:19 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_array.h"
|
|
|
|
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
|
|
|
|
#include "bmesh.h"
|
2012-03-08 03:25:53 +00:00
|
|
|
#include "intern/bmesh_operators_private.h" /* own include */
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
#define ELE_NEW 1
|
|
|
|
|
2012-02-28 09:48:00 +00:00
|
|
|
void bmo_mirror_exec(BMesh *bm, BMOperator *op)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
BMOperator dupeop, weldop;
|
|
|
|
BMOIter siter;
|
|
|
|
BMIter iter;
|
2012-04-17 05:09:37 +00:00
|
|
|
BMVert *v /* , *v2 */ /* UNUSED */, **vmap = NULL;
|
2012-02-19 18:31:04 +00:00
|
|
|
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};
|
2012-11-20 05:50:19 +00:00
|
|
|
float dist = BMO_slot_float_get(op->slots_in, "merge_dist");
|
2012-03-06 12:51:17 +00:00
|
|
|
int i, ototvert /*, ototedge */;
|
2012-11-19 14:58:31 +00:00
|
|
|
int axis = BMO_slot_int_get(op->slots_in, "axis");
|
2013-01-14 16:42:43 +00:00
|
|
|
bool mirror_u = BMO_slot_bool_get(op->slots_in, "mirror_u");
|
|
|
|
bool mirror_v = BMO_slot_bool_get(op->slots_in, "mirror_v");
|
2012-11-20 13:29:27 +00:00
|
|
|
BMOpSlot *slot_targetmap;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
ototvert = bm->totvert;
|
2012-03-06 12:51:17 +00:00
|
|
|
/* ototedge = bm->totedge; */ /* UNUSED */
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-11-28 00:16:06 +00:00
|
|
|
BMO_slot_mat4_get(op->slots_in, "matrix", mtx);
|
2012-02-19 18:31:04 +00:00
|
|
|
invert_m4_m4(imtx, mtx);
|
|
|
|
|
2012-07-21 00:58:02 +00:00
|
|
|
BMO_op_initf(bm, &dupeop, op->flag, "duplicate geom=%s", op, "geom");
|
2012-02-19 18:31:04 +00:00
|
|
|
BMO_op_exec(bm, &dupeop);
|
|
|
|
|
2012-11-27 00:50:59 +00:00
|
|
|
BMO_slot_buffer_flag_enable(bm, dupeop.slots_out, "geom.out", BM_ALL_NOLOOP, ELE_NEW);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
/* create old -> new mappin */
|
|
|
|
i = 0;
|
2012-04-17 05:09:37 +00:00
|
|
|
/* v2 = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); */ /* UNUSED */
|
2012-11-20 05:50:19 +00:00
|
|
|
BMO_ITER (v, &siter, dupeop.slots_out, "geom.out", BM_VERT) {
|
2012-04-28 15:14:16 +00:00
|
|
|
BLI_array_grow_one(vmap);
|
2012-02-19 18:31:04 +00:00
|
|
|
vmap[i] = v;
|
2012-04-17 05:09:37 +00:00
|
|
|
/* v2 = BM_iter_step(&iter); */ /* UNUSED */
|
2012-02-19 18:31:04 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
bm->elem_index_dirty |= BM_VERT;
|
|
|
|
|
|
|
|
/* feed old data to transform bmo */
|
|
|
|
scale[axis] = -1.0f;
|
2012-11-28 00:16:06 +00:00
|
|
|
BMO_op_callf(bm, op->flag, "transform verts=%fv matrix=%m4", ELE_NEW, mtx);
|
2012-07-21 00:58:02 +00:00
|
|
|
BMO_op_callf(bm, op->flag, "scale verts=%fv vec=%v", ELE_NEW, scale);
|
2012-11-28 00:16:06 +00:00
|
|
|
BMO_op_callf(bm, op->flag, "transform verts=%fv matrix=%m4", ELE_NEW, imtx);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-07-21 00:58:02 +00:00
|
|
|
BMO_op_init(bm, &weldop, op->flag, "weld_verts");
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-11-20 13:29:27 +00:00
|
|
|
slot_targetmap = BMO_slot_get(weldop.slots_in, "targetmap");
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
v = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL);
|
|
|
|
for (i = 0; i < ototvert; i++) {
|
2012-11-06 00:18:01 +00:00
|
|
|
if (fabsf(v->co[axis]) <= dist) {
|
2012-11-26 03:16:29 +00:00
|
|
|
BMO_slot_map_elem_insert(&weldop, slot_targetmap, vmap[i], v);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
v = BM_iter_step(&iter);
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:42:43 +00:00
|
|
|
if (mirror_u || mirror_v) {
|
2012-02-19 18:31:04 +00:00
|
|
|
BMFace *f;
|
|
|
|
BMLoop *l;
|
|
|
|
MLoopUV *luv;
|
|
|
|
int totlayer;
|
|
|
|
BMIter liter;
|
|
|
|
|
2012-11-20 05:50:19 +00:00
|
|
|
BMO_ITER (f, &siter, dupeop.slots_out, "geom.out", BM_FACE) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
|
2012-02-19 18:31:04 +00:00
|
|
|
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);
|
2013-01-14 16:42:43 +00:00
|
|
|
if (mirror_u)
|
2012-02-19 18:31:04 +00:00
|
|
|
luv->uv[0] = 1.0f - luv->uv[0];
|
2013-01-14 16:42:43 +00:00
|
|
|
if (mirror_v)
|
2012-02-19 18:31:04 +00:00
|
|
|
luv->uv[1] = 1.0f - luv->uv[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BMO_op_exec(bm, &weldop);
|
|
|
|
|
|
|
|
BMO_op_finish(bm, &weldop);
|
|
|
|
BMO_op_finish(bm, &dupeop);
|
|
|
|
|
2012-11-27 00:50:59 +00:00
|
|
|
BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_ALL_NOLOOP, ELE_NEW);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
BLI_array_free(vmap);
|
|
|
|
BLI_array_free(emap);
|
|
|
|
}
|