[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59240] trunk/blender/source/blender/bmesh : bmesh improvements to face creation.

Campbell Barton ideasman42 at gmail.com
Sun Aug 18 17:14:55 CEST 2013


Revision: 59240
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59240
Author:   campbellbarton
Date:     2013-08-18 15:14:55 +0000 (Sun, 18 Aug 2013)
Log Message:
-----------
bmesh improvements to face creation.

* fill-holes operator now takes advantage of new edge-net fill, works in many more cases then it did before.

* face-create that uses edge-net now initializes the normals based on surrounding geometry, only running normal calculation if there are no connected faces for a reference.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/CMakeLists.txt
    trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h
    trunk/blender/source/blender/bmesh/operators/bmo_create.c
    trunk/blender/source/blender/bmesh/operators/bmo_edgenet.c
    trunk/blender/source/blender/bmesh/operators/bmo_fill_holes.c
    trunk/blender/source/blender/bmesh/tools/bmesh_edgenet.c
    trunk/blender/source/blender/bmesh/tools/bmesh_edgenet.h

Added Paths:
-----------
    trunk/blender/source/blender/bmesh/operators/bmo_fill_attribute.c

Modified: trunk/blender/source/blender/bmesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/bmesh/CMakeLists.txt	2013-08-18 15:09:51 UTC (rev 59239)
+++ trunk/blender/source/blender/bmesh/CMakeLists.txt	2013-08-18 15:14:55 UTC (rev 59240)
@@ -50,6 +50,7 @@
 	operators/bmo_dupe.c
 	operators/bmo_edgenet.c
 	operators/bmo_extrude.c
+	operators/bmo_fill_attribute.c
 	operators/bmo_fill_edgeloop.c
 	operators/bmo_fill_grid.c
 	operators/bmo_fill_holes.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2013-08-18 15:09:51 UTC (rev 59239)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2013-08-18 15:14:55 UTC (rev 59240)
@@ -577,6 +577,28 @@
 
 
 /*
+ * Face Attribute Fill.
+ *
+ * Fill in faces with data from adjacent faces.
+ */
+static BMOpDefine bmo_face_attribute_fill_def = {
+	"face_attribute_fill",
+	/* slots_in */
+	{{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}},     /* input faces */
+	 {"use_normals",        BMO_OP_SLOT_BOOL},  /* copy face winding */
+	 {"use_data",           BMO_OP_SLOT_BOOL},  /* copy face data */
+	 {{'\0'}},
+	},
+	/* slots_out */
+	/* maps new faces to the group numbers they came from */
+	{{"faces_fail.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}},     /* faces that could not be handled */
+	 {{'\0'}},
+	},
+	bmo_face_attribute_fill_exec,
+	BMO_OPTYPE_FLAG_NORMALS_CALC | BMO_OPTYPE_FLAG_SELECT_FLUSH,
+};
+
+/*
  * Edge Loop Fill.
  *
  * Create faces defined by one or more non overlapping edge loops.
@@ -609,8 +631,9 @@
 	"edgenet_fill",
 	/* slots_in */
 	{{"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, /* input edges */
-	 {"mat_nr",         BMO_OP_SLOT_INT},      /* material to use */
-	 {"use_smooth",        BMO_OP_SLOT_BOOL},  /* smooth state to use */
+	 {"mat_nr",          BMO_OP_SLOT_INT},  /* material to use */
+	 {"use_smooth",      BMO_OP_SLOT_BOOL}, /* smooth state to use */
+	 {"sides",           BMO_OP_SLOT_INT},  /* number of sides */
 	 {{'\0'}},
 	},
 	/* slots_out */
@@ -1770,6 +1793,7 @@
 	&bmo_dissolve_verts_def,
 	&bmo_duplicate_def,
 	&bmo_holes_fill_def,
+	&bmo_face_attribute_fill_def,
 	&bmo_edgeloop_fill_def,
 	&bmo_edgenet_fill_def,
 	&bmo_edgenet_prepare_def,

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2013-08-18 15:09:51 UTC (rev 59239)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2013-08-18 15:14:55 UTC (rev 59240)
@@ -59,6 +59,7 @@
 void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op);
 void bmo_duplicate_exec(BMesh *bm, BMOperator *op);
 void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op);
+void bmo_face_attribute_fill_exec(BMesh *bm, BMOperator *op);
 void bmo_holes_fill_exec(BMesh *bm, BMOperator *op);
 void bmo_edgenet_fill_exec(BMesh *bm, BMOperator *op);
 void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op);

Modified: trunk/blender/source/blender/bmesh/operators/bmo_create.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_create.c	2013-08-18 15:09:51 UTC (rev 59239)
+++ trunk/blender/source/blender/bmesh/operators/bmo_create.c	2013-08-18 15:14:55 UTC (rev 59240)
@@ -153,8 +153,8 @@
 		BMO_op_finish(bm, &op_sub);
 
 		BMO_op_initf(bm, &op_sub, op->flag,
-		             "edgenet_fill edges=%fe mat_nr=%i use_smooth=%b",
-		             ELE_NEW, mat_nr, use_smooth);
+		             "edgenet_fill edges=%fe mat_nr=%i use_smooth=%b sides=%i",
+		             ELE_NEW, mat_nr, use_smooth, 10000);
 
 		BMO_op_exec(bm, &op_sub);
 
@@ -182,7 +182,7 @@
 		/* if we dissolved anything, then return */
 		if (BMO_slot_buffer_count(op_sub.slots_out, "region.out")) {
 			BMO_slot_copy(&op_sub, slots_out, "region.out",
-			              op,   slots_out,  "faces.out");
+			              op,      slots_out, "faces.out");
 			BMO_op_finish(bm, &op_sub);
 			return;
 		}

Modified: trunk/blender/source/blender/bmesh/operators/bmo_edgenet.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_edgenet.c	2013-08-18 15:09:51 UTC (rev 59239)
+++ trunk/blender/source/blender/bmesh/operators/bmo_edgenet.c	2013-08-18 15:14:55 UTC (rev 59240)
@@ -50,19 +50,23 @@
 
 void bmo_edgenet_fill_exec(BMesh *bm, BMOperator *op)
 {
+	BMOperator op_attr;
 	BMOIter siter;
 	BMFace *f;
 	const short mat_nr        = BMO_slot_int_get(op->slots_in,  "mat_nr");
 	const bool use_smooth     = BMO_slot_bool_get(op->slots_in, "use_smooth");
+//	const int sides           = BMO_slot_int_get(op->slots_in,  "sides");
 
 	if (!bm->totvert || !bm->totedge)
 		return;
 
+	BM_mesh_elem_hflag_disable_all(bm, BM_EDGE, BM_ELEM_TAG, false);
 	BMO_slot_buffer_hflag_enable(bm, op->slots_in, "edges", BM_EDGE, BM_ELEM_TAG, false);
 
-	BM_mesh_edgenet(bm, true, FACE_NEW);
+	BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false);
+	BM_mesh_edgenet(bm, true, true); // TODO, sides
 
-	BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, FACE_NEW);
+	BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
 
 	BMO_ITER (f, &siter, op->slots_out, "faces.out", BM_FACE) {
 		f->mat_nr = mat_nr;
@@ -73,13 +77,20 @@
 		BM_face_normal_update(f);
 	}
 
-	/* recalc normals,
-	 * TODO, could do checks to make normals consistent */
-	{
-		BMO_op_callf(bm, op->flag,
-		             "recalc_face_normals faces=%S",
-		             op, "faces.out");
+	/* --- Attribute Fill --- */
+	/* may as well since we have the faces already in a buffer */
+	BMO_op_initf(bm, &op_attr, op->flag,
+	             "face_attribute_fill faces=%S use_normals=%b",
+	             op, "faces.out", true);
+
+	BMO_op_exec(bm, &op_attr);
+
+	/* check if some faces couldn't be touched */
+	if (BMO_slot_buffer_count(op_attr.slots_out, "faces_fail.out")) {
+		BMO_op_callf(bm, op->flag, "recalc_face_normals faces=%S", &op_attr, "faces_fail.out");
 	}
+	BMO_op_finish(bm, &op_attr);
+
 }
 
 static BMEdge *edge_next(BMesh *bm, BMEdge *e)

Added: trunk/blender/source/blender/bmesh/operators/bmo_fill_attribute.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_fill_attribute.c	                        (rev 0)
+++ trunk/blender/source/blender/bmesh/operators/bmo_fill_attribute.c	2013-08-18 15:14:55 UTC (rev 59240)
@@ -0,0 +1,176 @@
+
+/*
+ * ***** 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/operators/bmo_fill_attribute.c
+ *  \ingroup bmesh
+ *
+ * Fill in geometry with the attributes of their adjacent data.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_linklist_stack.h"
+
+#include "bmesh.h"
+
+#include "intern/bmesh_operators_private.h" /* own include */
+
+/**
+ * Check if all other loops are tagged.
+ */
+static bool bm_loop_is_all_radial_tag(BMLoop *l)
+{
+	BMLoop *l_iter;
+	l_iter = l->radial_next;
+	do {
+		if (BM_elem_flag_test(l_iter->f, BM_ELEM_TAG) == 0) {
+			return false;
+		}
+	} while ((l_iter = l_iter->radial_next) != l);
+
+	return true;
+}
+
+/**
+ * Callback to run on source-loops for #BM_face_copy_shared
+ */
+static bool bm_loop_is_face_untag(BMElem *ele, void *UNUSED(user_data))
+{
+	return (BM_elem_flag_test(((BMLoop *)ele)->f, BM_ELEM_TAG) == 0);
+}
+
+/**
+ * Copy all attributes from adjacent untagged faces.
+ */
+static void bm_face_copy_shared_all(BMesh *bm, BMLoop *l,
+                                    const bool use_normals, const bool use_data)
+{
+	BMLoop *l_other = l->radial_next;
+	BMFace *f = l->f, *f_other;
+	while (BM_elem_flag_test(l_other->f, BM_ELEM_TAG)) {
+		l_other = l_other->radial_next;
+	}
+	f_other = l_other->f;
+
+	if (use_data) {
+		/* copy face-attrs */
+		BM_elem_attrs_copy(bm, bm, f_other, f);
+
+		/* copy loop-attrs */
+		BM_face_copy_shared(bm, f, bm_loop_is_face_untag, NULL);
+	}
+
+	if (use_normals) {
+		/* copy winding (flipping) */
+		if (l->v == l_other->v) {
+			BM_face_normal_flip(bm, f);
+		}
+	}
+}
+
+/**
+ * Flood fill attributes.
+ */
+static unsigned int bmesh_face_attribute_fill(BMesh *bm,
+                                              const bool use_normals, const bool use_data)
+{
+	BLI_LINKSTACK_DECLARE(loop_queue_prev, BMLoop *);
+	BLI_LINKSTACK_DECLARE(loop_queue_next, BMLoop *);
+
+	BMFace *f;
+	BMIter iter;
+	BMLoop *l;
+
+	unsigned int face_tot = 0;
+
+
+	BLI_LINKSTACK_INIT(loop_queue_prev);
+	BLI_LINKSTACK_INIT(loop_queue_next);
+
+	BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+		if (BM_elem_flag_test(f, BM_ELEM_TAG)) {
+			BMLoop *l_iter, *l_first;
+			l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+			do {
+				if (bm_loop_is_all_radial_tag(l_iter) == false) {
+					BLI_LINKSTACK_PUSH(loop_queue_prev, l_iter);
+				}
+			} while ((l_iter = l_iter->next) != l_first);
+		}
+	}
+
+	while (BLI_LINKSTACK_SIZE(loop_queue_prev)) {
+		while ((l = BLI_LINKSTACK_POP(loop_queue_prev))) {
+			/* check we're still un-assigned */
+			if (BM_elem_flag_test(l->f, BM_ELEM_TAG)) {
+				BMLoop *l_iter;
+
+				BM_elem_flag_disable(l->f, BM_ELEM_TAG);
+
+				l_iter = l->next;
+				do {
+					BMLoop *l_radial_iter = l_iter->radial_next;
+					if (l_radial_iter != l_iter) {
+						do {
+							if (BM_elem_flag_test(l_radial_iter->f, BM_ELEM_TAG)) {
+								BLI_LINKSTACK_PUSH(loop_queue_next, l_radial_iter);
+							}

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list