Fix T70070: Path always absolute when importing Alembic
Importing an Alembic file with a relative path is now also possible.
This commit is contained in:
parent
1353158aa2
commit
34143e4510
Notes:
blender-bot
2023-02-14 08:06:33 +01:00
Referenced by commit fb09d229dd
, Alembic: Fix compiler error on Windows
Referenced by issue #70070, Path always absolute when importing Alembic
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue