Commit: 613343447861eae1aef90786802bac28a1adaea6
Author: Aras Pranckevicius
Date:   Wed Sep 7 17:56:06 2022 +0300
Branches: blender-v3.3-release
https://developer.blender.org/rB613343447861eae1aef90786802bac28a1adaea6

Fix T100669: OBJ exporter does not properly export image sequence texture names

When exporting OBJ/MTL animation, texture file paths of image
sequences were not adjusted to contain the correct frame number.
Fixes T100669.

Also, the OBJ exporter was wrongly writing to the same .mtl file
for each exported frame, which is a regression compared to the
legacy Python exporter.

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

M       source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc
M       source/blender/io/wavefront_obj/exporter/obj_exporter.cc

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

diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc 
b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc
index 4ed148ec64e..2a6311d15db 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc
@@ -111,28 +111,41 @@ static const bNode *get_node_of_type(Span<const 
nodes::OutputSocketRef *> socket
   return nullptr;
 }
 
-/**
+/*
  * From a texture image shader node, get the image's filepath.
  * If packed image is found, only the file "name" is returned.
  */
-static const char *get_image_filepath(const bNode *tex_node)
+static std::string get_image_filepath(const bNode *tex_node)
 {
   if (!tex_node) {
-    return nullptr;
+    return "";
   }
   Image *tex_image = reinterpret_cast<Image *>(tex_node->id);
   if (!tex_image || !BKE_image_has_filepath(tex_image)) {
-    return nullptr;
+    return "";
   }
-  const char *path = tex_image->filepath;
+
   if (BKE_image_has_packedfile(tex_image)) {
     /* Put image in the same directory as the .MTL file. */
-    path = BLI_path_slash_rfind(path) + 1;
+    const char *filename = BLI_path_slash_rfind(tex_image->filepath) + 1;
     fprintf(stderr,
             "Packed image found:'%s'. Unpack and place the image in the same "
             "directory as the .MTL file.\n",
-            path);
+            filename);
+    return filename;
   }
+
+  char path[FILE_MAX];
+  BLI_strncpy(path, tex_image->filepath, FILE_MAX);
+
+  if (tex_image->source == IMA_SRC_SEQUENCE) {
+    char head[FILE_MAX], tail[FILE_MAX];
+    unsigned short numlen;
+    int framenr = static_cast<NodeTexImage 
*>(tex_node->storage)->iuser.framenr;
+    BLI_path_sequence_decode(path, head, tail, &numlen);
+    BLI_path_sequence_encode(path, head, tail, numlen, framenr);
+  }
+
   return path;
 }
 
@@ -302,8 +315,8 @@ static void store_image_textures(const nodes::NodeRef 
*bsdf_node,
     if (!tex_node) {
       continue;
     }
-    const char *tex_image_filepath = get_image_filepath(tex_node);
-    if (!tex_image_filepath) {
+    const std::string tex_image_filepath = get_image_filepath(tex_node);
+    if (tex_image_filepath.empty()) {
       continue;
     }
 
diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc 
b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
index 77d4f6268bc..421e814a0a6 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
@@ -268,7 +268,7 @@ void export_frame(Depsgraph *depsgraph, const 
OBJExportParams &export_params, co
   std::unique_ptr<MTLWriter> mtl_writer = nullptr;
   if (export_params.export_materials) {
     try {
-      mtl_writer = std::make_unique<MTLWriter>(export_params.filepath);
+      mtl_writer = std::make_unique<MTLWriter>(filepath);
     }
     catch (const std::system_error &ex) {
       print_exception_error(ex);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to