[Bf-blender-cvs] [32b4a7aa873] soc-2019-fast-io: [Fast import/export] Refactoring to separate settings specific to each exporter

Hugo Sales noreply at git.blender.org
Mon Jun 24 11:41:06 CEST 2019


Commit: 32b4a7aa87398db74f5392c2be0259ba0a42236f
Author: Hugo Sales
Date:   Mon Jun 24 10:40:43 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rB32b4a7aa87398db74f5392c2be0259ba0a42236f

[Fast import/export] Refactoring to separate settings specific to each exporter

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

M	source/blender/editors/io/intern/obj.cpp
M	source/blender/editors/io/intern/stl.cpp
M	source/blender/editors/io/io_common.c
M	source/blender/editors/io/io_common.h
M	source/blender/editors/io/io_obj.c
M	source/blender/editors/io/io_obj.h
M	source/blender/editors/io/io_stl.c
M	source/blender/editors/io/io_stl.h

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

diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj.cpp
index be1e6fe9bc8..61a19528a2e 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -35,6 +35,7 @@ extern "C" {
 
 #include "obj.h"
 #include "../io_common.h"
+#include "../io_obj.h"
 }
 
 #include <array>
@@ -143,7 +144,8 @@ bool OBJ_export_materials(bContext *C,
 
     ss << (mat->id.name + 2) << '"';
   }
-  ss << "], '" << path_reference_mode[settings->path_mode].identifier << "')";
+  ss << "], '" << path_reference_mode[((OBJExportSettings *)settings->extra)->path_mode].identifier
+     << "')";
   std::cerr << "Running '" << ss.str() << "'\n";
   return BPY_execute_string(C, imports, ss.str().c_str());
 #else
@@ -251,9 +253,11 @@ bool OBJ_export_mesh(bContext *UNUSED(C),
   if (mesh->totvert == 0)
     return true;
 
-  if (settings->export_objects_as_objects || settings->export_objects_as_groups) {
+  const OBJExportSettings *extra = (OBJExportSettings *)settings->extra;
+
+  if (extra->export_objects_as_objects || extra->export_objects_as_groups) {
     std::string name = common::get_object_name(eob, mesh);
-    if (settings->export_objects_as_objects)
+    if (extra->export_objects_as_objects)
       fprintf(file, "o %s\n", name.c_str());
     else
       fprintf(file, "g %s\n", name.c_str());
@@ -267,7 +271,7 @@ bool OBJ_export_mesh(bContext *UNUSED(C),
 
   if (settings->export_uvs) {
     // TODO someone Is T47010 still relevant?
-    if (settings->dedup_uvs)
+    if (extra->dedup_uvs)
       for (const std::array<float, 2> &uv :
            common::deduplicated_uv_iter(mesh, uv_total, uv_mapping_pair))
         fprintf(file, "vt %.6g %.6g\n", uv[0], uv[1]);
@@ -280,7 +284,7 @@ bool OBJ_export_mesh(bContext *UNUSED(C),
   }
 
   if (settings->export_normals) {
-    if (settings->dedup_normals)
+    if (extra->dedup_normals)
       for (const std::array<float, 3> &no :
            common::deduplicated_normal_iter{mesh, no_total, no_mapping_pair})
         fprintf(file, "vn %.4g %.4g %.4g\n", no[0], no[1], no[2]);
@@ -305,13 +309,13 @@ bool OBJ_export_mesh(bContext *UNUSED(C),
       ulong uv = 0;
       ulong no = 0;
       if (settings->export_uvs) {
-        if (settings->dedup_uvs)
+        if (extra->dedup_uvs)
           uv = uv_mapping[uv_initial_count + li]->second;
         else
           uv = uv_initial_count + li;
       }
       if (settings->export_normals) {
-        if (settings->dedup_normals)
+        if (extra->dedup_normals)
           no = no_mapping[no_initial_count + l.v]->second;
         else
           no = no_initial_count + l.v;
@@ -392,9 +396,11 @@ void OBJ_export_start(bContext *C, ExportSettings *const settings)
 {
   common::export_start(C, settings);
 
+  const OBJExportSettings *extra = (OBJExportSettings *)settings->extra;
+
   // If not exporting animations, the start and end are the same
-  for (int frame = settings->start_frame; frame <= settings->end_frame; ++frame) {
-    std::FILE *obj_file = get_file(settings->filepath, ".obj", settings->export_animations, frame);
+  for (int frame = extra->start_frame; frame <= extra->end_frame; ++frame) {
+    std::FILE *obj_file = get_file(settings->filepath, ".obj", extra->export_animations, frame);
     if (obj_file == nullptr)
       return;
 
@@ -406,10 +412,10 @@ void OBJ_export_start(bContext *C, ExportSettings *const settings)
     ulong vertex_total = 0, uv_total = 0, no_total = 0;
 
     /* clang-format off */
-    auto uv_mapping_pair = common::make_deduplicate_set<uv_key_t>(settings->dedup_uvs_threshold);
-    auto no_mapping_pair = common::make_deduplicate_set<no_key_t>(settings->dedup_normals_threshold);
+    auto uv_mapping_pair = common::make_deduplicate_set<uv_key_t>(extra->dedup_uvs_threshold);
+    auto no_mapping_pair = common::make_deduplicate_set<no_key_t>(extra->dedup_normals_threshold);
 
-    std::string mtl_path = get_path(settings->filepath, ".mtl", settings->export_animations, frame);
+    std::string mtl_path = get_path(settings->filepath, ".mtl", extra->export_animations, frame);
     std::set<const Material *> materials;
     /* clang-format on */
 
diff --git a/source/blender/editors/io/intern/stl.cpp b/source/blender/editors/io/intern/stl.cpp
index 3a20be71fb9..5d5f53fb361 100644
--- a/source/blender/editors/io/intern/stl.cpp
+++ b/source/blender/editors/io/intern/stl.cpp
@@ -40,6 +40,7 @@ extern "C" {
 
 #include "stl.h"
 #include "../io_common.h"
+#include "../io_stl.h"
 }
 
 #include <chrono>
@@ -125,7 +126,7 @@ void STL_export_start(bContext *C, ExportSettings *const settings)
     Mesh *mesh;
     settings->triangulate = true;  // STL only really works with triangles
     bool needs_free = common::get_final_mesh(settings, escene, ob, &mesh);
-    if (settings->use_ascii) {
+    if (((STLExportSettings *)settings->extra)->use_ascii) {
       if (!STL_export_mesh_ascii(C, settings, fs, ob, mesh))
         return;
     }
diff --git a/source/blender/editors/io/io_common.c b/source/blender/editors/io/io_common.c
index f00836c0434..0c83affed44 100644
--- a/source/blender/editors/io/io_common.c
+++ b/source/blender/editors/io/io_common.c
@@ -26,7 +26,7 @@
 #include "UI_resources.h"
 
 /* clang-format off */
-extern const EnumPropertyItem axis_remap[] =
+const EnumPropertyItem axis_remap[] =
   {{AXIS_X,     "AXIS_X",     ICON_NONE, "X axis",  ""},
    {AXIS_Y,     "AXIS_Y",     ICON_NONE, "Y axis",  ""},
    {AXIS_Z,     "AXIS_Z",     ICON_NONE, "Z axis",  ""},
@@ -35,7 +35,7 @@ extern const EnumPropertyItem axis_remap[] =
    {AXIS_NEG_Z, "AXIS_NEG_Z", ICON_NONE, "-Z axis", ""},
    {0,          NULL,         0,         NULL,      NULL}};
 
-extern const EnumPropertyItem path_reference_mode[] = {
+const EnumPropertyItem path_reference_mode[] = {
     {AUTO,     "AUTO",     ICON_NONE, "Auto",       "Use Relative paths with subdirectories only"},
     {ABSOLUTE, "ABSOLUTE", ICON_NONE, "Absolute",   "Always write absolute paths"},
     {RELATIVE, "RELATIVE", ICON_NONE, "Relative",   "Always write relative paths (where possible)"},
@@ -47,7 +47,7 @@ extern const EnumPropertyItem path_reference_mode[] = {
 
 void io_common_default_declare_export(struct wmOperatorType *ot, eFileSel_File_Types file_type)
 {
-
+  // Defines "filepath"
   WM_operator_properties_filesel(ot,
                                  FILE_TYPE_FOLDER | file_type,
                                  FILE_BLENDER,
@@ -56,6 +56,19 @@ void io_common_default_declare_export(struct wmOperatorType *ot, eFileSel_File_T
                                  FILE_DEFAULTDISPLAY,
                                  FILE_SORT_ALPHA);
 
+  RNA_def_enum(ot->srna,
+               "axis_forward",
+               axis_remap,
+               AXIS_NEG_Z,  // From orientation helper, not sure why
+               "Forward",
+               "The axis to remap the forward axis to");
+  RNA_def_enum(ot->srna,
+               "axis_up",
+               axis_remap,
+               AXIS_Y,  // From orientation helper, not sure why
+               "Up",
+               "The axis to remap the up axis to");
+
   RNA_def_boolean(
       ot->srna, "selected_only", 0, "Selected Objects Only", "Export only selected objects");
 
@@ -71,152 +84,6 @@ void io_common_default_declare_export(struct wmOperatorType *ot, eFileSel_File_T
                   "Renderable Objects Only",
                   "Export only objects marked renderable in the outliner");
 
-  RNA_def_int(ot->srna,
-              "start_frame",
-              INT_MIN,
-              INT_MIN,
-              INT_MAX,
-              "Start Frame",
-              "Start frame of the export, use the default value to "
-              "take the start frame of the current scene",
-              INT_MIN,
-              INT_MAX);
-
-  RNA_def_int(ot->srna,
-              "end_frame",
-              INT_MIN,
-              INT_MIN,
-              INT_MAX,
-              "End Frame",
-              "End frame of the export, use the default value to "
-              "take the end frame of the current scene",
-              INT_MIN,
-              INT_MAX);
-
-  RNA_def_int(ot->srna,
-              "xsamples",
-              1,
-              1,
-              128,
-              "Transform Samples",
-              "Number of times per frame transformations are sampled",
-              1,
-              128);
-
-  RNA_def_int(ot->srna,
-              "gsamples",
-              1,
-              1,
-              128,
-              "Geometry Samples",
-              "Number of times per frame object data are sampled",
-              1,
-              128);
-
-  RNA_def_float(ot->srna,
-                "sh_open",
-                0.0f,
-                -1.0f,
-                1.0f,
-                "Shutter Open",
-                "Time at which the shutter is open",
-                -1.0f,
-                1.0f);
-
-  RNA_def_float(ot->srna,
-                "sh_close",
-                1.0f,
-                -1.0f,
-                1.0f,
-                "Shutter Close",
-                "Time at which the shutter is closed",
-                -1.0f,
-                1.0f);
-
-  RNA_def_boolean(ot->srna,
-                  "flatten_hierarchy",
-                  0,
-                  "Flatten Hierarchy",
-                  "Do not preserve objects' parent/children relationship");
-
-  RNA_def_boolean(ot->srna, "export_animations", 0, "Animations", "Export animations");
-
-  RNA_def_boolean(ot->srna, "export_normals", 1, "Normals", "Export normals");
-
-  RNA_def_boolean(ot->srna,
-                  "dedup_normals",
-                  1,
-                  "Deduplicate Normals",
-                  "Remove duplicate normals");  // TODO someone add a threshold
-
-  // The UI seems to make it so the minimum softlimit can't be smaller than 0.001,
-  // but normals are only printed with four decimal places, so it doesn't matter too much
-  RNA_def_float(ot->srna,
-                "dedup_normals_threshold",
-                0.001,
-                FLT_MIN,
-                FLT_MAX,
-                "Threshold for deduplication of Normals",
-                "The minimum difference so two Normals are considered different",


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list