[Bf-blender-cvs] [fe15766f463] blender-v3.3-release: GPencil: Add frame number to Trace operator

Antonio Vazquez noreply at git.blender.org
Wed Sep 21 14:27:11 CEST 2022


Commit: fe15766f463db6cb9e37307972ac0b80e147bc34
Author: Antonio Vazquez
Date:   Thu Sep 15 11:10:21 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rBfe15766f463db6cb9e37307972ac0b80e147bc34

GPencil: Add frame number to Trace operator

The default trace can only trace an image or a sequence, but
it was not possible to trace only selected frames in a sequence. 
This new parameter allows to define what frame trace.

If the value is 0, the trace is done as before.

The parameter is not exposed in the UI because this is logic
if it is managed by a python API, but it has no sense in the UI.

This feature was included after receiving feedback from Studios
which need to trace videos only for some frames using custom
python scripts.

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

M	source/blender/editors/gpencil/gpencil_trace_ops.c

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

diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c b/source/blender/editors/gpencil/gpencil_trace_ops.c
index f6e88e05d46..fae1dccf404 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -71,6 +71,9 @@ typedef struct TraceJob {
   int32_t thickness;
   int32_t turnpolicy;
   int32_t mode;
+  /** Frame to render to be used by python API. Not exposed in UI.
+   * This feature is only used in Studios to run custom video trace for selected frames. */
+  int32_t frame_num;
 
   bool success;
   bool was_canceled;
@@ -212,7 +215,10 @@ static void trace_start_job(void *customdata, short *stop, short *do_update, flo
       (trace_job->mode == GPENCIL_TRACE_MODE_SINGLE)) {
     void *lock;
     ImageUser *iuser = trace_job->ob_active->iuser;
-    iuser->framenr = init_frame;
+
+    iuser->framenr = ((trace_job->frame_num == 0) || (trace_job->frame_num > iuser->frames)) ?
+                         init_frame :
+                         trace_job->frame_num;
     ImBuf *ibuf = BKE_image_acquire_ibuf(trace_job->image, iuser, &lock);
     if (ibuf) {
       /* Create frame. */
@@ -324,13 +330,14 @@ static int gpencil_trace_image_exec(bContext *C, wmOperator *op)
   job->thickness = RNA_int_get(op->ptr, "thickness");
   job->turnpolicy = RNA_enum_get(op->ptr, "turnpolicy");
   job->mode = RNA_enum_get(op->ptr, "mode");
+  job->frame_num = RNA_int_get(op->ptr, "frame_number");
 
   trace_initialize_job_data(job);
 
   /* Back to active base. */
   ED_object_base_activate(job->C, job->base_active);
 
-  if (job->image->source == IMA_SRC_FILE) {
+  if ((job->image->source == IMA_SRC_FILE) || (job->frame_num > 0)) {
     short stop = 0, do_update = true;
     float progress;
     trace_start_job(job, &stop, &do_update, &progress);
@@ -364,6 +371,8 @@ static int gpencil_trace_image_invoke(bContext *C, wmOperator *op, const wmEvent
 
 void GPENCIL_OT_trace_image(wmOperatorType *ot)
 {
+  PropertyRNA *prop;
+
   static const EnumPropertyItem turnpolicy_type[] = {
       {POTRACE_TURNPOLICY_BLACK,
        "BLACK",
@@ -475,4 +484,15 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
                   true,
                   "Start At Current Frame",
                   "Trace Image starting in current image frame");
+  prop = RNA_def_int(
+      ot->srna,
+      "frame_number",
+      0,
+      0,
+      9999,
+      "Trace Frame",
+      "Used to trace only one frame of the image sequence, set to zero to trace all",
+      0,
+      9999);
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }



More information about the Bf-blender-cvs mailing list