[Bf-blender-cvs] [45461012378] soc-2020-io-performance: Make all frames exportable; UI & filename changes

Ankit Meel noreply at git.blender.org
Mon Jun 15 19:22:53 CEST 2020


Commit: 454610123787a7b8f71e0e9187603c876e7833f7
Author: Ankit Meel
Date:   Mon Jun 15 22:52:36 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB454610123787a7b8f71e0e9187603c876e7833f7

Make all frames exportable; UI & filename changes

All frames are now exportable including negative ones, instead of
only 0-1000.

Added checkbox for Animation for better UI {F8622012}

File name doesn't contain frame name if no animation is being exported.

Noticed that `source/blender/io/wavefront_obj/IO_wavefront_obj.h` is
missing in the IDE's edited files list. So edited that in.

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

M	source/blender/editors/io/io_obj.c
M	source/blender/io/wavefront_obj/CMakeLists.txt
M	source/blender/io/wavefront_obj/IO_wavefront_obj.h
M	source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc

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

diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 7fcc78161c6..1056858b876 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -73,25 +73,6 @@ static int wm_obj_export_invoke(bContext *C, wmOperator *op, const wmEvent *even
   UNUSED_VARS(event);
 }
 
-static bool wm_obj_export_check(bContext *UNUSED(C), wmOperator *op)
-{
-  char filepath[FILE_MAX];
-  RNA_string_get(op->ptr, "filepath", filepath);
-
-  if (!BLI_path_extension_check(filepath, ".obj")) {
-    BLI_path_extension_ensure(filepath, FILE_MAX, ".obj");
-    RNA_string_set(op->ptr, "filepath", filepath);
-    return true;
-  }
-
-  /* End frame should be greater than or equal to start frame. */
-  if (RNA_int_get(op->ptr, "start_frame") > RNA_int_get(op->ptr, "end_frame")) {
-    RNA_int_set(op->ptr, "end_frame", RNA_int_get(op->ptr, "start_frame"));
-    return true;
-  }
-  return false;
-}
-
 static int wm_obj_export_exec(bContext *C, wmOperator *op)
 {
   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -100,8 +81,10 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
   }
   struct OBJExportParams export_params;
   RNA_string_get(op->ptr, "filepath", export_params.filepath);
+  export_params.export_animation = RNA_boolean_get(op->ptr, "export_animation");
   export_params.start_frame = RNA_int_get(op->ptr, "start_frame");
   export_params.end_frame = RNA_int_get(op->ptr, "end_frame");
+
   OBJ_export(C, &export_params);
 
   return OPERATOR_FINISHED;
@@ -111,16 +94,22 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr)
 {
   uiLayout *box;
   uiLayout *row;
+  bool export_animation = RNA_boolean_get(imfptr, "export_animation");
 
   box = uiLayoutBox(layout);
   row = uiLayoutRow(box, false);
-  uiItemL(row, IFACE_("Animation "), ICON_NONE);
+  uiItemL(row, IFACE_("Animation"), ICON_NONE);
+
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "export_animation", 0, NULL, ICON_NONE);
 
   row = uiLayoutRow(box, false);
   uiItemR(row, imfptr, "start_frame", 0, NULL, ICON_NONE);
+  uiLayoutSetEnabled(row, export_animation);
 
   row = uiLayoutRow(box, false);
   uiItemR(row, imfptr, "end_frame", 0, NULL, ICON_NONE);
+  uiLayoutSetEnabled(row, export_animation);
 }
 
 static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
@@ -130,6 +119,34 @@ static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op)
   ui_obj_export_settings(op->layout, &ptr);
 }
 
+static bool wm_obj_export_check(bContext *C, wmOperator *op)
+{
+  char filepath[FILE_MAX];
+  Scene *scene = CTX_data_scene(C);
+  bool ret = false;
+  RNA_string_get(op->ptr, "filepath", filepath);
+
+  if (!BLI_path_extension_check(filepath, ".obj")) {
+    BLI_path_extension_ensure(filepath, FILE_MAX, ".obj");
+    RNA_string_set(op->ptr, "filepath", filepath);
+    ret = true;
+  }
+
+  /* Set the default export frames to the current one in viewport. */
+  if (RNA_int_get(op->ptr, "start_frame") == INT_MAX) {
+    RNA_int_set(op->ptr, "start_frame", CFRA);
+    RNA_int_set(op->ptr, "end_frame", CFRA);
+    ret = true;
+  }
+
+  /* End frame should be greater than or equal to start frame. */
+  if (RNA_int_get(op->ptr, "start_frame") > RNA_int_get(op->ptr, "end_frame")) {
+    RNA_int_set(op->ptr, "end_frame", RNA_int_get(op->ptr, "start_frame"));
+    ret = true;
+  }
+  return ret;
+}
+
 void WM_OT_obj_export(struct wmOperatorType *ot)
 {
   ot->name = "Export Wavefront OBJ";
@@ -150,17 +167,30 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
                                  FILE_DEFAULTDISPLAY,
                                  FILE_SORT_ALPHA);
 
+  RNA_def_boolean(ot->srna,
+                  "export_animation",
+                  false,
+                  "Export Animation",
+                  "Write selected range of frames to individual files. If unchecked, exports the "
+                  "current viewport frame ");
   RNA_def_int(ot->srna,
               "start_frame",
-              1,
-              0,
-              1000,
+              INT_MAX,
+              -INT_MAX,
+              INT_MAX,
               "Start Frame",
               "The first frame to be exported",
               0,
               250);
-  RNA_def_int(
-      ot->srna, "end_frame", 1, 0, 1000, "End Frame", "The last frame to be exported", 0, 250);
+  RNA_def_int(ot->srna,
+              "end_frame",
+              1,
+              -INT_MAX,
+              INT_MAX,
+              "End Frame",
+              "The last frame to be exported",
+              0,
+              250);
 }
 
 static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
diff --git a/source/blender/io/wavefront_obj/CMakeLists.txt b/source/blender/io/wavefront_obj/CMakeLists.txt
index 42ae3ae5fbd..87b954df0b5 100644
--- a/source/blender/io/wavefront_obj/CMakeLists.txt
+++ b/source/blender/io/wavefront_obj/CMakeLists.txt
@@ -45,6 +45,7 @@ set(SRC
   intern/wavefront_obj_file_handler.cc
   intern/wavefront_obj_importer.cc
 
+  IO_wavefront_obj.h
   intern/wavefront_obj.hh
   intern/wavefront_obj_exporter.hh
   intern/wavefront_obj_file_handler.hh
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index a31f2e73395..ca6bbcff2b9 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -31,10 +31,12 @@ extern "C" {
 struct OBJExportParams {
   /** Full path to the destination OBJ file to export. */
   char filepath[FILENAME_MAX];
+  /** Whether mutiple frames are to be exported or not. */
+  bool export_animation;
   /** The first frame to be exported. */
-  short start_frame;
+  int start_frame;
   /** The last frame to be exported. */
-  short end_frame;
+  int end_frame;
 };
 
 struct OBJImportParams {
diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
index 63b0d8d61b2..2c1c246fa51 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_exporter.cc
@@ -235,18 +235,24 @@ void exporter_main(bContext *C, const OBJExportParams *export_params)
 {
   Scene *scene = CTX_data_scene(C);
   const char *filepath = export_params->filepath;
-  short start_frame = export_params->start_frame;
-  short end_frame = export_params->end_frame;
-  char filepath_with_frames[FILE_MAX];
 
+  /* Single frame export. */
+  if (!export_params->export_animation) {
+    export_frame(C, export_params, filepath);
+    return;
+  }
+
+  int start_frame = export_params->start_frame;
+  int end_frame = export_params->end_frame;
+  char filepath_with_frames[FILE_MAX];
   /* To reset the Scene to its original state. */
   int original_frame = CFRA;
 
-  for (short frame = start_frame; frame <= end_frame; frame++) {
+  for (int frame = start_frame; frame <= end_frame; frame++) {
     BLI_strncpy(filepath_with_frames, filepath, FILE_MAX);
-    /* 0 + 4 digits for frame number + 4 for extension + 1 null. */
-    char frame_ext[10];
-    BLI_snprintf(frame_ext, 10, "0%hd.obj", frame);
+    /* 1 _ + 11 digits for frame number (INT_MAX + sign) + 4 for extension + 1 null. */
+    char frame_ext[17];
+    BLI_snprintf(frame_ext, 17, "_%d.obj", frame);
     bool filepath_ok = BLI_path_extension_replace(filepath_with_frames, FILE_MAX, frame_ext);
     if (filepath_ok == false) {
       printf("Error: File Path too long.");



More information about the Bf-blender-cvs mailing list