Commit: b7174c9320c5e3446d8237059841d982279e32e9
Author: Campbell Barton
Date:   Sat Nov 1 23:31:01 2014 +0100
Branches: master
https://developer.blender.org/rBb7174c9320c5e3446d8237059841d982279e32e9

Fix connect-vertices failing for concave ngons

Also add:
- generic callback for bmesh elements.
- ability to pass an existing array to a bmesh operator.

===================================================================

M       source/blender/bmesh/CMakeLists.txt
M       source/blender/bmesh/bmesh.h
A       source/blender/bmesh/intern/bmesh_callback_generic.c
A       source/blender/bmesh/intern/bmesh_callback_generic.h
M       source/blender/bmesh/intern/bmesh_operator_api.h
M       source/blender/bmesh/intern/bmesh_operators.c
M       source/blender/bmesh/intern/bmesh_queries.c
M       source/blender/bmesh/intern/bmesh_queries.h
M       source/blender/bmesh/operators/bmo_connect_pair.c
M       source/blender/editors/mesh/editmesh_tools.c

===================================================================

diff --git a/source/blender/bmesh/CMakeLists.txt 
b/source/blender/bmesh/CMakeLists.txt
index 50d3ac3..2373786 100644
--- a/source/blender/bmesh/CMakeLists.txt
+++ b/source/blender/bmesh/CMakeLists.txt
@@ -74,6 +74,8 @@ set(SRC
        operators/bmo_utils.c
        operators/bmo_wireframe.c
 
+       intern/bmesh_callback_generic.c
+       intern/bmesh_callback_generic.h
        intern/bmesh_construct.c
        intern/bmesh_construct.h
        intern/bmesh_core.c
diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h
index 4efc6aa..87b1818 100644
--- a/source/blender/bmesh/bmesh.h
+++ b/source/blender/bmesh/bmesh.h
@@ -243,6 +243,7 @@ extern "C" {
 #include "intern/bmesh_error.h"
 
 #include "intern/bmesh_core.h"
+#include "intern/bmesh_callback_generic.h"
 #include "intern/bmesh_construct.h"
 #include "intern/bmesh_delete.h"
 #include "intern/bmesh_edgeloop.h"
diff --git a/source/blender/bmesh/intern/bmesh_callback_generic.c 
b/source/blender/bmesh/intern/bmesh_callback_generic.c
new file mode 100644
index 0000000..91fec39
--- /dev/null
+++ b/source/blender/bmesh/intern/bmesh_callback_generic.c
@@ -0,0 +1,55 @@
+/*
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/intern/bmesh_callback_generic.c
+ *  \ingroup bmesh
+ *
+ * BM construction functions.
+ */
+
+#include "BLI_utildefines.h"
+
+#include "bmesh.h"
+
+#include "intern/bmesh_callback_generic.h"
+
+bool BM_elem_cb_check_hflag_ex(BMElem *ele, void *user_data)
+{
+       const unsigned int hflag_pair = GET_INT_FROM_POINTER(user_data);
+       const char hflag_p = (hflag_pair & 0xff);
+       const char hflag_n = (hflag_pair >> 8);
+
+       return ((BM_elem_flag_test(ele, hflag_p) != 0) &&
+               (BM_elem_flag_test(ele, hflag_n) == 0));
+}
+
+bool BM_elem_cb_check_hflag_enabled(BMElem *ele, void *user_data)
+{
+       const char hflag = GET_INT_FROM_POINTER(user_data);
+
+       return (BM_elem_flag_test(ele, hflag) != 0);
+}
+
+bool BM_elem_cb_check_hflag_disabled(BMElem *ele, void *user_data)
+{
+       const char hflag = GET_INT_FROM_POINTER(user_data);
+
+       return (BM_elem_flag_test(ele, hflag) == 0);
+}
diff --git a/source/blender/bmesh/intern/bmesh_callback_generic.h 
b/source/blender/bmesh/intern/bmesh_callback_generic.h
new file mode 100644
index 0000000..8c46128
--- /dev/null
+++ b/source/blender/bmesh/intern/bmesh_callback_generic.h
@@ -0,0 +1,44 @@
+/*
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BMESH_CALLBACK_GENERIC_H__
+#define __BMESH_CALLBACK_GENERIC_H__
+
+/** \file blender/bmesh/intern/bmesh_callback_generic.h
+ *  \ingroup bmesh
+ */
+
+bool BM_elem_cb_check_hflag_enabled(BMElem *, void *user_data);
+bool BM_elem_cb_check_hflag_disabled(BMElem *, void *user_data);
+bool BM_elem_cb_check_hflag_ex(BMElem *, void *user_data);
+
+#define BM_elem_cb_check_hflag_ex_simple(type, hflag_p, hflag_n) \
+       (bool (*)(type, void *))BM_elem_cb_check_hflag_ex, \
+       SET_UINT_IN_POINTER(((hflag_p) | (hflag_n << 8)))
+
+#define BM_elem_cb_check_hflag_enabled_simple(type, hflag_p) \
+       (bool (*)(type, void *))BM_elem_cb_check_hflag_enabled, \
+       SET_UINT_IN_POINTER((hflag_p))
+
+#define BM_elem_cb_check_hflag_disabled_simple(type, hflag_n) \
+       (bool (*)(type, void *))BM_elem_cb_check_hflag_disabled, \
+       SET_UINT_IN_POINTER(hflag_n)
+
+#endif /* __BMESH_CALLBACK_GENERIC_H__ */
diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h 
b/source/blender/bmesh/intern/bmesh_operator_api.h
index 287aafc..825bbb1 100644
--- a/source/blender/bmesh/intern/bmesh_operator_api.h
+++ b/source/blender/bmesh/intern/bmesh_operator_api.h
@@ -395,6 +395,8 @@ void BMO_slot_buffer_from_disabled_hflag(BMesh *bm, 
BMOperator *op,
                                          BMOpSlot slot_args[BMO_OP_MAX_SLOTS], 
const char *slot_name,
                                          const char htype, const char hflag);
 
+void  BMO_slot_buffer_from_array(BMOperator *op, BMOpSlot *slot, BMHeader 
**ele_buffer, int ele_buffer_len);
+
 void  BMO_slot_buffer_from_single(BMOperator *op, BMOpSlot *slot, BMHeader 
*ele);
 void *BMO_slot_buffer_get_single(BMOpSlot *slot);
 
diff --git a/source/blender/bmesh/intern/bmesh_operators.c 
b/source/blender/bmesh/intern/bmesh_operators.c
index b041c01..ba154b0 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_operators.c
@@ -900,6 +900,21 @@ void BMO_slot_buffer_from_single(BMOperator *op, BMOpSlot 
*slot, BMHeader *ele)
        *slot->data.buf = ele;
 }
 
+void BMO_slot_buffer_from_array(BMOperator *op, BMOpSlot *slot, BMHeader 
**ele_buffer, int ele_buffer_len)
+{
+       BMO_ASSERT_SLOT_IN_OP(slot, op);
+       BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
+       BLI_assert(slot->len == 0 || slot->len == ele_buffer_len);
+
+       if (slot->data.buf == NULL) {
+               slot->data.buf = BLI_memarena_alloc(op->arena, 
sizeof(*slot->data.buf) * ele_buffer_len);
+       }
+
+       slot->len = ele_buffer_len;
+       memcpy(slot->data.buf, ele_buffer, ele_buffer_len * 
sizeof(*slot->data.buf));
+}
+
+
 void *BMO_slot_buffer_get_single(BMOpSlot *slot)
 {
        BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
@@ -1636,6 +1651,7 @@ static int BMO_opcode_from_opname_check(const char 
*opname)
  *
  * **Element Buffer** (#BMO_OP_SLOT_ELEMENT_BUF)
  * - `e` - single element vert/edge/face (use with 
#BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE).
+ * - `eb` - elem buffer, take an array and a length.
  * - `av` - all verts
  * - `ae` - all edges
  * - `af` - all faces
@@ -1756,12 +1772,23 @@ bool BMO_op_vinitf(BMesh *bm, BMOperator *op, const int 
flag, const char *_fmt,
                                        state = true;
                                        break;
                                }
-                               case 'e':  /* single vert/edge/face */
+                               case 'e':
                                {
-                                       BMHeader *ele = va_arg(vlist, void *);
                                        BMOpSlot *slot = 
BMO_slot_get(op->slots_in, slot_name);
 
-                                       BMO_slot_buffer_from_single(op, slot, 
ele);
+                                       if (NEXT_CHAR(fmt) == 'b') {
+                                               BMHeader **ele_buffer = 
va_arg(vlist, void *);
+                                               int ele_buffer_len = 
va_arg(vlist, int);
+
+                                               BMO_slot_buffer_from_array(op, 
slot, ele_buffer, ele_buffer_len);
+                                               fmt++;
+                                       }
+                                       else {
+                                               /* single vert/edge/face */
+                                               BMHeader *ele = va_arg(vlist, 
void *);
+
+                                               BMO_slot_buffer_from_single(op, 
slot, ele);
+                                       }
 
                                        state = true;
                                        break;
diff --git a/source/blender/bmesh/intern/bmesh_queries.c 
b/source/blender/bmesh/intern/bmesh_queries.c
index f301108..ca40cf9 100644
--- a/source/blender/bmesh/intern/bmesh_queries.c
+++ b/source/blender/bmesh/intern/bmesh_queries.c
@@ -202,6 +202,26 @@ bool BM_vert_pair_share_face_check(
        return false;
 }
 
+bool BM_vert_pair_share_face_check_cb(
+        BMVert *v_a, BMVert *v_b,
+        bool (*test_fn)(BMFace *, void *user_data), void *user_data)
+{
+       if (v_a->e && v_b->e) {
+               BMIter iter;
+               BMFace *f;
+
+               BM_ITER_ELEM (f, &iter, v_a, BM_FACES_OF_VERT) {
+                       if (test_fn(f, user_data)) {
+                               if (BM_vert_in_face(f, v_b)) {
+                                       return true;
+                               }
+                       }
+               }
+       }
+
+       return false;
+}
+
 /**
  * Given 2 verts, find the smallest face they share and give back both loops.
  */
diff --git a/source/blender/bmesh/intern/bmesh_queries.h 
b/source/blender/bmesh/intern/bmesh_queries.h
index 0d47633..c8578a8 100644
--- a/source/blender/bmesh/intern/bmesh_queries.h
+++ b/source/blender/bmesh/intern/bmesh_queries.h
@@ -52,6 +52,9 @@ BMLoop *BM_vert_find_first_loop(BMVert *v) 
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(
 
 bool    BM_vert_pair_share_face_check(
         BMVert *v_a, BMVert *v_b) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+bool    BM_vert_pair_share_face_check_cb(
+        BMVert *v_a, BMVert *v_b,
+        bool (*test_fn)(BMFace *f, void *user_data), void *user_data) 
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2, 3);
 BMFace *BM_vert_pair_share_face_by_len(
         BMVert *v_a, BMVert *v_b,
         BMLoop **r_l_a, BMLoop **r_l_b,
diff --git a/source/blender/bmesh/operators/bmo_connect_pair.c 
b/source/blender/bmesh/operators/bmo_connect_pair.c
index cfffb60..916ea3e 100644
--- a/source/blender/bmesh/operators/bmo_connect_pair.c
+++ b/source/blender/bmesh/operators/bmo_connect_pair.c
@@ -230,23 +230,45 @@ static PathLinkState *state_dupe_add(
 static PathLinkState *state_step__face_edges(
         PathContext *pc,
         PathLinkState *state, const PathLinkState *state_orig,
-        BMLoop *l_iter, BMLoop *l_last)
+        BMLoop *l_iter, BMLoop *l_last,
+        float *r_dist_best)
 {
+       BMLoop *l_iter_best = NULL;
+       float dist_best = *r_dist_best;
+
        do {
                if (state_isect_co_pair(pc, l_iter->v->co, 
l_iter->next->v->co)) {
-                       BMElem *ele_next      = (BMElem *)l_iter->e;
-                       BMElem *ele_next_from = (BMElem *)l_iter->f;
+                       float dist_test;
+                       float co_isect[3];
 
-                       if (FACE_WALK_TEST((BMFace *)ele_next_from) &&
-                           (state_link_find(state, ele_next) == false))
-                       {

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to