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:
@@ -27,6 +27,7 @@ extern "C" {
|
|||||||
|
|
||||||
struct CacheReader;
|
struct CacheReader;
|
||||||
struct ListBase;
|
struct ListBase;
|
||||||
|
struct Main;
|
||||||
struct Mesh;
|
struct Mesh;
|
||||||
struct Object;
|
struct Object;
|
||||||
struct Scene;
|
struct Scene;
|
||||||
@@ -103,7 +104,9 @@ bool ABC_import(struct bContext *C,
|
|||||||
bool validate_meshes,
|
bool validate_meshes,
|
||||||
bool as_background_job);
|
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);
|
void ABC_free_handle(AbcArchiveHandle *handle);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
#include "abc_archive.h"
|
#include "abc_archive.h"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "BKE_blender_version.h"
|
#include "BKE_blender_version.h"
|
||||||
|
#include "BKE_main.h"
|
||||||
|
|
||||||
|
#include "BLI_path_util.h"
|
||||||
|
#include "BLI_string.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -95,20 +99,24 @@ static IArchive open_archive(const std::string &filename,
|
|||||||
return IArchive();
|
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
|
#ifdef WIN32
|
||||||
UTF16_ENCODE(filename);
|
UTF16_ENCODE(abs_filename);
|
||||||
std::wstring wstr(filename_16);
|
std::wstring wstr(filename_16);
|
||||||
m_infile.open(wstr.c_str(), std::ios::in | std::ios::binary);
|
m_infile.open(wstr.c_str(), std::ios::in | std::ios::binary);
|
||||||
UTF16_UN_ENCODE(filename);
|
UTF16_UN_ENCODE(abs_filename);
|
||||||
#else
|
#else
|
||||||
m_infile.open(filename, std::ios::in | std::ios::binary);
|
m_infile.open(abs_filename, std::ios::in | std::ios::binary);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_streams.push_back(&m_infile);
|
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. */
|
/* We can't open an HDF5 file from a stream, so close it. */
|
||||||
if (m_is_hdf5) {
|
if (m_is_hdf5) {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
struct Main;
|
||||||
|
|
||||||
/* Wrappers around input and output archives. The goal is to be able to use
|
/* 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
|
* 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.
|
* the stream objects remain valid as long as the archives are open.
|
||||||
@@ -46,7 +48,7 @@ class ArchiveReader {
|
|||||||
bool m_is_hdf5;
|
bool m_is_hdf5;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ArchiveReader(const char *filename);
|
ArchiveReader(struct Main *bmain, const char *filename);
|
||||||
|
|
||||||
bool valid() const;
|
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;
|
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()) {
|
if (!archive->valid()) {
|
||||||
delete archive;
|
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);
|
WM_set_locked_interface(data->wm, true);
|
||||||
|
|
||||||
ArchiveReader *archive = new ArchiveReader(data->filename);
|
ArchiveReader *archive = new ArchiveReader(data->bmain, data->filename);
|
||||||
|
|
||||||
if (!archive->valid()) {
|
if (!archive->valid()) {
|
||||||
#ifndef WITH_ALEMBIC_HDF5
|
#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);
|
BLI_freelistN(&cache_file->object_paths);
|
||||||
|
|
||||||
#ifdef WITH_ALEMBIC
|
#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);
|
BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -603,6 +603,9 @@ static void ui_alembic_import_settings(uiLayout *layout, PointerRNA *imfptr)
|
|||||||
row = uiLayoutRow(box, false);
|
row = uiLayoutRow(box, false);
|
||||||
uiItemL(row, IFACE_("Options:"), ICON_NONE);
|
uiItemL(row, IFACE_("Options:"), ICON_NONE);
|
||||||
|
|
||||||
|
row = uiLayoutRow(box, false);
|
||||||
|
uiItemR(row, imfptr, "relative_path", 0, NULL, ICON_NONE);
|
||||||
|
|
||||||
row = uiLayoutRow(box, false);
|
row = uiLayoutRow(box, false);
|
||||||
uiItemR(row, imfptr, "set_frame_range", 0, NULL, ICON_NONE);
|
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_TYPE_FOLDER | FILE_TYPE_ALEMBIC,
|
||||||
FILE_BLENDER,
|
FILE_BLENDER,
|
||||||
FILE_SAVE,
|
FILE_SAVE,
|
||||||
WM_FILESEL_FILEPATH,
|
WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH,
|
||||||
FILE_DEFAULTDISPLAY,
|
FILE_DEFAULTDISPLAY,
|
||||||
FILE_SORT_ALPHA);
|
FILE_SORT_ALPHA);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user