Alembic: clean up exporter metadata code

The Alembic file metadata object was created in one place, a bit of
metadata was added, then it was passed along with other properties which
were then injected as metadata in another function. This is now cleaned up.

No functional changes.
This commit is contained in:
Sybren A. Stüvel
2019-11-19 12:45:43 +01:00
parent dfdbb237bb
commit 66bec8c25d
3 changed files with 26 additions and 28 deletions

View File

@@ -28,6 +28,8 @@ extern "C" {
#include "BLI_path_util.h" #include "BLI_path_util.h"
#include "BLI_string.h" #include "BLI_string.h"
#include "DNA_scene_types.h"
} }
#ifdef WIN32 #ifdef WIN32
@@ -147,12 +149,15 @@ Alembic::Abc::IObject ArchiveReader::getTop()
static OArchive create_archive(std::ostream *ostream, static OArchive create_archive(std::ostream *ostream,
const std::string &filename, const std::string &filename,
const std::string &scene_name, const std::string &scene_name,
Alembic::Abc::MetaData &md, double scene_fps,
bool ogawa) bool ogawa)
{ {
md.set(Alembic::Abc::kApplicationNameKey, "Blender"); Alembic::Abc::MetaData abc_metadata;
md.set(Alembic::Abc::kUserDescriptionKey, scene_name);
md.set("blender_version", versionstr); abc_metadata.set(Alembic::Abc::kApplicationNameKey, "Blender");
abc_metadata.set(Alembic::Abc::kUserDescriptionKey, scene_name);
abc_metadata.set("blender_version", versionstr);
abc_metadata.set("FramesPerTimeUnit", std::to_string(scene_fps));
time_t raw_time; time_t raw_time;
time(&raw_time); time(&raw_time);
@@ -169,13 +174,13 @@ static OArchive create_archive(std::ostream *ostream,
buffer[buffer_len - 1] = '\0'; buffer[buffer_len - 1] = '\0';
} }
md.set(Alembic::Abc::kDateWrittenKey, buffer); abc_metadata.set(Alembic::Abc::kDateWrittenKey, buffer);
ErrorHandler::Policy policy = ErrorHandler::kThrowPolicy; ErrorHandler::Policy policy = ErrorHandler::kThrowPolicy;
#ifdef WITH_ALEMBIC_HDF5 #ifdef WITH_ALEMBIC_HDF5
if (!ogawa) { if (!ogawa) {
return OArchive(Alembic::AbcCoreHDF5::WriteArchive(), filename, md, policy); return OArchive(Alembic::AbcCoreHDF5::WriteArchive(), filename, abc_metadata, policy);
} }
#else #else
static_cast<void>(filename); static_cast<void>(filename);
@@ -183,13 +188,13 @@ static OArchive create_archive(std::ostream *ostream,
#endif #endif
Alembic::AbcCoreOgawa::WriteArchive archive_writer; Alembic::AbcCoreOgawa::WriteArchive archive_writer;
return OArchive(archive_writer(ostream, md), kWrapExisting, policy); return OArchive(archive_writer(ostream, abc_metadata), kWrapExisting, policy);
} }
ArchiveWriter::ArchiveWriter(const char *filename, ArchiveWriter::ArchiveWriter(const char *filename,
const char *scene, const std::string &abc_scene_name,
bool do_ogawa, const Scene *scene,
Alembic::Abc::MetaData &md) bool do_ogawa)
{ {
/* Use stream to support unicode character paths on Windows. */ /* Use stream to support unicode character paths on Windows. */
if (do_ogawa) { if (do_ogawa) {
@@ -203,7 +208,7 @@ ArchiveWriter::ArchiveWriter(const char *filename,
#endif #endif
} }
m_archive = create_archive(&m_outfile, filename, scene, md, do_ogawa); m_archive = create_archive(&m_outfile, filename, abc_scene_name, FPS, do_ogawa);
} }
OArchive &ArchiveWriter::archive() OArchive &ArchiveWriter::archive()

View File

@@ -35,6 +35,7 @@
#include <fstream> #include <fstream>
struct Main; struct Main;
struct Scene;
/* 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
@@ -68,10 +69,10 @@ class ArchiveWriter {
Alembic::Abc::OArchive m_archive; Alembic::Abc::OArchive m_archive;
public: public:
explicit ArchiveWriter(const char *filename, ArchiveWriter(const char *filename,
const char *scene, const std::string &abc_scene_name,
bool do_ogawa, const Scene *scene,
Alembic::Abc::MetaData &md); bool do_ogawa);
Alembic::Abc::OArchive &archive(); Alembic::Abc::OArchive &archive();
}; };

View File

@@ -266,27 +266,19 @@ void AbcExporter::getFrameSet(unsigned int nr_of_samples, std::set<double> &fram
void AbcExporter::operator()(short *do_update, float *progress, bool *was_canceled) void AbcExporter::operator()(short *do_update, float *progress, bool *was_canceled)
{ {
std::string scene_name; std::string abc_scene_name;
if (m_bmain->name[0] != '\0') { if (m_bmain->name[0] != '\0') {
char scene_file_name[FILE_MAX]; char scene_file_name[FILE_MAX];
BLI_strncpy(scene_file_name, m_bmain->name, FILE_MAX); BLI_strncpy(scene_file_name, m_bmain->name, FILE_MAX);
scene_name = scene_file_name; abc_scene_name = scene_file_name;
} }
else { else {
scene_name = "untitled"; abc_scene_name = "untitled";
} }
Scene *scene = m_settings.scene; m_writer = new ArchiveWriter(
const double fps = FPS; m_filename, abc_scene_name, m_settings.scene, m_settings.export_ogawa);
char buf[16];
snprintf(buf, 15, "%f", fps);
const std::string str_fps = buf;
Alembic::AbcCoreAbstract::MetaData md;
md.set("FramesPerTimeUnit", str_fps);
m_writer = new ArchiveWriter(m_filename, scene_name.c_str(), m_settings.export_ogawa, md);
/* Create time samplings for transforms and shapes. */ /* Create time samplings for transforms and shapes. */