Fix T70070: Path always absolute when importing Alembic
authorSybren A. Stüvel <sybren@blender.org>
Thu, 19 Sep 2019 13:55:03 +0000 (15:55 +0200)
committerSybren A. Stüvel <sybren@blender.org>
Thu, 19 Sep 2019 13:55:19 +0000 (15:55 +0200)
Importing an Alembic file with a relative path is now also possible.

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

index 696e0ff1810bc474ccf62ce07d5fa8cdfe2efce7..7c5efaf309dd3a4a8b9282920c547938e778889b 100644 (file)
@@ -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);
 
index c4252d20d48c2de27f28f8ab1976304d648a6573..08aa02977f4f8f79af94e10f52dd4db6bb164dae 100644 (file)
 #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) {
index 343a8112aa20d05729809965cb22027fe03261d0..a64de742cdff4c293204b2c74e24d9a94ed8716e 100644 (file)
@@ -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;
 
index 98e5477f2b2eac375706bb285a1a7995398a143f..1034c5b319f7d0e1feb582ded2b02f899e9dfb20 100644 (file)
@@ -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
index 2d6256f12e2d41b5a353c2ff3d6626444362489d..3b0f4d9c2aa8ca184292b7d55cba215c9c872c41 100644 (file)
@@ -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
 
index aac4da12658afa9b95abbc430281173b114c7769..573dfcde88ad47bc600d642591d68c4d10f32c4a 100644 (file)
@@ -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);