[Bf-blender-cvs] [85ab8eaa888] soc-2020-io-performance: Put the blender file basename in comment in the header of the .mtl file.

Howard Trickey noreply at git.blender.org
Sat Mar 20 20:58:05 CET 2021


Commit: 85ab8eaa888c59953123bee168f5102a249169aa
Author: Howard Trickey
Date:   Sat Mar 20 15:57:13 2021 -0400
Branches: soc-2020-io-performance
https://developer.blender.org/rB85ab8eaa888c59953123bee168f5102a249169aa

Put the blender file basename in comment in the header of the .mtl file.

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

M	source/blender/editors/io/io_obj.c
M	source/blender/io/wavefront_obj/IO_wavefront_obj.h
M	source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh
M	source/blender/io/wavefront_obj/exporter/obj_exporter.cc
M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh

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

diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index fbf4425c09e..e97770b93f6 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -105,6 +105,7 @@ 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.blen_filepath = CTX_data_main(C)->name;
   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");
diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
index 2b28efd6e1f..49ca6a754da 100644
--- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h
+++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h
@@ -55,6 +55,9 @@ struct OBJExportParams {
   /** Full path to the destination .OBJ file. */
   char filepath[FILE_MAX];
 
+  /** Full path to current blender file (used for comments in output). */
+  const char *blen_filepath;
+
   /** Whether multiple frames should be exported. */
   bool export_animation;
   /** The first frame to be exported. */
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
index a79166b3d66..7566c16e53f 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc
@@ -25,6 +25,8 @@
 
 #include "BKE_blender_version.h"
 
+#include "BLI_path_util.h"
+
 #include "obj_export_mesh.hh"
 #include "obj_export_mtl.hh"
 #include "obj_export_nurbs.hh"
@@ -476,11 +478,14 @@ MTLWriter::MTLWriter(const char *obj_filepath) noexcept(false)
   std::cout << "Material Library created at: " << mtl_filepath_ << std::endl;
 }
 
-void MTLWriter::write_header() const
+void MTLWriter::write_header(const char *blen_filepath) const
 {
   using namespace std::string_literals;
+  const char *blen_basename = (blen_filepath && blen_filepath[0] != '\0') ?
+                                  BLI_path_basename(blen_filepath) :
+                                  "None";
   file_handler_->write<eMTLSyntaxElement::string>("# Blender "s + BKE_blender_version_string() +
-                                                  "\n");
+                                                  " MTL File: '" + blen_basename + "'\n");
   file_handler_->write<eMTLSyntaxElement::string>("# www.blender.org\n");
 }
 
diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh
index b882a28bd0f..61997f99cb0 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh
@@ -116,7 +116,7 @@ class MTLWriter : NonMovable, NonCopyable {
  public:
   MTLWriter(const char *obj_filepath) noexcept(false);
 
-  void write_header() const;
+  void write_header(const char *blen_filepath) const;
   StringRefNull mtl_file_path() const;
   void append_materials(const OBJMesh &mesh_to_export);
 
diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
index 28d9c97d30b..7cab0d49c08 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
@@ -160,7 +160,7 @@ static void write_mesh_objects(Vector<std::unique_ptr<OBJMesh>> exportable_as_me
       print_exception_error(ex);
     }
     if (mtl_writer) {
-      mtl_writer->write_header();
+      mtl_writer->write_header(export_params.blen_filepath);
       obj_writer.write_mtllib_name(mtl_writer->mtl_file_path());
     }
   }
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
index d5ed833757a..e91d93fcaf9 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh
@@ -77,6 +77,7 @@ struct OBJExportParamsDefault {
   OBJExportParamsDefault()
   {
     params.filepath[0] = '\0';
+    params.blen_filepath = '\0';
     params.export_animation = false;
     params.start_frame = 0;
     params.end_frame = 1;



More information about the Bf-blender-cvs mailing list