Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-18 19:14:55 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-18 19:14:55 +0400
commitc5e14f62a673507a6298bf9f676f6de11d193f07 (patch)
tree566e8f7fe07f0713f1667b236998cbb9dd94f492
parenta71f84606a383801d4e6ceb8106bcc33857a5322 (diff)
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.
-rw-r--r--source/blender/bmesh/CMakeLists.txt1
-rw-r--r--source/blender/bmesh/intern/bmesh_opdefines.c28
-rw-r--r--source/blender/bmesh/intern/bmesh_operators_private.h1
-rw-r--r--source/blender/bmesh/operators/bmo_create.c6
-rw-r--r--source/blender/bmesh/operators/bmo_edgenet.c27
-rw-r--r--source/blender/bmesh/operators/bmo_fill_attribute.c176
-rw-r--r--source/blender/bmesh/operators/bmo_fill_holes.c119
-rw-r--r--source/blender/bmesh/tools/bmesh_edgenet.c7
-rw-r--r--source/blender/bmesh/tools/bmesh_edgenet.h3
9 files changed, 265 insertions, 103 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt
index 533593d6f77..98205852646 100644
--- a/source/blender/bmesh/CMakeLists.txt
+++ b/source/blender/bmesh/CMakeLists.txt
@@ -50,6 +50,7 @@ set(SRC
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
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index 371d55f385e..615654c1c3a 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -577,6 +577,28 @@ static BMOpDefine bmo_holes_fill_def = {
/*
+ * 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 @@ static BMOpDefine bmo_edgenet_fill_def = {
"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 @@ const BMOpDefine *bmo_opdefines[] = {
&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,
diff --git a/source/blender/bmesh/intern/bmesh_operators_private.h b/source/blender/bmesh/intern/bmesh_operators_private.h
index 33c10411c0f..35fd9b3d530 100644
--- a/source/blender/bmesh/intern/bmesh_operators_private.h
+++ b/source/blender/bmesh/intern/bmesh_operators_private.h
@@ -59,6 +59,7 @@ void bmo_dissolve_limit_exec(BMesh *bm, BMOperator *op);
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);
diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c
index cce5c992d2a..3b403ca800e 100644
--- a/source/blender/bmesh/operators/bmo_create.c
+++ b/source/blender/bmesh/operators/bmo_create.c
@@ -153,8 +153,8 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op)
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 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op)
/* 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;
}
diff --git a/source/blender/bmesh/operators/bmo_edgenet.c b/source/blender/bmesh/operators/bmo_edgenet.c
index 6c88161ca35..0d9521a6ad4 100644
--- a/source/blender/bmesh/operators/bmo_edgenet.c
+++ b/source/blender/bmesh/operators/bmo_edgenet.c
@@ -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 @@ void bmo_edgenet_fill_exec(BMesh *bm, BMOperator *op)
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)
diff --git a/source/blender/bmesh/operators/bmo_fill_attribute.c b/source/blender/bmesh/operators/bmo_fill_attribute.c
new file mode 100644
index 00000000000..f53b4536e44
--- /dev/null
+++ b/source/blender/bmesh/operators/bmo_fill_attribute.c
@@ -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);
+ }
+ } while ((l_radial_iter = l_radial_iter->radial_next) != l_iter);
+ }
+ } while ((l_iter = l_iter->next) != l);
+
+ /* do last because of face flipping */
+ bm_face_copy_shared_all(bm, l,
+ use_normals, use_data);
+ face_tot += 1;
+ }
+ }
+
+ BLI_LINKSTACK_SWAP(loop_queue_prev, loop_queue_next);
+ }
+
+ BLI_LINKSTACK_FREE(loop_queue_prev);
+ BLI_LINKSTACK_FREE(loop_queue_next);
+
+ return face_tot;
+}
+
+void bmo_face_attribute_fill_exec(BMesh *bm, BMOperator *op)
+{
+ const bool use_normals = BMO_slot_bool_get(op->slots_in, "use_normals");
+ const bool use_data = BMO_slot_bool_get(op->slots_in, "use_data");
+
+ int face_tot;
+
+ BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false);
+ BMO_slot_buffer_hflag_enable(bm, op->slots_in, "faces", BM_FACE, BM_ELEM_TAG, false); /* do inline */
+
+ /* now we can copy adjacent data */
+ face_tot = bmesh_face_attribute_fill(bm, use_normals, use_data);
+
+ if (face_tot != BMO_slot_buffer_count(op->slots_in, "faces")) {
+ /* any remaining tags will be skipped */
+ BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces_fail.out", BM_FACE, BM_ELEM_TAG);
+ }
+}
diff --git a/source/blender/bmesh/operators/bmo_fill_holes.c b/source/blender/bmesh/operators/bmo_fill_holes.c
index 844205f5b91..475eb5ba32d 100644
--- a/source/blender/bmesh/operators/bmo_fill_holes.c
+++ b/source/blender/bmesh/operators/bmo_fill_holes.c
@@ -28,110 +28,57 @@
#include "MEM_guardedalloc.h"
-#include "BLI_listbase.h"
-#include "BLI_alloca.h"
-#include "BLI_math.h"
+#include "BLI_utildefines.h"
#include "bmesh.h"
#include "intern/bmesh_operators_private.h" /* own include */
-#define EDGE_MARK 2
-#define ELE_OUT 4
-
-/**
- * Clone of BM_face_find_longest_loop that ensures the loop has an adjacent face
- */
-static BMLoop *bm_face_find_longest_loop_manifold(BMFace *f)
-{
- BMLoop *longest_loop = NULL;
- float longest_len = 0.0f;
- BMLoop *l_iter, *l_first;
-
- l_iter = l_first = BM_FACE_FIRST_LOOP(f);
-
- do {
- if (BM_edge_is_wire(l_iter->e) == false) {
- const float len = len_squared_v3v3(l_iter->v->co, l_iter->next->v->co);
- if (len >= longest_len) {
- longest_loop = l_iter;
- longest_len = len;
- }
- }
- } while ((l_iter = l_iter->next) != l_first);
-
- return longest_loop;
-}
-
-static BMFace *bm_face_from_eloop(BMesh *bm, struct BMEdgeLoopStore *el_store)
-{
- LinkData *node = BM_edgeloop_verts_get(el_store)->first;
- const int len = BM_edgeloop_length_get(el_store);
- BMVert **f_verts = BLI_array_alloca(f_verts, len);
- BMFace *f;
- BMLoop *l;
- unsigned int i = 0;
-
- do {
- f_verts[i++] = node->data;
- } while ((node = node->next));
-
- f = BM_face_create_ngon_verts(bm, f_verts, len, 0, true, false);
- BM_face_copy_shared(bm, f, NULL, NULL);
-
- l = bm_face_find_longest_loop_manifold(f);
- if (l) {
- BMFace *f_other = l->radial_next->f;
- BLI_assert(l->radial_next != l);
- BM_elem_attrs_copy(bm, bm, f_other, f);
- }
-
- return f;
-}
-
-static bool bm_edge_test_cb(BMEdge *e, void *bm_v)
-{
- return BMO_elem_flag_test((BMesh *)bm_v, e, EDGE_MARK);
-}
-
void bmo_holes_fill_exec(BMesh *bm, BMOperator *op)
{
- ListBase eloops = {NULL, NULL};
- LinkData *el_store;
+ BMOperator op_attr;
+ const unsigned int sides = BMO_slot_int_get(op->slots_in, "sides");
- BMEdge *e;
- int count;
- BMOIter siter;
+ BM_mesh_elem_hflag_disable_all(bm, BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
+ BMO_slot_buffer_hflag_enable(bm, op->slots_in, "edges", BM_EDGE, BM_ELEM_TAG, false);
- const int sides = BMO_slot_int_get(op->slots_in, "sides");
+ BM_mesh_edgenet(bm, true, true); // TODO, sides
- /* clear tags */
- BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false);
+ /* bad - remove faces after as a workaround */
+ if (sides != 0) {
+ BMOIter siter;
+ BMFace *f;
- /* tag edges that may be apart of loops */
- BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) {
- BMO_elem_flag_set(bm, e, EDGE_MARK, BM_edge_is_boundary(e));
+ 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) {
+ if (f->len > sides) {
+ BM_face_kill(bm, f);
+ }
+ }
}
- count = BM_mesh_edgeloops_find(bm, &eloops, bm_edge_test_cb, (void *)bm);
+ BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
- for (el_store = eloops.first; el_store; el_store = el_store->next) {
- if (BM_edgeloop_is_closed((struct BMEdgeLoopStore *)el_store)) {
- const int len = BM_edgeloop_length_get((struct BMEdgeLoopStore *)el_store);
- if ((sides == 0) || (len <= sides)) {
- BMFace *f;
+ /* --- 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 use_data=%b",
+ op, "faces.out", true, true);
- f = bm_face_from_eloop(bm, (struct BMEdgeLoopStore *)el_store);
- BMO_elem_flag_enable(bm, f, ELE_OUT);
- }
- }
- }
+ BMO_op_exec(bm, &op_attr);
- (void)count;
+ /* check if some faces couldn't be touched */
+ if (BMO_slot_buffer_count(op_attr.slots_out, "faces_fail.out")) {
+ BMOIter siter;
+ BMFace *f;
- BM_mesh_edgeloops_free(&eloops);
+ BMO_ITER (f, &siter, op_attr.slots_out, "faces_fail.out", BM_FACE) {
+ BM_face_normal_update(f); /* normals are zero'd */
+ }
- BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, ELE_OUT);
+ BMO_op_callf(bm, op->flag, "recalc_face_normals faces=%S", &op_attr, "faces_fail.out");
+ }
+ BMO_op_finish(bm, &op_attr);
}
diff --git a/source/blender/bmesh/tools/bmesh_edgenet.c b/source/blender/bmesh/tools/bmesh_edgenet.c
index 18efb9acd78..3aa86b2c97b 100644
--- a/source/blender/bmesh/tools/bmesh_edgenet.c
+++ b/source/blender/bmesh/tools/bmesh_edgenet.c
@@ -443,7 +443,8 @@ static LinkNode *bm_edgenet_path_calc_best(
* \param use_edge_tag Only fill tagged edges.
* \param face_oflag if nonzero, apply all new faces with this bmo flag.
*/
-void BM_mesh_edgenet(BMesh *bm, const bool use_edge_tag, const short face_oflag)
+void BM_mesh_edgenet(BMesh *bm,
+ const bool use_edge_tag, const bool use_new_face_tag)
{
VertNetInfo *vnet_info = MEM_callocN(sizeof(*vnet_info) * (size_t)bm->totvert, __func__);
BLI_mempool *edge_queue_pool = BLI_mempool_create(sizeof(LinkNode), 1, 512, 0);
@@ -491,8 +492,8 @@ void BM_mesh_edgenet(BMesh *bm, const bool use_edge_tag, const short face_oflag)
}
} while ((l_iter = l_iter->next) != l_first);
- if (face_oflag) {
- BMO_elem_flag_enable(bm, f, face_oflag);
+ if (use_new_face_tag) {
+ BM_elem_flag_enable(f, BM_ELEM_TAG);
}
/* the face index only needs to be unique, not kept valid */
diff --git a/source/blender/bmesh/tools/bmesh_edgenet.h b/source/blender/bmesh/tools/bmesh_edgenet.h
index ffb3fa133da..327a7f5aa23 100644
--- a/source/blender/bmesh/tools/bmesh_edgenet.h
+++ b/source/blender/bmesh/tools/bmesh_edgenet.h
@@ -27,6 +27,7 @@
* \ingroup bmesh
*/
-void BM_mesh_edgenet(BMesh *bm, const bool use_edge_tag, const short face_oflag);
+void BM_mesh_edgenet(BMesh *bm,
+ const bool use_edge_tag, const bool use_new_face_tag);
#endif /* __BMESH_EDGENET_H__ */