[Bf-blender-cvs] [6ffe5a545b0] temp-lineart-embree: LineArt: Trying out moller tri-tri functions.

YimingWu noreply at git.blender.org
Tue Mar 29 15:59:33 CEST 2022


Commit: 6ffe5a545b0fb83c89ba3537ceca4db6559bf048
Author: YimingWu
Date:   Tue Mar 29 21:58:47 2022 +0800
Branches: temp-lineart-embree
https://developer.blender.org/rB6ffe5a545b0fb83c89ba3537ceca4db6559bf048

LineArt: Trying out moller tri-tri functions.

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

M	source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
M	source/blender/gpencil_modifiers/intern/lineart/lineart_util.c

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

diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index f4c0203cc8f..95b6807443b 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -802,6 +802,16 @@ float MOD_lineart_chain_compute_length(LineartEdgeChain *ec);
 
 void ED_operatortypes_lineart(void);
 
+int moller_tri_tri_intersect_with_isectline(double V0[3],
+                                            double V1[3],
+                                            double V2[3],
+                                            double U0[3],
+                                            double U1[3],
+                                            double U2[3],
+                                            int *coplanar,
+                                            double isectpt1[3],
+                                            double isectpt2[3]);
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index ec0a141e0d7..b317ab3be85 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -2990,6 +2990,18 @@ static bool lineart_embree_triangle_intersect(LineartTriangle *tri,
     }
   }
   else {
+
+    int coplanar;
+    int res_moller = moller_tri_tri_intersect_with_isectline(tri->v[0]->gloc,
+                                                             tri->v[1]->gloc,
+                                                             tri->v[2]->gloc,
+                                                             testing->v[0]->gloc,
+                                                             testing->v[1]->gloc,
+                                                             testing->v[2]->gloc,
+                                                             &coplanar,
+                                                             r_v1,
+                                                             r_v2);
+    return res_moller && !coplanar;
     /* If not sharing any points, then we need to try all the possibilities. */
 
     int pcount = 0;
@@ -3546,35 +3558,35 @@ OcclusionCollideFunc(void *userPtr, struct RTCCollision *collisions, unsigned in
     float pa[9], pb[9];
     // float *pb = geom_triangle->points;
 
-    copy_v3fl_v3db(&pa[0], prim_edge->v1->gloc);
-    copy_v3fl_v3db(&pa[3], prim_edge->v2->gloc);
-    copy_v3fl_v3db(&pa[6], rb->camera_pos);
-    copy_v3fl_v3db(&pb[0], prim_triangle->v[0]->gloc);
-    copy_v3fl_v3db(&pb[3], prim_triangle->v[1]->gloc);
-    copy_v3fl_v3db(&pb[6], prim_triangle->v[2]->gloc);
+    // copy_v3fl_v3db(&pa[0], prim_edge->v1->gloc);
+    // copy_v3fl_v3db(&pa[3], prim_edge->v2->gloc);
+    // copy_v3fl_v3db(&pa[6], rb->camera_pos);
+    // copy_v3fl_v3db(&pb[0], prim_triangle->v[0]->gloc);
+    // copy_v3fl_v3db(&pb[3], prim_triangle->v[1]->gloc);
+    // copy_v3fl_v3db(&pb[6], prim_triangle->v[2]->gloc);
 
     // uint32_t *tb = geom_triangle->looptri[collisions[i].primID1].tri;
     float i1[3], i2[3];
-    if (lineart_isect_tri_tri_v3_check_overlap(
-            &pa[0], &pa[3], &pa[6], &pb[0], &pb[3], &pb[6], i1, i2)) {
-      // lineart_add_occlusion_pair_thread(rb, eln_edge, eln_triangle, prim_edge, prim_triangle);
-      double l, r;
-      if (lineart_triangle_edge_image_space_occlusion(NULL,
-                                                      prim_triangle,
-                                                      prim_edge,
-                                                      rb->camera_pos,
-                                                      rb->cam_is_persp,
-                                                      rb->allow_overlapping_edges,
-                                                      rb->view_projection,
-                                                      rb->view_vector,
-                                                      rb->shift_x,
-                                                      rb->shift_y,
-                                                      &l,
-                                                      &r)) {
-        lineart_thread_add_occlusion_pair(
-            rb->thread_occlusion_data, eln_edge, eln_triangle, prim_edge, prim_triangle, l, r);
-      }
+    // if (lineart_isect_tri_tri_v3_check_overlap(
+    //        &pa[0], &pa[3], &pa[6], &pb[0], &pb[3], &pb[6], i1, i2)) {
+    // lineart_add_occlusion_pair_thread(rb, eln_edge, eln_triangle, prim_edge, prim_triangle);
+    double l, r;
+    if (lineart_triangle_edge_image_space_occlusion(NULL,
+                                                    prim_triangle,
+                                                    prim_edge,
+                                                    rb->camera_pos,
+                                                    rb->cam_is_persp,
+                                                    rb->allow_overlapping_edges,
+                                                    rb->view_projection,
+                                                    rb->view_vector,
+                                                    rb->shift_x,
+                                                    rb->shift_y,
+                                                    &l,
+                                                    &r)) {
+      lineart_thread_add_occlusion_pair(
+          rb->thread_occlusion_data, eln_edge, eln_triangle, prim_edge, prim_triangle, l, r);
     }
+    //}
   }
 }
 
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_util.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_util.c
index 4ea17b25995..c3df21d3f74 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_util.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_util.c
@@ -247,3 +247,874 @@ void lineart_count_and_print_render_buffer_memory(LineartRenderBuffer *rb)
 
   (void)total; /* Ignored. */
 }
+
+/* Triangle/triangle intersection test routine,
+ * by Tomas Moller, 1997.
+ * See article "A Fast Triangle-Triangle Intersection Test",
+ * Journal of Graphics Tools, 2(2), 1997
+ * updated: 2001-06-20 (added line of intersection)
+ *
+ * int moller_tri_tri_intersect(double V0[3],double V1[3],double V2[3],
+ *                       double U0[3],double U1[3],double U2[3])
+ *
+ * parameters: vertices of triangle 1: V0,V1,V2
+ *             vertices of triangle 2: U0,U1,U2
+ * result    : returns 1 if the triangles intersect, otherwise 0
+ *
+ * Here is a version withouts divisions (a little faster)
+ * int moller_NoDivTriTriIsect(double V0[3],double V1[3],double V2[3],
+ *                      double U0[3],double U1[3],double U2[3]);
+ *
+ * This version computes the line of intersection as well (if they are not coplanar):
+ * int moller_tri_tri_intersect_with_isectline(double V0[3],double V1[3],double V2[3],
+ *				        double U0[3],double U1[3],double U2[3],int *coplanar,
+ *				        double isectpt1[3],double isectpt2[3]);
+ * coplanar returns whether the tris are coplanar
+ * isectpt1, isectpt2 are the endpoints of the line of intersection
+ */
+
+/*
+Copyright 2020 Tomas Akenine-Möller
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or
+substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
+NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
+OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <math.h>
+
+#define FABS(x) ((double)fabs(x)) /* implement as is fastest on your machine */
+
+/* if USE_EPSILON_TEST is true then we do a check:
+         if |dv|<EPSILON then dv=0.0;
+   else no check is done (which is less robust)
+*/
+#define USE_EPSILON_TEST 0
+#define EPSILON 0.000001
+
+/* some macros */
+#define CROSS(dest, v1, v2) \
+  dest[0] = v1[1] * v2[2] - v1[2] * v2[1]; \
+  dest[1] = v1[2] * v2[0] - v1[0] * v2[2]; \
+  dest[2] = v1[0] * v2[1] - v1[1] * v2[0];
+
+#define DOT(v1, v2) (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2])
+
+#define SUB(dest, v1, v2) \
+  dest[0] = v1[0] - v2[0]; \
+  dest[1] = v1[1] - v2[1]; \
+  dest[2] = v1[2] - v2[2];
+
+#define ADD(dest, v1, v2) \
+  dest[0] = v1[0] + v2[0]; \
+  dest[1] = v1[1] + v2[1]; \
+  dest[2] = v1[2] + v2[2];
+
+#define MULT(dest, v, factor) \
+  dest[0] = factor * v[0]; \
+  dest[1] = factor * v[1]; \
+  dest[2] = factor * v[2];
+
+#define SET(dest, src) \
+  dest[0] = src[0]; \
+  dest[1] = src[1]; \
+  dest[2] = src[2];
+
+/* sort so that a<=b */
+#define SORT(a, b) \
+  if (a > b) { \
+    double _c; \
+    _c = a; \
+    a = b; \
+    b = _c; \
+  }
+
+#define ISECT(VV0, VV1, VV2, D0, D1, D2, isect0, isect1) \
+  isect0 = VV0 + (VV1 - VV0) * D0 / (D0 - D1); \
+  isect1 = VV0 + (VV2 - VV0) * D0 / (D0 - D2);
+
+#define COMPUTE_INTERVALS(VV0, VV1, VV2, D0, D1, D2, D0D1, D0D2, isect0, isect1) \
+  if (D0D1 > 0.0f) { \
+    /* here we know that D0D2<=0.0 */ \
+    /* that is D0, D1 are on the same side, D2 on the other or on the plane */ \
+    ISECT(VV2, VV0, VV1, D2, D0, D1, isect0, isect1); \
+  } \
+  else if (D0D2 > 0.0f) { \
+    /* here we know that d0d1<=0.0 */ \
+    ISECT(VV1, VV0, VV2, D1, D0, D2, isect0, isect1); \
+  } \
+  else if (D1 * D2 > 0.0f || D0 != 0.0f) { \
+    /* here we know that d0d1<=0.0 or that D0!=0.0 */ \
+    ISECT(VV0, VV1,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list