[Bf-blender-cvs] [2a9069a8870] newboolean: More progress but still not functional at all.

Howard Trickey noreply at git.blender.org
Wed Sep 4 04:38:22 CEST 2019


Commit: 2a9069a8870a7367e2c2bc7e01eae1d186eae2c1
Author: Howard Trickey
Date:   Tue Sep 3 22:36:37 2019 -0400
Branches: newboolean
https://developer.blender.org/rB2a9069a8870a7367e2c2bc7e01eae1d186eae2c1

More progress but still not functional at all.

Fixed a bug where it wouldn't compile with NDEBUG defined.

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

M	source/blender/blenlib/BLI_math_base.h
M	source/blender/bmesh/tools/bmesh_boolean.c

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

diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 4ac966be83d..04cf9987d25 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -262,6 +262,7 @@ double double_round(double x, int ndigits);
 #else
 #  define BLI_ASSERT_UNIT_V2(v) (void)(v)
 #  define BLI_ASSERT_UNIT_V3(v) (void)(v)
+#  define BLI_ASSERT_UNIT_V3_DB(v) (void)(v)
 #  define BLI_ASSERT_UNIT_QUAT(v) (void)(v)
 #  define BLI_ASSERT_ZERO_M3(m) (void)(m)
 #  define BLI_ASSERT_ZERO_M4(m) (void)(m)
diff --git a/source/blender/bmesh/tools/bmesh_boolean.c b/source/blender/bmesh/tools/bmesh_boolean.c
index bf6fc37cbe3..a8fead3ff52 100644
--- a/source/blender/bmesh/tools/bmesh_boolean.c
+++ b/source/blender/bmesh/tools/bmesh_boolean.c
@@ -117,7 +117,7 @@ typedef struct IMesh {
 typedef struct MeshAdd {
   LinkNodePair verts; /* Links are NewVerts. */
   LinkNodePair edges; /* Links are NewEdges. */
-  LinkNodePair faces; /* Linkes are NewFaces. */
+  LinkNodePair faces; /* Links are NewFaces. */
   int vindex_start;   /* Add this to position in verts to get index of new vert. */
   int eindex_start;   /* Add this to position in edges to get index of new edge. */
   int findex_start;   /* Add this to position in faces to get index of new face. */
@@ -175,6 +175,15 @@ typedef struct MeshPartSet {
   const char *label; /* for debugging */
 } MeshPartSet;
 
+/* An IMeshPlus is an IMesh plus a MeshAdd.
+ * If the element indices are in range for the IMesh, then functions
+ * access those, else they access the MeshAdd.
+ */
+ typedef struct IMeshPlus {
+   IMesh *im;
+   MeshAdd *meshadd;
+ } IMeshPlus;
+
 /* Result of intersecting two MeshParts.
  * This only need identify the thngs that probably intersect,
  * as the actual intersections will be done later, when
@@ -199,9 +208,16 @@ typedef struct BoolState {
   void *test_fn_user_data;
 } BoolState;
 
-/* test_fn results used to distinguish parts of mesh */
+/* test_fn results used to distinguish parts of mesh. */
 enum { TEST_NONE = -1, TEST_B = 0, TEST_A = 1, TEST_ALL = 2 };
 
+/* Decoration to shut up gnu 'unused function' warning. */
+#ifdef __GNUC__
+# define ATTU __attribute__((unused))
+#else
+# define ATTU
+#endif
+
 #define BOOLDEBUG
 #ifdef BOOLDEBUG
 /* For Debugging. */
@@ -211,11 +227,11 @@ enum { TEST_NONE = -1, TEST_B = 0, TEST_A = 1, TEST_ALL = 2 };
 #  define F4(v) (v)[0], (v)[1], (v)[2], (v)[3]
 #  define BMI(e) BM_elem_index_get(e)
 
-static void dump_part(const MeshPart *part, const char *label);
-static void dump_partset(const MeshPartSet *pset);
-static void dump_partpartintersect(const PartPartIntersect *ppi, const char *label);
-static void dump_meshadd(const MeshAdd *ma, const char *label);
-static void dump_intintmap(const IntIntMap *map, const char *label, const char *prefix);
+ATTU static void dump_part(const MeshPart *part, const char *label);
+ATTU static void dump_partset(const MeshPartSet *pset);
+ATTU static void dump_partpartintersect(const PartPartIntersect *ppi, const char *label);
+ATTU static void dump_meshadd(const MeshAdd *ma, const char *label);
+ATTU static void dump_intintmap(const IntIntMap *map, const char *label, const char *prefix);
 #endif
 
 /* Forward declarations of some static functions. */
@@ -273,7 +289,7 @@ static int intset_get_index_for_value(const IndexedIntSet *intset, int value)
 
 /* Indices in IndexedCoordSets start at index_offset. */
 
-static void init_coordset(IndexedCoordSet *coordset, int index_offset)
+ATTU static void init_coordset(IndexedCoordSet *coordset, int index_offset)
 {
   coordset->listhead.list = NULL;
   coordset->listhead.last_node = NULL;
@@ -281,7 +297,7 @@ static void init_coordset(IndexedCoordSet *coordset, int index_offset)
   coordset->size = 0;
 }
 
-static int add_to_coordset(BoolState *bs,
+ATTU static int add_to_coordset(BoolState *bs,
                            IndexedCoordSet *coordset,
                            const float p[3],
                            bool do_dup_check)
@@ -315,7 +331,7 @@ static int add_to_coordset(BoolState *bs,
   return index;
 }
 
-static float *coordset_coord(const IndexedCoordSet *coordset, int index)
+ATTU static float *coordset_coord(const IndexedCoordSet *coordset, int index)
 {
   int i;
 
@@ -442,7 +458,7 @@ static inline int intintmap_iter_value(IntIntMapIterator *iter)
 /** Miscellaneous utility functions. */
 #pragma mark Miscellaneous utility functions
 
-static int min_int_in_array(int *array, int len)
+ATTU static int min_int_in_array(int *array, int len)
 {
   int min = INT_MAX;
   int i;
@@ -467,7 +483,7 @@ static LinkNode *linklist_shallow_copy_arena(LinkNode *list, struct MemArena *ar
 }
 
 /* Get to last node of a liskned list. Also return list size in r_count. */
-static LinkNode *linklist_last(LinkNode *ln, int *r_count)
+ATTU static LinkNode *linklist_last(LinkNode *ln, int *r_count)
 {
   int i;
 
@@ -485,6 +501,9 @@ static LinkNode *linklist_last(LinkNode *ln, int *r_count)
 
 /** Functions to move to Blenlib's math_geom when stable. */
 
+#if 0
+/* This general tri-tri intersect routine may be useful as an optimization later, but is unused for now. */
+
 /*
  * Return -1, 0, or 1 as (px,py) is right of, collinear (within epsilon) with, or left of line
  * (l1,l2)
@@ -723,6 +742,7 @@ static bool isect_tri_tri_epsilon_v3_db_ex(const double t_a0[3],
     *r_npts = 0;
   return false;
 }
+#endif
 
 /* Does the line intersect the segment (within epsilon)?
  * If line and seg are parallel and coincident, return 2.
@@ -925,6 +945,34 @@ static int imesh_find_co_db(const IMesh *im, const double co[3], double eps)
   }
 }
 
+/* Find an edge in im between given two verts (either order ok), if it exists.
+ * Else return -1.
+ * TODO: speed this up.
+ */
+static int imesh_find_edge(const IMesh *im, int v1, int v2)
+{
+  BMesh *bm = im->bm;
+  int e;
+
+  if (bm) {
+    if (v1 >= bm->totvert || v2 >= bm->totvert) {
+      return -1;
+    }
+    for (e = 0; e < bm->totedge; e++) {
+      BMEdge *bme = BM_edge_at_index(bm, e);
+      int ev1 = BM_elem_index_get(bme->v1);
+      int ev2 = BM_elem_index_get(bme->v2);
+      if ((ev1 == v1 && ev2 == v2) || (ev1== v2 && ev2 == v1)) {
+        return e;
+      }
+    }
+    return -1;
+  }
+  else {
+    return -1; /* TODO */
+  }
+}
+
 static void imesh_get_edge_cos_db(const IMesh *im, int e, double *r_coords1, double *r_coords2)
 {
   if (im->bm) {
@@ -1101,6 +1149,7 @@ static void apply_meshadd_to_bmesh(BMesh *bm,
                                    const IntIntMap *vert_merge_map)
 {
   /* TODO: implement apply_meshadd_to_bmesh */
+  UNUSED_VARS(bm, meshadd, vert_merge_map);
 }
 
 static void apply_meshadd_to_imesh(IMesh *im,
@@ -1178,7 +1227,7 @@ static int meshadd_add_edge(BoolState *bs, MeshAdd *meshadd, int v1, int v2, int
   return meshadd->eindex_start + BLI_linklist_count(meshadd->edges.list) - 1;
 }
 
-static int meshadd_add_face(
+ATTU static int meshadd_add_face(
     BoolState *bs, MeshAdd *meshadd, const IntPair *vert_edge, int len, int example)
 {
   NewFace *newf;
@@ -1192,6 +1241,75 @@ static int meshadd_add_face(
   return meshadd->findex_start + BLI_linklist_count(meshadd->faces.list) - 1;
 }
 
+static int meshadd_facelen(const MeshAdd *meshadd, int f)
+{
+  LinkNode *ln;
+  NewFace *nf;
+
+  ln = BLI_linklist_find(meshadd->faces.list, f - meshadd->findex_start);
+  if (ln) {
+    nf = (NewFace *)ln->link;
+    return nf->len;
+  }
+  return 0;
+}
+
+static int meshadd_face_vert(const MeshAdd *meshadd, int f, int index)
+{
+  LinkNode *ln;
+  NewFace *nf;
+
+  ln = BLI_linklist_find(meshadd->faces.list, f - meshadd->findex_start);
+  if (ln) {
+    nf = (NewFace *)ln->link;
+    if (index >= 0 && index < nf->len) {
+      return nf->vert_edge_pairs[index].first;
+    }
+  }
+  return -1;
+}
+
+static void meshadd_get_vert_co(const MeshAdd *meshadd, int v, float *r_coords)
+{
+  LinkNode *ln;
+  NewVert *nv;
+
+  ln = BLI_linklist_find(meshadd->verts.list, v - meshadd->vindex_start);
+  if (ln) {
+    nv = (NewVert *)ln->link;
+    copy_v3_v3(r_coords, nv->co);
+  }
+  else {
+    zero_v3(r_coords);
+  }
+}
+
+static void meshadd_get_vert_co_db(const MeshAdd *meshadd, int v, double *r_coords)
+{
+  float fco[3];
+
+  meshadd_get_vert_co(meshadd, v, fco);
+  copy_v3db_v3fl(r_coords, fco);
+}
+
+static void meshadd_get_edge_verts(const MeshAdd *meshadd, int e, int *r_v1, int *r_v2)
+{
+  LinkNode *ln;
+  NewEdge *ne;
+
+  ln = BLI_linklist_find(meshadd->edges.list, e - meshadd->eindex_start);
+  if (ln) {
+    ne = (NewEdge *)ln->link;
+    *r_v1 = ne->v1;
+    *r_v2 = ne->v2;
+  }
+  else {
+    *r_v1 = -1;
+    *r_v2 = -1;
+  }
+}
+
+
 /** MeshPartSet functions. */
 #pragma mark MeshPartSet functions
 
@@ -1256,7 +1374,7 @@ static void init_meshpart(BoolState *UNUSED(bs), MeshPart *part)
   memset(part, 0, sizeof(*part));
 }
 
-static MeshPart *copy_part(BoolState *bs, const MeshPart *part)
+ATTU static MeshPart *copy_part(BoolState *bs, const MeshPart *part)
 {
   MeshPart *copy;
   MemArena *arena = bs->mem_arena;
@@ -1411,12 +1529,12 @@ static MeshPart *find_part_for_plane(BoolState *bs, MeshPartSet *partset, const
   return new_part;
 }
 
-static void add_vert_to_part(BoolState *bs, MeshPart *part, int v)
+ATTU static void add_vert_to_part(BoolState *bs, MeshPart *part, int v)
 {
   BLI_linklist_prepend_arena(&part->verts, POINTER_FROM_INT(v), bs->mem_arena);
 }
 
-static void add_edge_to_part(BoolState *bs, MeshPart *part, int e)
+ATTU static void add_edge_to_part(BoolState *bs, MeshPart *part, int e)
 {
   BLI_linklist_prepend_arena(&part->verts, POINTER_FROM_INT(e), bs->mem_arena);
 }
@@ -1493,6 +1611,60 @@ static IntersectOutput *isect_out_from_cdt(BoolState *bs,
 }
 #endif
 
+/** IMeshPlus functions. */
+#pragma mark IMeshPlus functions
+
+static void init_imeshplus(IMeshPlus *imp, IMesh *im, MeshAdd *meshadd)
+{
+  imp->im = im;
+  imp->meshadd = meshadd;
+}
+
+static int imeshplus_facelen(const IMeshPlus *imp, int f)
+{
+  IMesh *im = imp->im;
+  return (f < imesh_totface(im)) ? imesh_facelen(im, f) : meshadd_facelen(imp->meshadd, f);
+}
+
+static int imeshplus_face_vert(const IMeshPlus *imp, int f, int index)
+{
+  IMesh *im = imp->im;
+  retu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list