[Bf-blender-cvs] [d7b36d55d47] newboolean: More consistent face-face intersections.

Howard Trickey noreply at git.blender.org
Thu Dec 12 20:21:52 CET 2019


Commit: d7b36d55d47db5b9958082d151800da00ca1ce2c
Author: Howard Trickey
Date:   Thu Dec 12 14:19:54 2019 -0500
Branches: newboolean
https://developer.blender.org/rBd7b36d55d47db5b9958082d151800da00ca1ce2c

More consistent face-face intersections.

Changed the part-part intersect algorithm so that the same calculation
is done whenever a particular edge intersects a plane.

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

M	release/datafiles/locale
M	release/scripts/addons
M	release/scripts/addons_contrib
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/blenlib/intern/math_geom_inline.c
M	source/blender/blenlib/intern/math_vector_inline.c
M	source/blender/bmesh/tools/bmesh_boolean.c

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

diff --git a/release/datafiles/locale b/release/datafiles/locale
index b0b6396312e..1e75f78b59a 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit b0b6396312e7ceb78826d423f8f152ddba01c039
+Subproject commit 1e75f78b59a0647ceecb102b490ade1ada0dcdba
diff --git a/release/scripts/addons b/release/scripts/addons
index 2f425cc128b..04d2e7af46e 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 2f425cc128b8b709cc1ebf2c96ad372778f4aeda
+Subproject commit 04d2e7af46e83fa2348808a47da4311d810fdb17
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index b52e7760ff6..70b649775ee 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit b52e7760ff6ccbcca73d2bbccc77f70ca2eaf98f
+Subproject commit 70b649775eeeebedb02c1c7b7aa996a7f6294177
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 8a6fe40b857..b10dbda0c63 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -81,6 +81,7 @@ void plane_to_point_vector_v3_normalized(const float plane[4],
                                          float r_plane_no[3]);
 
 MINLINE float plane_point_side_v3(const float plane[4], const float co[3]);
+MINLINE double plane_point_side_v3_db(const double plane[4], const double co[3]);
 
 /********************************* Volume **********************************/
 
@@ -115,6 +116,7 @@ float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l
 
 float dist_signed_squared_to_plane_v3(const float p[3], const float plane[4]);
 float dist_squared_to_plane_v3(const float p[3], const float plane[4]);
+double dist_squared_to_plane_normalized_v3_db(const double pt[3], const double plane[4]);
 float dist_signed_to_plane_v3(const float p[3], const float plane[4]);
 float dist_to_plane_v3(const float p[3], const float plane[4]);
 
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index c7f50c3c7be..5903105c20b 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -160,6 +160,7 @@ MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f);
 MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f);
 MINLINE void madd_v3db_v3dbdb(double r[3], const double a[3], double f);
 MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]);
+MINLINE void madd_v3_v3v3_db(double r[3], const double a[3], const double b[3]);
 MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f);
 MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f);
 MINLINE void madd_v3_v3v3db_db(double r[3], const double a[3], const double b[3], double f);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 7c8a5cba02b..000c58730ec 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -432,6 +432,15 @@ void closest_to_plane3_normalized_v3(float r_close[3], const float plane[3], con
   madd_v3_v3v3fl(r_close, pt, plane, -side);
 }
 
+void closest_to_plane3_normalized_v3_db(double r_close[3],
+                                        const double plane[3],
+                                        const double pt[3])
+{
+  const double side = dot_v3v3_db(plane, pt);
+  BLI_ASSERT_UNIT_V3_DB(plane);
+  madd_v3_v3v3db_db(r_close, pt, plane, -side);
+}
+
 float dist_signed_squared_to_plane_v3(const float pt[3], const float plane[4])
 {
   const float len_sq = len_squared_v3(plane);
@@ -3251,7 +3260,7 @@ bool isect_aabb_aabb_v3(const float min1[3],
 bool isect_aabb_aabb_v3_db(const double min1[3],
                            const double max1[3],
                            const double min2[3],
-						   const double max2[3])
+                           const double max2[3])
 {
   return (min1[0] < max2[0] && min1[1] < max2[1] && min1[2] < max2[2] && min2[0] < max1[0] &&
           min2[1] < max1[1] && min2[2] < max1[2]);
@@ -3379,7 +3388,10 @@ float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3],
   return lambda;
 }
 
-double closest_to_line_v3_db(double r_close[3], const double p[3], const double l1[3], const double l2[3])
+double closest_to_line_v3_db(double r_close[3],
+                             const double p[3],
+                             const double l1[3],
+                             const double l2[3])
 {
   double h[3], u[3], lambda;
   sub_v3_v3v3_db(u, l2, l1);
diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c
index d275ea0862e..79af62b430f 100644
--- a/source/blender/blenlib/intern/math_geom_inline.c
+++ b/source/blender/blenlib/intern/math_geom_inline.c
@@ -260,6 +260,11 @@ MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
   return dot_v3v3(co, plane) + plane[3];
 }
 
+MINLINE double plane_point_side_v3_db(const double plane[4], const double co[3])
+{
+  return dot_v3v3_db(co, plane) + plane[3];
+}
+
 /* useful to calculate an even width shell, by taking the angle between 2 planes.
  * The return value is a scale on the offset.
  * no angle between planes is 1.0, as the angle between the 2 planes approaches 180d
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 6a94459eb0c..66d78d1759e 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -700,6 +700,13 @@ MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
   r[2] += a[2] * b[2];
 }
 
+MINLINE void madd_v3_v3v3_db(double r[3], const double a[3], const double b[3])
+{
+  r[0] += a[0] * b[0];
+  r[1] += a[1] * b[1];
+  r[2] += a[2] * b[2];
+}
+
 MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
 {
   r[0] = a[0] + b[0] * f;
diff --git a/source/blender/bmesh/tools/bmesh_boolean.c b/source/blender/bmesh/tools/bmesh_boolean.c
index 80188183e14..b642c7166c9 100644
--- a/source/blender/bmesh/tools/bmesh_boolean.c
+++ b/source/blender/bmesh/tools/bmesh_boolean.c
@@ -808,66 +808,71 @@ static bool isect_tri_tri_epsilon_v3_db_ex(const double t_a0[3],
 }
 #endif
 
-/* Does the line intersect the segment (within epsilon)?
- * If line and seg are parallel and coincident, return 2.
- * If line intersects the segment within epsilon, return 1.
- * Otherwise return 0.
- * If the return value is 1, put the intersection point in isect,
- * and the fraction of the way from line_v1 to line_v2 to isect in *r_lambda
- * (may be outside of the range [0,1]) and the fraction of the way from seg_v1
- * to seg_v2 in *r_mu.
+/* TODO: move these into math_geom.c. */
+/* What is interpolation factor that gives closest point on line to a given point? */
+static double line_interp_factor_v3_db(const double point[3], const double line_co1[3], const double line_co2[3])
+{
+  double h[3], seg_dir[3], seg_len_squared;
+
+  sub_v3_v3v3_db(h, point, line_co1);
+  seg_len_squared = len_squared_v3v3_db(line_co2, line_co1);
+  if (UNLIKELY(seg_len_squared) == 0.0) {
+    return 0.0;
+  }
+  sub_v3_v3v3_db(seg_dir, line_co2, line_co1);
+  return dot_v3v3_db(h, seg_dir) / seg_len_squared;
+}
+
+/* Does the segment intersect the plane, within epsilon?
+ * Return value is 0 if no intersect, 1 if one intersect, 2 if the whole segment is in the plane.
+ * In case 1, r_isect gets the intersection point, possibly snapped to an endpoint (if outside
+ * segment but within epsilon) and r_lambda gets the factor from seg_co1 to seg_co2 of
+ * the intersection point.
+ * \note Similar logic to isect_ray_plane_v3.
  */
-static int isect_line_seg_epsilon_v3_db(const double line_v1[3],
-                                        const double line_v2[3],
-                                        const double seg_v1[3],
-                                        const double seg_v2[3],
-                                        double epsilon,
-                                        double isect[3],
-                                        double *r_lambda,
-                                        double *r_mu)
-{
-  double fac_a, fac_b;
-  double a_dir[3], b_dir[3], a0b0[3], crs_ab[3];
-  double epsilon_squared = epsilon * epsilon;
-  sub_v3_v3v3_db(a_dir, line_v2, line_v1);
-  sub_v3_v3v3_db(b_dir, seg_v2, seg_v1);
-  cross_v3_v3v3_db(crs_ab, b_dir, a_dir);
-  const double nlen = len_squared_v3_db(crs_ab);
-
-  if (nlen < epsilon_squared) {
-    /* Parallel Lines or near parallel. Are the coincident? */
-    double d1, d2;
-    d1 = dist_squared_to_line_v3_db(seg_v1, line_v1, line_v2);
-    d2 = dist_squared_to_line_v3_db(seg_v2, line_v1, line_v2);
-    if (d1 <= epsilon_squared || d2 <= epsilon_squared) {
+static int isect_seg_plane_normalized_epsilon_v3_db(const double seg_co1[3],
+             const double seg_co2[3],
+             const double plane[4],
+             double epsilon,
+             double r_isect[3],
+             double *r_lambda)
+{
+  double h[3], plane_co[3], seg_dir[3], side1, side2;
+  double dot, lambda;
+
+  BLI_ASSERT_UNIT_V3_DB(plane);
+  sub_v3_v3v3_db(seg_dir, seg_co2, seg_co1);
+  dot = dot_v3v3_db(plane, seg_dir);
+  if (dot == 0.0) {
+    /* plane_point_side_v3_db gets signed distance of point to plane. */
+    side1 = plane_point_side_v3_db(plane, seg_co1);
+    side2 = plane_point_side_v3_db(plane, seg_co2);
+    if (fabs(side1) <= epsilon || fabs(side2) <= epsilon) {
       return 2;
     }
     else {
       return 0;
     }
   }
+  mul_v3db_v3dbdb(plane_co, plane, -plane[3]);
+  sub_v3_v3v3_db(h, seg_co1, plane_co);
+  lambda = -dot_v3v3_db(plane, h) / dot;
+  if (lambda < -epsilon || lambda > 1.0 + epsilon) {
+    return 0;
+  }
+  if (lambda < 0.0) {
+    lambda = 0.0;
+    copy_v3_v3_db(r_isect, seg_co1);
+  }
+  else if (lambda > 1.0) {
+    lambda = 1.0;
+    copy_v3_v3_db(r_isect, seg_co2);
+  }
   else {
-    double c[3], cray[3];
-    double blen = len_v3_db(b_dir);
-    sub_v3_v3v3_db(a0b0, seg_v1, line_v1)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list