[Bf-blender-cvs] [014b53304e4] soc-2019-fast-io: [Fast import/export] Added boiler plate for OBJ importing

Hugo Sales noreply at git.blender.org
Sun Jul 21 02:37:25 CEST 2019


Commit: 014b53304e43cdecc9f95f82f5b58926897237df
Author: Hugo Sales
Date:   Tue Jul 16 16:24:38 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rB014b53304e43cdecc9f95f82f5b58926897237df

[Fast import/export] Added boiler plate for OBJ importing

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

M	source/blender/editors/io/CMakeLists.txt
M	source/blender/editors/io/intern/common.cpp
M	source/blender/editors/io/intern/common.hpp
M	source/blender/editors/io/intern/obj.h
R099	source/blender/editors/io/intern/obj.cpp	source/blender/editors/io/intern/obj_export.cpp
A	source/blender/editors/io/intern/obj_import.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

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

diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index a7f6d77dfc4..3538d5ea746 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -52,7 +52,8 @@ set(SRC
   io_obj.h
   io_stl.h
 
-  intern/obj.cpp
+  intern/obj_export.cpp
+  intern/obj_import.cpp
   intern/obj.h
   intern/stl.cpp
   intern/stl.h
diff --git a/source/blender/editors/io/intern/common.cpp b/source/blender/editors/io/intern/common.cpp
index bed96c4b5d3..484c5365d29 100644
--- a/source/blender/editors/io/intern/common.cpp
+++ b/source/blender/editors/io/intern/common.cpp
@@ -264,20 +264,21 @@ bool export_end(bContext *UNUSED(C), ExportSettings *const settings)
   return true;
 }
 
-bool time_export(bContext *C,
-                 ExportSettings *const settings,
-                 void (*start)(bContext *C, ExportSettings *const settings),
-                 bool (*end)(bContext *C, ExportSettings *const settings))
+void import_start(bContext *UNUSED(C), ImportSettings *const settings)
 {
-  auto f = std::chrono::steady_clock::now();
-  start(C, settings);
-  auto ret = end(C, settings);
-  std::cout << "Took "
-            << std::chrono::duration_cast<std::chrono::milliseconds>(
-                   std::chrono::steady_clock::now() - f)
-                   .count()
-            << "ms\n";
-  return ret;
+  G.is_rendering = true;
+  BKE_spacedata_draw_locks(true);
+}
+
+bool import_end(bContext *UNUSED(C), ImportSettings *const settings)
+{
+  G.is_rendering = false;
+  BKE_spacedata_draw_locks(false);
+  DEG_graph_free(settings->depsgraph);
+  if (settings->format_specific)
+    MEM_freeN(settings->format_specific);
+  MEM_freeN(settings);
+  return true;
 }
 
 const std::array<float, 3> calculate_normal(const Mesh *const mesh, const MPoly &mp)
diff --git a/source/blender/editors/io/intern/common.hpp b/source/blender/editors/io/intern/common.hpp
index ed2ad4a9a27..cbd6e416ce1 100644
--- a/source/blender/editors/io/intern/common.hpp
+++ b/source/blender/editors/io/intern/common.hpp
@@ -82,6 +82,9 @@ float get_unit_scale(const Scene *const scene);
 void export_start(bContext *C, ExportSettings *const settings);
 bool export_end(bContext *C, ExportSettings *const settings);
 
+void import_start(bContext *C, ImportSettings *const settings);
+bool import_end(bContext *C, ImportSettings *const settings);
+
 // Execute `start` and `end` and time it. Those functions should be
 // specific to each exportter, but have the same signature as the two above
 bool time_export(bContext *C,
@@ -106,6 +109,20 @@ template<typename T> std::string get_object_name(const Object *const ob, const T
   return name;
 }
 
+template<typename Start, typename End, typename Settings>
+bool time(bContext *C, Settings *const settings, Start start, End end)
+{
+  auto f = std::chrono::steady_clock::now();
+  start(C, settings);
+  auto ret = end(C, settings);
+  std::cout << "Took "
+            << std::chrono::duration_cast<std::chrono::milliseconds>(
+                   std::chrono::steady_clock::now() - f)
+                   .count()
+            << "ms\n";
+  return ret;
+}
+
 // --- Deduplication ---
 // TODO someone How to properly compare similarity of vectors?
 struct threshold_comparator {
diff --git a/source/blender/editors/io/intern/obj.h b/source/blender/editors/io/intern/obj.h
index 052ce5df93b..e1b65ad4089 100644
--- a/source/blender/editors/io/intern/obj.h
+++ b/source/blender/editors/io/intern/obj.h
@@ -33,6 +33,7 @@ extern "C" {
 struct bContext;
 
 bool OBJ_export(bContext *C, ExportSettings *const settings);
+bool OBJ_import(bContext *C, ImportSettings *const settings);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj_export.cpp
similarity index 99%
rename from source/blender/editors/io/intern/obj.cpp
rename to source/blender/editors/io/intern/obj_export.cpp
index a84826e07d9..61425344941 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj_export.cpp
@@ -506,11 +506,13 @@ bool OBJ_export_end(bContext *C, ExportSettings *const settings)
 {
   return common::export_end(C, settings);
 }
+
 }  // namespace
 
 extern "C" {
 bool OBJ_export(bContext *C, ExportSettings *const settings)
 {
-  return common::time_export(C, settings, &OBJ_export_start, &OBJ_export_end);
+  return common::time(C, settings, &OBJ_export_start, &OBJ_export_end);
 }
+
 }  // extern
diff --git a/source/blender/editors/io/intern/obj_import.cpp b/source/blender/editors/io/intern/obj_import.cpp
new file mode 100644
index 00000000000..0bed847704b
--- /dev/null
+++ b/source/blender/editors/io/intern/obj_import.cpp
@@ -0,0 +1,79 @@
+extern "C" {
+
+#include "BLI_sys_types.h"
+#include "BLI_math.h"
+#include "BLT_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
+#include "BKE_mesh_runtime.h"
+#include "BKE_scene.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_ID.h"
+#include "DNA_layer_types.h"
+#include "DNA_material_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
+#include "DNA_space_types.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#ifdef WITH_PYTHON
+#  include "BPY_extern.h"
+#endif
+
+#include "ED_object.h"
+#include "bmesh.h"
+#include "bmesh_tools.h"
+
+#include "obj.h"
+#include "../io_common.h"
+#include "../io_obj.h"
+}
+
+#include <array>
+#include <algorithm>
+#include <chrono>
+#include <cstdio>
+#include <cstring>
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include <map>
+#include <set>
+#include <sstream>
+#include <unordered_map>
+#include <vector>
+
+#include "common.hpp"
+#include "iterators.hpp"
+
+namespace {
+void OBJ_import_start(bContext *C, ImportSettings *const settings)
+{
+  common::import_start(C, settings);
+  std::cerr << "IMPORTING\n";
+}
+
+bool OBJ_import_end(bContext *C, ImportSettings *const settings)
+{
+  return common::import_end(C, settings);
+}
+}  // namespace
+
+extern "C" {
+bool OBJ_import(bContext *C, ImportSettings *const settings)
+{
+  return common::time(C, settings, &OBJ_import_start, &OBJ_import_end);
+}
+}
diff --git a/source/blender/editors/io/intern/stl.cpp b/source/blender/editors/io/intern/stl.cpp
index f25582b7884..f2ad1fc9826 100644
--- a/source/blender/editors/io/intern/stl.cpp
+++ b/source/blender/editors/io/intern/stl.cpp
@@ -148,6 +148,6 @@ bool STL_export_end(bContext *C, ExportSettings *const settings)
 extern "C" {
 bool STL_export(bContext *C, ExportSettings *const settings)
 {
-  return common::time_export(C, settings, &STL_export_start, &STL_export_end);
+  return common::time(C, settings, &STL_export_start, &STL_export_end);
 }
 }  // extern
diff --git a/source/blender/editors/io/io_common.c b/source/blender/editors/io/io_common.c
index 558d1f2ef81..84637e6ee2f 100644
--- a/source/blender/editors/io/io_common.c
+++ b/source/blender/editors/io/io_common.c
@@ -112,25 +112,51 @@ void io_common_default_declare_export(struct wmOperatorType *ot, eFileSel_File_T
                 0.0001f,
                 1000.0f);
 }
-void io_common_default_declare_import(struct wmOperatorType *ot)
+void io_common_default_declare_import(struct wmOperatorType *ot, eFileSel_File_Types file_type)
 {
+  // Defines "filepath"
+  WM_operator_properties_filesel(ot,
+                                 FILE_TYPE_FOLDER | file_type,
+                                 FILE_BLENDER,
+                                 FILE_SAVE,
+                                 WM_FILESEL_FILEPATH,
+                                 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_float(ot->srna,
+                "global_scale",
+                1.0f,
+                0.0001f,
+                1000.0f,
+                "Scale",
+                "Value by which to enlarge or shrink the objects with"
+                "respect to the world's origin",
+                0.0001f,
+                1000.0f);
 }
 
 ExportSettings *io_common_construct_default_export_settings(struct bContext *C,
                                                             struct wmOperator *op)
 {
+  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+    BKE_report(op->reports, RPT_ERROR, "No file given");
+    return NULL;
+  }
+
   ExportSettings *settings = MEM_mallocN(sizeof(ExportSettings), "ExportSettings");
 
   settings->scene = CTX_data_scene(C);
@@ -155,6 +181,29 @@ ExportSettings *io_common_construct_default_export_settings(struct bContext *C,
   return settings;
 }
 
+ImportSettings *io_common_construct_default_import_settings(struct bContext *C,
+                                                            struct wmOperator *op)
+{
+  if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+    BKE_report(op->reports, RPT_ERROR, "No file given");
+    return NULL;
+  }
+
+  ImportSettings *settings = MEM_mallocN(sizeof(ImportSettings), "ImportSettings");
+  settings->scene = CTX_data_scene(C);
+  settings->view_layer = CTX_data_view_layer(C);
+  settings->main = CTX_data_main(C);
+  settings->depsgraph = NULL;  // Defer building
+
+  RNA_string_get(op->ptr, "filepath", settings->filepath);
+
+  settings->axis_forward = RNA_enum_get(op->ptr, "axis_forward");
+  settings->axis_up = RNA_enum_get(op->ptr, "axis_up");
+  settings->global_scale = RNA_float_get(op->ptr, "global_scale");
+
+  return settings;
+}
+
 bool io_common_export_check(bContext *UNUSED(C), wmOperator *op, const char *ext)
 {
   char filepath[FILE_MAX];
@@ -197,16 +246,18 @@ int io_common_export_inv

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list