[Bf-blender-cvs] [c2305201bc6] soc-2020-io-performance: Remove the need to apply modifiers to use render properties.

Ankit Meel noreply at git.blender.org
Tue Sep 29 19:20:18 CEST 2020


Commit: c2305201bc696c1157577f48daa7b7d7a8858f91
Author: Ankit Meel
Date:   Tue Sep 29 22:11:14 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBc2305201bc696c1157577f48daa7b7d7a8858f91

Remove the need to apply modifiers to use render properties.

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

M	source/blender/editors/io/io_obj.c
M	source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
M	source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
M	source/blender/io/wavefront_obj/intern/obj_exporter.cc
M	source/blender/io/wavefront_obj/intern/obj_exporter.hh

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

diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index f1ca5263a7d..fba6889f6eb 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -72,7 +72,7 @@ const EnumPropertyItem io_obj_export_evaluation_mode[] = {
      "DAG_EVAL_RENDER",
      0,
      "Render",
-     "Apply modifiers to objects for render properties to take effect"},
+     "Export objects as they appear in render"},
     {DAG_EVAL_VIEWPORT,
      "DAG_EVAL_VIEWPORT",
      0,
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
index 51d5a9a1cbb..ff425a5e451 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.cc
@@ -32,7 +32,7 @@
 #include "obj_export_nurbs.hh"
 
 namespace blender::io::obj {
-OBJCurve::OBJCurve(Depsgraph *depsgraph,
+OBJCurve::OBJCurve(const Depsgraph *depsgraph,
                    const OBJExportParams &export_params,
                    Object *export_object)
     : export_object_eval_(export_object)
diff --git a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
index 12b40067d67..72d2c400c31 100644
--- a/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_export_nurbs.hh
@@ -42,7 +42,9 @@ class OBJCurve : NonMovable, NonCopyable {
   float world_axes_transform_[4][4];
 
  public:
-  OBJCurve(Depsgraph *depsgraph, const OBJExportParams &export_params, Object *export_object);
+  OBJCurve(const Depsgraph *depsgraph,
+           const OBJExportParams &export_params,
+           Object *export_object);
 
   const char *get_curve_name() const;
   int tot_nurbs() const;
diff --git a/source/blender/io/wavefront_obj/intern/obj_exporter.cc b/source/blender/io/wavefront_obj/intern/obj_exporter.cc
index 3896bd27d63..0c127939d97 100644
--- a/source/blender/io/wavefront_obj/intern/obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/intern/obj_exporter.cc
@@ -39,19 +39,55 @@
 #include "obj_exporter.hh"
 
 #include "obj_export_file_writer.hh"
+
 namespace blender::io::obj {
+
+OBJDepsgraph::OBJDepsgraph(const bContext *C, const eEvaluationMode eval_mode)
+{
+  Scene *scene = CTX_data_scene(C);
+  Main *bmain = CTX_data_main(C);
+  ViewLayer *view_layer = CTX_data_view_layer(C);
+  if (eval_mode == DAG_EVAL_RENDER) {
+    depsgraph_ = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
+    needs_free_ = true;
+    DEG_graph_build_for_all_objects(depsgraph_);
+    BKE_scene_graph_evaluated_ensure(depsgraph_, bmain);
+  }
+  else {
+    depsgraph_ = CTX_data_ensure_evaluated_depsgraph(C);
+    needs_free_ = false;
+  }
+}
+
+OBJDepsgraph::~OBJDepsgraph()
+{
+  if (needs_free_) {
+    DEG_graph_free(depsgraph_);
+  }
+}
+
+Depsgraph *OBJDepsgraph::get()
+{
+  return depsgraph_;
+}
+
+void OBJDepsgraph::update_for_newframe()
+{
+  BKE_scene_graph_update_for_newframe(depsgraph_);
+}
+
 /**
  * Filter `Object`s in a Scene to find supported objects, as per export settings and object types,
  * and add them to the given containers.
  *
  * \note Curves are also stored with Meshes if export settings specify so.
  */
-static void find_exportable_objects(ViewLayer *view_layer,
-                                    Depsgraph *depsgraph,
+static void find_exportable_objects(Depsgraph *depsgraph,
                                     const OBJExportParams &export_params,
                                     Vector<std::unique_ptr<OBJMesh>> &r_exportable_meshes,
                                     Vector<std::unique_ptr<OBJCurve>> &r_exportable_nurbs)
 {
+  ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
   LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
     Object *object_in_layer = base->object;
     if (export_params.export_selected_objects && !(object_in_layer->base_flag & BASE_SELECTED)) {
@@ -106,8 +142,7 @@ static void find_exportable_objects(ViewLayer *view_layer,
 /**
  * Exports a single frame to an OBJ and MTL (conditional) pair.
  */
-static void export_frame(ViewLayer *view_layer,
-                         Depsgraph *depsgraph,
+static void export_frame(Depsgraph *depsgraph,
                          const OBJExportParams &export_params,
                          const char *filepath)
 {
@@ -121,8 +156,7 @@ static void export_frame(ViewLayer *view_layer,
   Vector<std::unique_ptr<OBJMesh>> exportable_as_mesh;
   /* NURBS to be exported in parameter form. */
   Vector<std::unique_ptr<OBJCurve>> exportable_as_nurbs;
-  find_exportable_objects(
-      view_layer, depsgraph, export_params, exportable_as_mesh, exportable_as_nurbs);
+  find_exportable_objects(depsgraph, export_params, exportable_as_mesh, exportable_as_nurbs);
 
   if (export_params.export_materials) {
     mtl_writer.reset(new MTLWriter(filepath));
@@ -189,18 +223,14 @@ void exporter_main(bContext *C, const OBJExportParams &export_params)
   /* TODO(ankitm) find a better way to exit edit mode that doesn't hit assert
    * https://hastebin.com/mitihetagi in file F8653460 */
   ED_object_editmode_exit(C, EM_FREEDATA);
-  Scene *scene = CTX_data_scene(C);
-  Main *bmain = CTX_data_main(C);
-  ViewLayer *view_layer = CTX_data_view_layer(C);
-  Depsgraph *depsgraph = export_params.export_eval_mode == DAG_EVAL_RENDER ?
-                             DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER) :
-                             CTX_data_ensure_evaluated_depsgraph(C);
+  OBJDepsgraph obj_depsgraph(C, export_params.export_eval_mode);
+  Scene *scene = DEG_get_input_scene(obj_depsgraph.get());
   const char *filepath = export_params.filepath;
 
   /* Single frame export, i.e. no amimation is to be exported. */
   if (!export_params.export_animation) {
     fprintf(stderr, "Writing to %s\n", filepath);
-    export_frame(view_layer, depsgraph, export_params, filepath);
+    export_frame(obj_depsgraph.get(), export_params, filepath);
     return;
   }
 
@@ -216,9 +246,9 @@ void exporter_main(bContext *C, const OBJExportParams &export_params)
     }
 
     CFRA = frame;
-    BKE_scene_graph_update_for_newframe(depsgraph);
+    obj_depsgraph.update_for_newframe();
     fprintf(stderr, "Writing to %s\n", filepath_with_frames);
-    export_frame(view_layer, depsgraph, export_params, filepath_with_frames);
+    export_frame(obj_depsgraph.get(), export_params, filepath_with_frames);
   }
   CFRA = original_frame;
 }
diff --git a/source/blender/io/wavefront_obj/intern/obj_exporter.hh b/source/blender/io/wavefront_obj/intern/obj_exporter.hh
index f214acebd74..f602ffcf057 100644
--- a/source/blender/io/wavefront_obj/intern/obj_exporter.hh
+++ b/source/blender/io/wavefront_obj/intern/obj_exporter.hh
@@ -28,6 +28,23 @@
 #include "IO_wavefront_obj.h"
 
 namespace blender::io::obj {
+/**
+ * Behaves like `std::unique_ptr<Depsgraph, <custom_deleter>>`.
+ * Needed to free a new Depsgraph created for `DAG_EVAL_RENDER`.
+ */
+class OBJDepsgraph {
+ private:
+  Depsgraph *depsgraph_ = nullptr;
+  bool needs_free_ = false;
+
+ public:
+  OBJDepsgraph(const bContext *C, const eEvaluationMode eval_mode);
+  ~OBJDepsgraph();
+
+  Depsgraph *get();
+  void update_for_newframe();
+};
+
 void exporter_main(bContext *C, const OBJExportParams &export_params);
 
 }  // namespace blender::io::obj



More information about the Bf-blender-cvs mailing list