[Bf-blender-cvs] [9d399488710] universal-scene-description: USD export: ensure packed texture file extension.

Michael Kowalski noreply at git.blender.org
Mon Jun 6 18:29:25 CEST 2022


Commit: 9d39948871019716db24fc6bb8a87d8f9db5d5f5
Author: Michael Kowalski
Date:   Mon Jun 6 12:26:02 2022 -0400
Branches: universal-scene-description
https://developer.blender.org/rB9d39948871019716db24fc6bb8a87d8f9db5d5f5

USD export: ensure packed texture file extension.

Updated in-memory texture path generation logic to
ensure the path has a valid extension for the image
format.  Also moved duplicate code for identifying
in-memory textures into a common function.

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

M	source/blender/io/usd/intern/usd_writer_material.cc

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

diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc
index e416c8f22f3..1cbd014fb42 100644
--- a/source/blender/io/usd/intern/usd_writer_material.cc
+++ b/source/blender/io/usd/intern/usd_writer_material.cc
@@ -354,17 +354,16 @@ static void create_uvmap_shader(const USDExporterContext &usd_export_context,
   }
 }
 
+static bool is_in_memory_texture(Image *ima)
+{
+  return BKE_image_is_dirty(ima) || ima->source == IMA_SRC_GENERATED ||
+         BKE_image_has_packedfile(ima);
+}
+
 /* Generate a file name for an in-memory image that doesn't have a
  * filepath already defined. */
 static std::string get_in_memory_texture_filename(Image *ima)
 {
-  bool is_dirty = BKE_image_is_dirty(ima);
-  bool is_generated = ima->source == IMA_SRC_GENERATED;
-  bool is_packed = BKE_image_has_packedfile(ima);
-  if (!(is_generated || is_dirty || is_packed)) {
-    return "";
-  }
-
   /* Determine the correct file extension from the image format. */
   ImBuf *imbuf = BKE_image_acquire_ibuf(ima, nullptr, nullptr);
   if (!imbuf) {
@@ -375,8 +374,13 @@ static std::string get_in_memory_texture_filename(Image *ima)
   BKE_image_format_from_imbuf(&imageFormat, imbuf);
 
   char file_name[FILE_MAX];
-  /* Use the image name for the file name. */
-  strcpy(file_name, ima->id.name + 2);
+  if (strlen(ima->filepath) > 0) {
+    BLI_split_file_part(ima->filepath, file_name, FILE_MAX);
+  }
+  else {
+    /* Use the image name for the file name. */
+    strcpy(file_name, ima->id.name + 2);
+  }
 
   BKE_image_path_ensure_ext_from_imformat(file_name, &imageFormat);
 
@@ -2215,16 +2219,13 @@ std::string get_tex_image_asset_path(bNode *node,
 
   std::string path;
 
-  if (strlen(ima->filepath) > 0) {
+  if (is_in_memory_texture(ima)) {
+    path = get_in_memory_texture_filename(ima);
+  }
+  else if (strlen(ima->filepath) > 0) {
     /* Get absolute path. */
     path = get_tex_image_asset_path(ima);
   }
-  else if (export_params.export_textures) {
-    /* Image has no filepath, but since we are exporting textures,
-     * check if this is an in-memory texture for which we can
-     * generate a file name. */
-    path = get_in_memory_texture_filename(ima);
-  }
 
   return get_tex_image_asset_path(path, stage, export_params); 
 }
@@ -2407,13 +2408,9 @@ void export_texture(bNode *node,
 
   BLI_dir_create_recursive(tex_dir_path);
 
-  const bool is_dirty = BKE_image_is_dirty(ima);
-  const bool is_generated = ima->source == IMA_SRC_GENERATED;
-  const bool is_packed = BKE_image_has_packedfile(ima);
-
   std::string dest_dir(tex_dir_path);
 
-  if (is_generated || is_dirty || is_packed) {
+  if (is_in_memory_texture(ima)) {
     export_in_memory_texture(ima, dest_dir, allow_overwrite);
   }
   else if (ima->source == IMA_SRC_TILED) {



More information about the Bf-blender-cvs mailing list