[Bf-blender-cvs] [b82d1cc4c7d] lanpr-under-gp: LineArt: Internal angle splitting function.

YimingWu noreply at git.blender.org
Wed Jul 29 10:02:09 CEST 2020


Commit: b82d1cc4c7d52e6d38769baf37fd0c9233af1e8d
Author: YimingWu
Date:   Wed Jul 29 16:01:42 2020 +0800
Branches: lanpr-under-gp
https://developer.blender.org/rBb82d1cc4c7d52e6d38769baf37fd0c9233af1e8d

LineArt: Internal angle splitting function.

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

M	release/scripts/startup/bl_ui/properties_render.py
M	source/blender/editors/include/ED_lineart.h
M	source/blender/editors/lineart/lineart_chain.c
M	source/blender/editors/lineart/lineart_cpu.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index df588c8adef..efc222cc93d 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -721,6 +721,7 @@ class RENDER_PT_lineart(RenderButtonsPanel, Panel):
 
         else:
             layout.prop(lineart, "crease_threshold", slider=True)
+            layout.prop(lineart, "angle_splitting_threshold", slider=True)
 
             layout.prop(lineart, "chaining_image_threshold")
             layout.prop(lineart, "chaining_geometry_threshold")
diff --git a/source/blender/editors/include/ED_lineart.h b/source/blender/editors/include/ED_lineart.h
index 38586ffbf20..a002c4d1779 100644
--- a/source/blender/editors/include/ED_lineart.h
+++ b/source/blender/editors/include/ED_lineart.h
@@ -245,9 +245,10 @@ typedef struct LineartRenderBuffer {
   float cam_obmat[4][4];
   double camera_pos[3];
   double near_clip, far_clip;
-  double shift_x, shift_y;
-  double chaining_image_threshold;
-  double chaining_geometry_threshold;
+  float shift_x, shift_y;
+  float chaining_image_threshold;
+  float chaining_geometry_threshold;
+  float angle_splitting_threshold;
 } LineartRenderBuffer;
 
 typedef enum eLineartRenderStatus {
@@ -485,6 +486,8 @@ void ED_lineart_chain_feature_lines(LineartRenderBuffer *rb);
 void ED_lineart_chain_split_for_fixed_occlusion(LineartRenderBuffer *rb);
 void ED_lineart_chain_connect(LineartRenderBuffer *rb, const int do_geometry_space);
 void ED_lineart_chain_discard_short(LineartRenderBuffer *rb, const float threshold);
+void ED_lineart_chain_split_angle(LineartRenderBuffer *rb, float angle_threshold_rad);
+
 int ED_lineart_chain_count(const LineartRenderLineChain *rlc);
 void ED_lineart_chain_clear_picked_flag(struct LineartRenderBuffer *rb);
 
diff --git a/source/blender/editors/lineart/lineart_chain.c b/source/blender/editors/lineart/lineart_chain.c
index 8b5f69eee18..21eda5c3d7b 100644
--- a/source/blender/editors/lineart/lineart_chain.c
+++ b/source/blender/editors/lineart/lineart_chain.c
@@ -848,3 +848,58 @@ void ED_lineart_chain_clear_picked_flag(LineartRenderBuffer *rb)
     rlc->picked = 0;
   }
 }
+
+/* This should always be the last stage!, see the end of
+ * ED_lineart_chain_split_for_fixed_occlusion().*/
+void ED_lineart_chain_split_angle(LineartRenderBuffer *rb, float angle_threshold_rad)
+{
+  LineartRenderLineChain *rlc, *new_rlc;
+  LineartRenderLineChainItem *rlci, *next_rlci, *prev_rlci;
+  ListBase swap = {0};
+
+  swap.first = rb->chains.first;
+  swap.last = rb->chains.last;
+
+  rb->chains.last = rb->chains.first = NULL;
+
+  while ((rlc = BLI_pophead(&swap)) != NULL) {
+    rlc->next = rlc->prev = NULL;
+    BLI_addtail(&rb->chains, rlc);
+    LineartRenderLineChainItem *first_rlci = (LineartRenderLineChainItem *)rlc->chain.first;
+    for (rlci = first_rlci->next; rlci; rlci = next_rlci) {
+      next_rlci = rlci->next;
+      prev_rlci = rlci->prev;
+      float angle = M_PI;
+      if (next_rlci && prev_rlci) {
+        angle = angle_v2v2v2(prev_rlci->pos, rlci->pos, next_rlci->pos);
+      }
+      else {
+        break; /* No need to split at the last point anyway.*/
+      }
+      if (angle < angle_threshold_rad) {
+        new_rlc = lineart_chain_create(rb);
+        new_rlc->chain.first = rlci;
+        new_rlc->chain.last = rlc->chain.last;
+        rlc->chain.last = rlci->prev;
+        ((LineartRenderLineChainItem *)rlc->chain.last)->next = 0;
+        rlci->prev = 0;
+
+        /*  end the previous one */
+        lineart_chain_append_point(rb,
+                                   rlc,
+                                   rlci->pos[0],
+                                   rlci->pos[1],
+                                   rlci->gpos[0],
+                                   rlci->gpos[1],
+                                   rlci->gpos[2],
+                                   rlci->normal,
+                                   rlci->line_type,
+                                   rlc->level);
+        new_rlc->object_ref = rlc->object_ref;
+        new_rlc->type = rlc->type;
+        new_rlc->level = rlc->level;
+        rlc = new_rlc;
+      }
+    }
+  }
+}
diff --git a/source/blender/editors/lineart/lineart_cpu.c b/source/blender/editors/lineart/lineart_cpu.c
index ea51097f356..b852d7bf1a1 100644
--- a/source/blender/editors/lineart/lineart_cpu.c
+++ b/source/blender/editors/lineart/lineart_cpu.c
@@ -114,8 +114,8 @@ static int lineart_triangle_line_imagespace_intersection_v2(SpinLock *spl,
                                                             const char override_cam_is_persp,
                                                             const double vp[4][4],
                                                             const double *camera_dir,
-                                                            const double cam_shift_x,
-                                                            const double cam_shift_y,
+                                                            const float cam_shift_x,
+                                                            const float cam_shift_y,
                                                             double *from,
                                                             double *to);
 
@@ -381,8 +381,6 @@ static void lineart_occlusion_single_line(LineartRenderBuffer *rb,
         }
       }
     }
-    printf("nba lrub %f %f %f %f\n", nba->l, nba->r, nba->u, nba->b);
-
     nba = lineart_bounding_area_next(nba, rl, x, y, k, positive_x, positive_y, &x, &y);
   }
 }
@@ -1659,8 +1657,8 @@ static int lineart_triangle_line_imagespace_intersection_v2(SpinLock *UNUSED(spl
                                                             const char override_cam_is_persp,
                                                             const double vp[4][4],
                                                             const double *camera_dir,
-                                                            const double cam_shift_x,
-                                                            const double cam_shift_y,
+                                                            const float cam_shift_x,
+                                                            const float cam_shift_y,
                                                             double *from,
                                                             double *to)
 {
@@ -2388,6 +2386,7 @@ LineartRenderBuffer *ED_lineart_create_render_buffer(Scene *scene)
     rb->shift_y = c->shifty;
   }
 
+  rb->angle_splitting_threshold = scene->lineart.angle_splitting_threshold;
   rb->chaining_image_threshold = scene->lineart.chaining_image_threshold;
   rb->chaining_geometry_threshold = scene->lineart.chaining_geometry_threshold;
 
@@ -3507,6 +3506,8 @@ int ED_lineart_compute_feature_lines_internal(Depsgraph *depsgraph, const int sh
 
     /* This configuration ensures there won't be accidental lost of short segments */
     ED_lineart_chain_discard_short(rb, MIN3(t_image, t_geom, 0.01f) - FLT_EPSILON);
+
+    ED_lineart_chain_split_angle(rb, rb->angle_splitting_threshold);
   }
   // Set after GP done.
   // ED_lineart_calculation_flag_set(LRT_RENDER_FINISHED);
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 239db677efc..22913ab1146 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1731,8 +1731,8 @@ typedef struct SceneLineart {
 
   int _pad;
 
-  /** cosine angle, for splitting strokes at sharp points */
-  float separation_angle;
+  /**  0-PI angle, for splitting strokes at sharp points */
+  float angle_splitting_threshold;
 
   /* CPU mode */
   float chaining_geometry_threshold;
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 117f8442194..03ccfeb487f 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -7331,6 +7331,14 @@ static void rna_def_scene_lineart(BlenderRNA *brna)
   RNA_def_property_flag(prop, PROP_EDITABLE);
   RNA_def_property_update(prop, NC_SCENE, "rna_lineart_update");
 
+  prop = RNA_def_property(srna, "angle_splitting_threshold", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_float_default(prop, 0.5f);
+  RNA_def_property_ui_text(prop, "Angle Splitting", "angle splitting threshold in radian");
+  /*  Don't allow value very close to PI, or we get a lot of small segments.*/
+  RNA_def_property_ui_range(prop, 0.0f, M_PI - 0.1, 0.01f, 2);
+  RNA_def_property_flag(prop, PROP_EDITABLE);
+  RNA_def_property_update(prop, NC_SCENE, "rna_lineart_update");
+
   /* types */
   prop = RNA_def_property(srna, "use_contour", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "line_types", LRT_EDGE_FLAG_CONTOUR);



More information about the Bf-blender-cvs mailing list