[Bf-blender-cvs] [34143e45104] master: Fix T70070: Path always absolute when importing Alembic

Sybren A. Stüvel noreply at git.blender.org
Thu Sep 19 15:55:35 CEST 2019


Commit: 34143e45104b296ece09c646ea3fb0d8bb24c519
Author: Sybren A. Stüvel
Date:   Thu Sep 19 15:55:03 2019 +0200
Branches: master
https://developer.blender.org/rB34143e45104b296ece09c646ea3fb0d8bb24c519

Fix T70070: Path always absolute when importing Alembic

Importing an Alembic file with a relative path is now also possible.

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

M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/abc_archive.cc
M	source/blender/alembic/intern/abc_archive.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/editors/io/io_alembic.c

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

diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h
index 696e0ff1810..7c5efaf309d 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -27,6 +27,7 @@ extern "C" {
 
 struct CacheReader;
 struct ListBase;
+struct Main;
 struct Mesh;
 struct Object;
 struct Scene;
@@ -103,7 +104,9 @@ bool ABC_import(struct bContext *C,
                 bool validate_meshes,
                 bool as_background_job);
 
-AbcArchiveHandle *ABC_create_handle(const char *filename, struct ListBase *object_paths);
+AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
+                                    const char *filename,
+                                    struct ListBase *object_paths);
 
 void ABC_free_handle(AbcArchiveHandle *handle);
 
diff --git a/source/blender/alembic/intern/abc_archive.cc b/source/blender/alembic/intern/abc_archive.cc
index c4252d20d48..08aa02977f4 100644
--- a/source/blender/alembic/intern/abc_archive.cc
+++ b/source/blender/alembic/intern/abc_archive.cc
@@ -24,6 +24,10 @@
 #include "abc_archive.h"
 extern "C" {
 #include "BKE_blender_version.h"
+#include "BKE_main.h"
+
+#include "BLI_path_util.h"
+#include "BLI_string.h"
 }
 
 #ifdef WIN32
@@ -95,20 +99,24 @@ static IArchive open_archive(const std::string &filename,
   return IArchive();
 }
 
-ArchiveReader::ArchiveReader(const char *filename)
+ArchiveReader::ArchiveReader(struct Main *bmain, const char *filename)
 {
+  char abs_filename[FILE_MAX];
+  BLI_strncpy(abs_filename, filename, FILE_MAX);
+  BLI_path_abs(abs_filename, BKE_main_blendfile_path(bmain));
+
 #ifdef WIN32
-  UTF16_ENCODE(filename);
+  UTF16_ENCODE(abs_filename);
   std::wstring wstr(filename_16);
   m_infile.open(wstr.c_str(), std::ios::in | std::ios::binary);
-  UTF16_UN_ENCODE(filename);
+  UTF16_UN_ENCODE(abs_filename);
 #else
-  m_infile.open(filename, std::ios::in | std::ios::binary);
+  m_infile.open(abs_filename, std::ios::in | std::ios::binary);
 #endif
 
   m_streams.push_back(&m_infile);
 
-  m_archive = open_archive(filename, m_streams, m_is_hdf5);
+  m_archive = open_archive(abs_filename, m_streams, m_is_hdf5);
 
   /* We can't open an HDF5 file from a stream, so close it. */
   if (m_is_hdf5) {
diff --git a/source/blender/alembic/intern/abc_archive.h b/source/blender/alembic/intern/abc_archive.h
index 343a8112aa2..a64de742cdf 100644
--- a/source/blender/alembic/intern/abc_archive.h
+++ b/source/blender/alembic/intern/abc_archive.h
@@ -34,6 +34,8 @@
 
 #include <fstream>
 
+struct Main;
+
 /* Wrappers around input and output archives. The goal is to be able to use
  * streams so that unicode paths work on Windows (T49112), and to make sure that
  * the stream objects remain valid as long as the archives are open.
@@ -46,7 +48,7 @@ class ArchiveReader {
   bool m_is_hdf5;
 
  public:
-  explicit ArchiveReader(const char *filename);
+  ArchiveReader(struct Main *bmain, const char *filename);
 
   bool valid() const;
 
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 98e5477f2b2..1034c5b319f 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -173,9 +173,11 @@ static bool gather_objects_paths(const IObject &object, ListBase *object_paths)
   return parent_is_part_of_this_object;
 }
 
-AbcArchiveHandle *ABC_create_handle(const char *filename, ListBase *object_paths)
+AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
+                                    const char *filename,
+                                    ListBase *object_paths)
 {
-  ArchiveReader *archive = new ArchiveReader(filename);
+  ArchiveReader *archive = new ArchiveReader(bmain, filename);
 
   if (!archive->valid()) {
     delete archive;
@@ -650,7 +652,7 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa
 
   WM_set_locked_interface(data->wm, true);
 
-  ArchiveReader *archive = new ArchiveReader(data->filename);
+  ArchiveReader *archive = new ArchiveReader(data->bmain, data->filename);
 
   if (!archive->valid()) {
 #ifndef WITH_ALEMBIC_HDF5
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 2d6256f12e2..3b0f4d9c2aa 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -246,7 +246,7 @@ void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file
   BLI_freelistN(&cache_file->object_paths);
 
 #ifdef WITH_ALEMBIC
-  cache_file->handle = ABC_create_handle(filepath, &cache_file->object_paths);
+  cache_file->handle = ABC_create_handle(bmain, filepath, &cache_file->object_paths);
   BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
 #endif
 
diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index aac4da12658..573dfcde88a 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -603,6 +603,9 @@ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
   row = uiLayoutRow(box, false);
   uiItemL(row, IFACE_("Options:"), ICON_NONE);
 
+  row = uiLayoutRow(box, false);
+  uiItemR(row, imfptr, "relative_path", 0, NULL, ICON_NONE);
+
   row = uiLayoutRow(box, false);
   uiItemR(row, imfptr, "set_frame_range", 0, NULL, ICON_NONE);
 
@@ -691,7 +694,7 @@ void WM_OT_alembic_import(wmOperatorType *ot)
                                  FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC,
                                  FILE_BLENDER,
                                  FILE_SAVE,
-                                 WM_FILESEL_FILEPATH,
+                                 WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
                                  FILE_DEFAULTDISPLAY,
                                  FILE_SORT_ALPHA);



More information about the Bf-blender-cvs mailing list