[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59386] trunk/blender/source/blender/bmesh : 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.
Campbell Barton
ideasman42 at gmail.com
Thu Aug 22 19:56:08 CEST 2013
Revision: 59386
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59386
Author: campbellbarton
Date: 2013-08-22 17:56:08 +0000 (Thu, 22 Aug 2013)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/bmesh/CMakeLists.txt
trunk/blender/source/blender/bmesh/bmesh.h
trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h
Added Paths:
-----------
trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c
trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c
trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.h
Modified: trunk/blender/source/blender/bmesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/bmesh/CMakeLists.txt 2013-08-22 17:32:41 UTC (rev 59385)
+++ trunk/blender/source/blender/bmesh/CMakeLists.txt 2013-08-22 17:56:08 UTC (rev 59386)
@@ -41,6 +41,7 @@
set(SRC
operators/bmo_beautify.c
operators/bmo_bevel.c
+ operators/bmo_bisect_plane.c
operators/bmo_bridge.c
operators/bmo_connect.c
operators/bmo_connect_nonplanar.c
@@ -120,6 +121,8 @@
tools/bmesh_bevel.c
tools/bmesh_bevel.h
+ tools/bmesh_bisect_plane.c
+ tools/bmesh_bisect_plane.h
tools/bmesh_decimate_collapse.c
tools/bmesh_decimate_dissolve.c
tools/bmesh_decimate_unsubdivide.c
Modified: trunk/blender/source/blender/bmesh/bmesh.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh.h 2013-08-22 17:32:41 UTC (rev 59385)
+++ trunk/blender/source/blender/bmesh/bmesh.h 2013-08-22 17:56:08 UTC (rev 59386)
@@ -270,6 +270,7 @@
#include "intern/bmesh_inline.h"
#include "tools/bmesh_bevel.h"
+#include "tools/bmesh_bisect_plane.h"
#include "tools/bmesh_decimate.h"
#include "tools/bmesh_edgenet.h"
#include "tools/bmesh_edgesplit.h"
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2013-08-22 17:32:41 UTC (rev 59385)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2013-08-22 17:56:08 UTC (rev 59386)
@@ -1118,6 +1118,29 @@
};
/*
+ * Bisect Plane.
+ *
+ * Bisects the mesh by a plane (cut the mesh in half).
+ */
+static BMOpDefine bmo_bisect_plane_def = {
+ "bisect_plane",
+ /* slots_in */
+ {{"geom", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT | BM_EDGE | BM_FACE}},
+ {"dist", BMO_OP_SLOT_FLT}, /* minimum distance when testing if a vert is exactly on the plane */
+ {"plane_co", BMO_OP_SLOT_VEC}, /* point on the plane */
+ {"plane_no", BMO_OP_SLOT_VEC}, /* direction of the plane */
+ {"clear_outer", BMO_OP_SLOT_BOOL}, /* when enabled. remove all geometry on the positive side of the plane */
+ {"clear_inner", BMO_OP_SLOT_BOOL}, /* when enabled. remove all geometry on the negative side of the plane */
+ {{'\0'}},
+ },
+ {{"geom_cut.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT | BM_EDGE}}, /* output new geometry from the cut */
+ {"geom.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT | BM_EDGE | BM_FACE}}, /* input and output geometry (result of cut) */
+ {{'\0'}}},
+ bmo_bisect_plane_exec,
+ BMO_OPTYPE_FLAG_UNTAN_MULTIRES | BMO_OPTYPE_FLAG_NORMALS_CALC | BMO_OPTYPE_FLAG_SELECT_FLUSH,
+};
+
+/*
* Delete Geometry.
*
* Utility operator to delete geometry.
@@ -1835,6 +1858,7 @@
&bmo_split_edges_def,
&bmo_subdivide_edges_def,
&bmo_subdivide_edgering_def,
+ &bmo_bisect_plane_def,
&bmo_symmetrize_def,
&bmo_transform_def,
&bmo_translate_def,
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h 2013-08-22 17:32:41 UTC (rev 59385)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h 2013-08-22 17:56:08 UTC (rev 59386)
@@ -35,6 +35,7 @@
void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op);
void bmo_bevel_exec(BMesh *bm, BMOperator *op);
void bmo_bisect_edges_exec(BMesh *bm, BMOperator *op);
+void bmo_bisect_plane_exec(BMesh *bm, BMOperator *op);
void bmo_bmesh_to_mesh_exec(BMesh *bm, BMOperator *op);
void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op);
void bmo_collapse_exec(BMesh *bm, BMOperator *op);
Added: trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c (rev 0)
+++ trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c 2013-08-22 17:56:08 UTC (rev 59386)
@@ -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);
+}
Property changes on: trunk/blender/source/blender/bmesh/operators/bmo_bisect_plane.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c
===================================================================
--- trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c (rev 0)
+++ trunk/blender/source/blender/bmesh/tools/bmesh_bisect_plane.c 2013-08-22 17:56:08 UTC (rev 59386)
@@ -0,0 +1,411 @@
+/*
+ * ***** 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): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/tools/bmesh_bisect_plane.c
+ * \ingroup bmesh
+ *
+ * Cut the geometry in half using a plane.
+ */
+
+#include <limits.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_alloca.h"
+#include "BLI_mempool.h"
+#include "BLI_linklist.h"
+#include "BLI_linklist_stack.h"
+#include "BLI_math.h"
+
+#include "bmesh.h"
+
+#ifdef __GNUC__
+# pragma GCC diagnostic error "-Wsign-conversion"
+# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 /* gcc4.6+ only */
+# pragma GCC diagnostic error "-Wsign-compare"
+# pragma GCC diagnostic error "-Wconversion"
+# endif
+#endif
+
+
+/* -------------------------------------------------------------------- */
+/* Math utils */
+
+static int plane_point_test_v3(const float plane[4], const float co[3], const float eps, float *r_depth)
+{
+ const float f = plane_point_side_v3(co, plane);
+ *r_depth = f;
+
+ if (f <= -eps) return -1;
+ else if (f >= eps) return 1;
+ else return 0;
+}
+
+
+/* -------------------------------------------------------------------- */
+/* Wrappers to hide internal data-structure abuse,
+ * later we may want to move this into some hash lookup
+ * to a separate struct, but for now we can store in BMesh data */
+
+/**
+ * Direction -1/0/1
+ */
+#define BM_VERT_DIR(v) ((v)->head.index)
+/**
+ * Distance from the plane.
+ */
+#define BM_VERT_DIST(v) ((v)->no[0])
+
+/**
+ * Temp value for sorting.
+ */
+#define BM_VERT_SORTVAL(v) ((v)->no[1])
+
+/**
+ * Temp value for sorting.
+ */
+#define BM_VERT_LOOPINDEX(v) (*((unsigned int *)(&(v)->no[2])))
+
+/**
+ * Hide flag access
+ * (for more readable code since same flag is used differently for vert/edgeface)...
+ */
+
+/* enable when vertex is in the center and its faces have been added to the stack */
+BLI_INLINE void vert_is_center_enable(BMVert *v) { BM_elem_flag_enable(v, BM_ELEM_TAG); }
+BLI_INLINE void vert_is_center_disable(BMVert *v) { BM_elem_flag_disable(v, BM_ELEM_TAG); }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list