diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-22 21:56:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-22 21:56:08 +0400 |
commit | e97f979f73ffb1872a7bb388efab883b47544e78 (patch) | |
tree | 8ba9247185bb4e7cce7181026f1cf7f0b7fa8d4b /source/blender/bmesh/operators/bmo_bisect_plane.c | |
parent | c1cc9f3376eea4664a85db82e1901f5f03e59ac0 (diff) |
new bmesh operator bisect_plane, cuts a mesh in half, takes a user defined plane as an argument, handles concave ngons which need multiple cuts.
Diffstat (limited to 'source/blender/bmesh/operators/bmo_bisect_plane.c')
-rw-r--r-- | source/blender/bmesh/operators/bmo_bisect_plane.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/source/blender/bmesh/operators/bmo_bisect_plane.c b/source/blender/bmesh/operators/bmo_bisect_plane.c new file mode 100644 index 00000000000..a4103bfec41 --- /dev/null +++ b/source/blender/bmesh/operators/bmo_bisect_plane.c @@ -0,0 +1,100 @@ +/* + * ***** 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): + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/bmesh/operators/bmo_bisect_plane.c + * \ingroup bmesh + * + * Wrapper around #BM_mesh_bisect_plane + */ + +#include "BLI_utildefines.h" +#include "BLI_math.h" + +#include "bmesh.h" + +#include "intern/bmesh_operators_private.h" /* own include */ + +#define ELE_NEW 1 +#define ELE_INPUT 2 + +void bmo_bisect_plane_exec(BMesh *bm, BMOperator *op) +{ + const float dist = BMO_slot_float_get(op->slots_in, "dist"); + const bool clear_outer = BMO_slot_bool_get(op->slots_in, "clear_outer"); + const bool clear_inner = BMO_slot_bool_get(op->slots_in, "clear_inner"); + + float plane_co[3]; + float plane_no[3]; + float plane[4]; + + BMO_slot_vec_get(op->slots_in, "plane_co", plane_co); + BMO_slot_vec_get(op->slots_in, "plane_no", plane_no); + + if (is_zero_v3(plane_no)) { + BMO_error_raise(bm, op, BMERR_MESH_ERROR, "Zero normal given"); + return; + } + + plane_from_point_normal_v3(plane, plane_co, plane_no); + + /* tag geometry to bisect */ + BM_mesh_elem_hflag_disable_all(bm, BM_EDGE | BM_FACE, BM_ELEM_TAG, false); + BMO_slot_buffer_hflag_enable(bm, op->slots_in, "geom", BM_EDGE | BM_FACE, BM_ELEM_TAG, false); + + BMO_slot_buffer_flag_enable(bm, op->slots_in, "geom", BM_ALL_NOLOOP, ELE_INPUT); + + + BM_mesh_bisect_plane(bm, plane, true, + ELE_NEW, dist); + + + if (clear_outer || clear_inner) { + BMOIter siter; + BMVert *v; + float plane_alt[4]; + + copy_v3_v3(plane_alt, plane); + + if (clear_outer) { + plane_alt[3] = plane[3] - dist; + + BMO_ITER (v, &siter, op->slots_in, "geom", BM_VERT) { + if (plane_point_side_v3(plane_alt, v->co) > 0.0f) { + BM_vert_kill(bm, v); + } + } + } + + if (clear_inner) { + plane_alt[3] = plane[3] + dist; + + BMO_ITER (v, &siter, op->slots_in, "geom", BM_VERT) { + if (plane_point_side_v3(plane_alt, v->co) < 0.0f) { + BM_vert_kill(bm, v); + } + } + } + } + + BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out", BM_ALL_NOLOOP, ELE_NEW | ELE_INPUT); + BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom_cut.out", BM_VERT | BM_EDGE, ELE_NEW); +} |