Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2016-08-25 06:19:41 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2016-08-25 06:19:41 +0300
commit3c533be77ea8f6c88b188eb870bb46ba972d1372 (patch)
tree0cb7f2906d678e9f478ff16967afadda2ca21fcb /source/blender/alembic/intern/abc_exporter.cc
parentbfc5a94292bb6044e6f95d56d896ad2231e685e7 (diff)
Fix T49112: Alembic unicode path issues on Windows.
Now we pass streams to Alembic instead of passing the filename string. That way we can open the stream ourselves with the proper unicode encoding. Note that this only applies to Ogawa archive, as HDF5 does not support streams. Differential Revision: https://developer.blender.org/D2160
Diffstat (limited to 'source/blender/alembic/intern/abc_exporter.cc')
-rw-r--r--source/blender/alembic/intern/abc_exporter.cc85
1 files changed, 68 insertions, 17 deletions
diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc
index 2e9f429f887..764b1533309 100644
--- a/source/blender/alembic/intern/abc_exporter.cc
+++ b/source/blender/alembic/intern/abc_exporter.cc
@@ -30,6 +30,10 @@
#include <Alembic/AbcCoreOgawa/All.h>
+#ifdef WIN32
+# include "utfconv.h"
+#endif
+
#include "abc_camera.h"
#include "abc_curves.h"
#include "abc_hair.h"
@@ -67,6 +71,54 @@ extern "C" {
using Alembic::Abc::TimeSamplingPtr;
using Alembic::Abc::OBox3dProperty;
+
+/* ************************************************************************** */
+
+/* This kinda duplicates CreateArchiveWithInfo, but Alembic does not seem to
+ * have a version supporting streams. */
+static Alembic::Abc::OArchive create_archive(std::ostream *ostream,
+ const std::string &filename,
+ const std::string &scene_name,
+ const Alembic::Abc::Argument &arg0,
+ const Alembic::Abc::Argument &arg1,
+ bool ogawa)
+{
+ Alembic::Abc::MetaData md = GetMetaData(arg0, arg1);
+ md.set(Alembic::Abc::kApplicationNameKey, "Blender");
+ md.set(Alembic::Abc::kUserDescriptionKey, scene_name);
+
+ time_t raw_time;
+ time(&raw_time);
+ char buffer[128];
+
+#if defined _WIN32 || defined _WIN64
+ ctime_s(buffer, 128, &raw_time);
+#else
+ ctime_r(&raw_time, buffer);
+#endif
+
+ const std::size_t buffer_len = strlen(buffer);
+ if (buffer_len > 0 && buffer[buffer_len - 1] == '\n') {
+ buffer[buffer_len - 1] = '\0';
+ }
+
+ md.set(Alembic::Abc::kDateWrittenKey, buffer);
+
+ Alembic::Abc::ErrorHandler::Policy policy = GetErrorHandlerPolicyFromArgs(arg0, arg1);
+
+#ifdef WITH_ALEMBIC_HDF5
+ if (!ogawa) {
+ return Alembic::Abc::OArchive(Alembic::AbcCoreHDF5::WriteArchive(), filename, md, policy);
+ }
+#else
+ static_cast<void>(filename);
+ static_cast<void>(ogawa);
+#endif
+
+ Alembic::AbcCoreOgawa::WriteArchive archive_writer;
+ return Alembic::Abc::OArchive(archive_writer(ostream, md), Alembic::Abc::kWrapExisting, policy);
+}
+
/* ************************************************************************** */
ExportSettings::ExportSettings()
@@ -247,26 +299,25 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled)
Alembic::Abc::Argument arg(md);
-#ifdef WITH_ALEMBIC_HDF5
- if (!m_settings.export_ogawa) {
- m_archive = Alembic::Abc::CreateArchiveWithInfo(Alembic::AbcCoreHDF5::WriteArchive(),
- m_filename,
- "Blender",
- scene_name,
- Alembic::Abc::ErrorHandler::kThrowPolicy,
- arg);
- }
- else
+ /* Use stream to support unicode character paths on Windows. */
+ if (m_settings.export_ogawa) {
+#ifdef WIN32
+ UTF16_ENCODE(m_filename);
+ std::wstring wstr(m_filename_16);
+ m_out_file.open(wstr.c_str(), std::ios::out | std::ios::binary);
+ UTF16_UN_ENCODE(m_filename);
+#else
+ m_out_file.open(m_filename, std::ios::out | std::ios::binary);
#endif
- {
- m_archive = Alembic::Abc::CreateArchiveWithInfo(Alembic::AbcCoreOgawa::WriteArchive(),
- m_filename,
- "Blender",
- scene_name,
- Alembic::Abc::ErrorHandler::kThrowPolicy,
- arg);
}
+ m_archive = create_archive(&m_out_file,
+ m_filename,
+ scene_name,
+ Alembic::Abc::ErrorHandler::kThrowPolicy,
+ arg,
+ m_settings.export_ogawa);
+
/* Create time samplings for transforms and shapes. */
TimeSamplingPtr trans_time = createTimeSampling(m_settings.frame_step_xform);