[Bf-blender-cvs] [6f9f45aa4b3] temp-lineart-contained: WIP bake buttons

Sebastian Parborg noreply at git.blender.org
Mon Feb 15 01:59:10 CET 2021


Commit: 6f9f45aa4b3d7c6f68121a7df9cf15176c23aed4
Author: Sebastian Parborg
Date:   Mon Feb 15 01:58:14 2021 +0100
Branches: temp-lineart-contained
https://developer.blender.org/rB6f9f45aa4b3d7c6f68121a7df9cf15176c23aed4

WIP bake buttons

Buggy and naming and settings needs to change probably.
See TODOs in the code

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

M	source/blender/editors/object/object_ops.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
M	source/blender/gpencil_modifiers/intern/lineart/ED_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c

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

diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 2124d242ee2..2fec027fa4b 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -37,6 +37,9 @@
 
 #include "object_intern.h"
 
+// TODO: Not nice, but here in the mean time to just try out the LineArt bake operators
+#include "../../gpencil_modifiers/intern/lineart/ED_lineart.h"
+
 /* ************************** registration **********************************/
 
 void ED_operatortypes_object(void)
@@ -153,6 +156,7 @@ void ED_operatortypes_object(void)
   WM_operatortype_append(OBJECT_OT_gpencil_modifier_apply);
   WM_operatortype_append(OBJECT_OT_gpencil_modifier_copy);
   WM_operatortype_append(OBJECT_OT_gpencil_modifier_copy_to_selected);
+  ED_operatortypes_lineart();
 
   /* shader fx */
   WM_operatortype_append(OBJECT_OT_shaderfx_add);
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index 3a376438dfb..6249e385c9d 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -400,6 +400,22 @@ static void vgroup_panel_draw(const bContext *UNUSED(C), Panel *panel)
   uiItemR(layout, ptr, "soft_selection", 0, NULL, ICON_NONE);
 }
 
+static void baking_panel_draw(const bContext *UNUSED(C), Panel *panel)
+{
+  uiLayout *layout = panel->layout;
+
+  uiLayoutSetPropSep(layout, true);
+
+  // TODO come up with better names for these buttons!
+  uiItemO(layout, IFACE_("Bake Current Object"), ICON_NONE, "OBJECT_OT_lineart_bake_strokes");
+  uiItemO(layout,
+          IFACE_("Bake All Line Art Objects"),
+          ICON_NONE,
+          "OBJECT_OT_lineart_bake_all_strokes");
+  uiItemO(layout, IFACE_("Clear Current Object"), ICON_NONE, "OBJECT_OT_lineart_clear_strokes");
+  uiItemO(layout, IFACE_("Clear All Objects"), ICON_NONE, "OBJECT_OT_lineart_clear_all_strokes");
+}
+
 static void panelRegister(ARegionType *region_type)
 {
   PanelType *panel_type = gpencil_modifier_panel_register(
@@ -413,6 +429,8 @@ static void panelRegister(ARegionType *region_type)
       region_type, "chaining", "Chaining", NULL, chaining_panel_draw, panel_type);
   gpencil_modifier_subpanel_register(
       region_type, "vgroup", "Vertex Weight Transfer", NULL, vgroup_panel_draw, panel_type);
+  gpencil_modifier_subpanel_register(
+      region_type, "baking", "Baking", NULL, baking_panel_draw, panel_type);
 }
 
 GpencilModifierTypeInfo modifierType_Gpencil_Lineart = {
diff --git a/source/blender/gpencil_modifiers/intern/lineart/ED_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/ED_lineart.h
index 738274e0c1b..ae7d0c663b1 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/ED_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/ED_lineart.h
@@ -582,6 +582,9 @@ float ED_lineart_chain_compute_length(LineartRenderLineChain *rlc);
 struct wmOperatorType;
 
 /* Operator types */
-void SCENE_OT_lineart_bake_strokes(struct wmOperatorType *ot);
+void OBJECT_OT_lineart_bake_strokes(struct wmOperatorType *ot);
+void OBJECT_OT_lineart_bake_all_strokes(struct wmOperatorType *ot);
+void OBJECT_OT_lineart_clear_strokes(struct wmOperatorType *ot);
+void OBJECT_OT_lineart_clear_all_strokes(struct wmOperatorType *ot);
 
 void ED_operatortypes_lineart(void);
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c
index 9e9a71e99ea..d9e6551a288 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c
@@ -46,209 +46,304 @@
 
 #include "lineart_intern.h"
 
-#ifdef LINEART_WITH_BAKE
-
-static int lineart_gpencil_update_strokes_exec(bContext *C, wmOperator *UNUSED(op))
+static void clear_strokes(Object *ob, GpencilModifierData *md, int frame)
 {
-  Depsgraph *dg = CTX_data_depsgraph_pointer(C);
+  if (md->type != eGpencilModifierType_Lineart) {
+    return;
+  }
+  LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
+  bGPdata *gpd = ob->data;
 
-  BLI_spin_lock(&lineart_share.lock_loader);
+  bGPDlayer *gpl = BKE_gpencil_layer_get_by_name(gpd, lmd->target_layer, 1);
+  if (!gpl) {
+    return;
+  }
+  bGPDframe *gpf = BKE_gpencil_layer_frame_find(gpl, frame);
+
+  if (!gpf) {
+    /* No greasepencil frame found. */
+    return;
+  }
 
-  ED_lineart_compute_feature_lines_background(dg, 0);
+  BKE_gpencil_layer_frame_delete(gpl, gpf);
+}
 
-  /* Wait for loading finish. */
-  BLI_spin_lock(&lineart_share.lock_loader);
-  BLI_spin_unlock(&lineart_share.lock_loader);
+// TODO use the job system for baking so that the UI doesn't freeze on big bake tasks.
+static void bake_strokes(Object *ob, Depsgraph *dg, GpencilModifierData *md, int frame)
+{
+  if (md->type != eGpencilModifierType_Lineart) {
+    return;
+  }
+  LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
+  bGPdata *gpd = ob->data;
 
-  WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED | ND_SPACE_PROPERTIES, NULL);
+  bGPDlayer *gpl = BKE_gpencil_layer_get_by_name(gpd, lmd->target_layer, 1);
+  if (!gpl) {
+    return;
+  }
+  bool only_use_existing_gp_frames = false;
+  bGPDframe *gpf = (only_use_existing_gp_frames ?
+                        BKE_gpencil_layer_frame_find(gpl, frame) :
+                        BKE_gpencil_layer_frame_get(gpl, frame, GP_GETFRAME_ADD_NEW));
+
+  if (!gpf) {
+    /* No greasepencil frame created or found. */
+    return;
+  }
 
-  return OPERATOR_FINISHED;
+  ED_lineart_compute_feature_lines_internal(dg, lmd);
+
+  ED_lineart_gpencil_generate_with_type(
+      lmd->render_buffer,
+      dg,
+      ob,
+      gpl,
+      gpf,
+      lmd->source_type,
+      lmd->source_type == LRT_SOURCE_OBJECT ? (void *)lmd->source_object :
+                                              (void *)lmd->source_collection,
+      lmd->level_start,
+      lmd->use_multiple_levels ? lmd->level_end : lmd->level_start,
+      lmd->target_material ? BKE_gpencil_object_material_index_get(ob, lmd->target_material) : 0,
+      lmd->line_types,
+      lmd->transparency_flags,
+      lmd->transparency_mask,
+      lmd->thickness,
+      lmd->opacity,
+      lmd->pre_sample_length,
+      lmd->source_vertex_group,
+      lmd->vgname,
+      lmd->flags);
+
+  ED_lineart_destroy_render_data(lmd);
 }
 
-static int lineart_gpencil_bake_strokes_invoke(bContext *C,
-                                               wmOperator *op,
-                                               const wmEvent *UNUSED(event))
+static int lineart_gpencil_bake_all_strokes_invoke(bContext *C,
+                                                   wmOperator *op,
+                                                   const wmEvent *UNUSED(event))
 {
   Scene *scene = CTX_data_scene(C);
   Depsgraph *dg = CTX_data_depsgraph_pointer(C);
   int frame;
-  int frame_begin = ((lineart->flags & LRT_BAKING_FINAL_RANGE) ? MAX2(scene->r.sfra, 1) :
-                                                                 lineart->baking_preview_start);
-  int frame_end = ((lineart->flags & LRT_BAKING_FINAL_RANGE) ? scene->r.efra :
-                                                               lineart->baking_preview_end);
-  int frame_total = frame_end - frame_begin;
+  int frame_begin = scene->r.sfra;
+  int frame_end = scene->r.efra;
   int frame_orig = scene->r.cfra;
-  int frame_increment = ((lineart->flags & LRT_BAKING_KEYFRAMES_ONLY) ?
-                             1 :
-                             (lineart->baking_skip + 1));
-  LineartGpencilModifierData *lmd;
-  LineartRenderBuffer *rb;
-  int use_types;
-  bool frame_updated;
-
-  /* Needed for progress report. */
-  lineart_share.wm = CTX_wm_manager(C);
-  lineart_share.main_window = CTX_wm_window(C);
+  int frame_increment = scene->r.frame_step;
+  bool overwrite_frames = true;
 
   for (frame = frame_begin; frame <= frame_end; frame += frame_increment) {
 
-    frame_updated = false;
+    BKE_scene_frame_set(scene, frame);
+    BKE_scene_graph_update_for_newframe(dg);
 
-    FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (
-        scene->master_collection, ob, DAG_EVAL_RENDER) {
-
-      int cleared = 0;
+    CTX_DATA_BEGIN (C, Object *, ob, visible_objects) {
       if (ob->type != OB_GPENCIL) {
         continue;
       }
 
-      LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
-        if (md->type != eGpencilModifierType_Lineart) {
-          continue;
-        }
-        lmd = (LineartGpencilModifierData *)md;
-        bGPdata *gpd = ob->data;
-        bGPDlayer *gpl = BKE_gpencil_layer_get_by_name(gpd, lmd->target_layer, 1);
-        bGPDframe *gpf = ((lineart->flags & LRT_BAKING_KEYFRAMES_ONLY) ?
-                              BKE_gpencil_layer_frame_find(gpl, frame) :
-                              BKE_gpencil_layer_frame_get(gpl, frame, GP_GETFRAME_ADD_NEW));
-
-        if (!gpf) {
-          continue; /* happens when it's keyframe only. */
+      if (overwrite_frames) {
+        LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
+          clear_strokes(ob, md, frame);
         }
+      }
 
-        if (!frame_updated) {
-          /* Reset flags. LRT_SYNC_IGNORE prevent any line art modifiers run calculation
-           * function when depsgraph calls for modifier evalurates. */
-          ED_lineart_modifier_sync_flag_set(LRT_SYNC_IGNORE, false);
-          ED_lineart_calculation_flag_set(LRT_RENDER_IDLE);
+      LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
+        bake_strokes(ob, dg, md, frame);
+      }
+    }
+    CTX_DATA_END;
+  }
 
-          BKE_scene_frame_set(scene, frame);
-          BKE_scene_graph_update_for_newframe(dg);
+  /* Restore original frame. */
+  BKE_scene_frame_set(scene, frame_orig);
+  BKE_scene_graph_update_for_newframe(dg);
 
-          ED_lineart_update_render_progress(
-              (int)((float)(frame - frame_begin) / frame_total * 100), NULL);
+  BKE_report(op->reports, RPT_INFO, "Line Art baking is complete.");
+  WM_event_add_notifier(C, 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list