16#include <Alembic/Abc/ArchiveInfo.h>
17#include <Alembic/Abc/ErrorHandler.h>
18#include <Alembic/Abc/Foundation.h>
19#include <Alembic/Abc/OArchive.h>
20#include <Alembic/AbcCoreAbstract/MetaData.h>
21#include <Alembic/AbcCoreAbstract/TimeSampling.h>
22#include <Alembic/AbcCoreAbstract/TimeSamplingType.h>
23#include <Alembic/AbcCoreOgawa/ReadWrite.h>
24#include <Alembic/AbcGeom/ArchiveBounds.h>
35using Alembic::Abc::ErrorHandler;
36using Alembic::Abc::kWrapExisting;
37using Alembic::Abc::MetaData;
38using Alembic::Abc::OArchive;
39using Alembic::Abc::TimeSampling;
40using Alembic::Abc::TimeSamplingPtr;
41using Alembic::Abc::TimeSamplingType;
45 MetaData abc_metadata;
47 std::string abc_user_description(bmain->
filepath);
48 if (abc_user_description.empty()) {
49 abc_user_description =
"unknown";
52 abc_metadata.set(Alembic::Abc::kApplicationNameKey,
"Blender");
53 abc_metadata.set(Alembic::Abc::kUserDescriptionKey, abc_user_description);
55 abc_metadata.set(
"FramesPerTimeUnit", std::to_string(scene_fps));
61#if defined _WIN32 || defined _WIN64
62 ctime_s(buffer, 128, &raw_time);
64 ctime_r(&raw_time, buffer);
67 const std::size_t buffer_len = strlen(buffer);
68 if (buffer_len > 0 && buffer[buffer_len - 1] ==
'\n') {
69 buffer[buffer_len - 1] =
'\0';
72 abc_metadata.set(Alembic::Abc::kDateWrittenKey, buffer);
77 const std::string &filepath,
78 MetaData &abc_metadata)
86 std::wstring wstr(filepath_cstr_16);
87 abc_ostream->open(wstr.c_str(), std::ios::out | std::ios::binary);
90 abc_ostream->open(filepath, std::ios::out | std::ios::binary);
93 ErrorHandler::Policy policy = ErrorHandler::kThrowPolicy;
95 Alembic::AbcCoreOgawa::WriteArchive archive_writer;
96 return new OArchive(archive_writer(abc_ostream, abc_metadata), kWrapExisting, policy);
113 std::vector<double> &r_samples)
115 double frame_offset = time_relative ? params.
frame_start : 0.0;
116 double time_factor = time_relative ? scene_fps : 1.0;
119 double time_inc = (shutter_close - shutter_open) / nr_of_samples;
123 double sample_time = shutter_open + time_inc *
sample;
124 double time = (frame_offset + sample_time) / time_factor;
126 r_samples.push_back(time);
134 std::vector<double> samples;
137 return TimeSamplingPtr(
new TimeSampling());
142 TimeSamplingType ts(
uint32_t(samples.size()), 1.0 / scene_fps);
143 return TimeSamplingPtr(
new TimeSampling(ts, samples));
149 std::set<double> &r_frames)
152 std::vector<double> shutter_samples;
156 for (
size_t j = 0; j < nr_of_samples; j++) {
157 r_frames.insert(frame + shutter_samples[j]);
167 const std::string &filepath)
170 double scene_fps = scene->frames_per_second();
177 TimeSamplingPtr ts_xform;
178 TimeSamplingPtr ts_shapes;
181 time_sampling_index_transforms_ =
archive->addTimeSampling(*ts_xform);
185 ts_shapes = ts_xform;
186 time_sampling_index_shapes_ = time_sampling_index_transforms_;
190 time_sampling_index_shapes_ =
archive->addTimeSampling(*ts_shapes);
198 export_frames_.insert(xform_frames_.begin(), xform_frames_.end());
199 export_frames_.insert(shape_frames_.begin(), shape_frames_.end());
201 abc_archive_bbox_ = Alembic::AbcGeom::CreateOArchiveBounds(*
archive,
202 time_sampling_index_transforms_);
212 return time_sampling_index_transforms_;
217 return time_sampling_index_shapes_;
222 return export_frames_.begin();
226 return export_frames_.end();
230 return export_frames_.size();
235 return xform_frames_.contains(frame);
239 return shape_frames_.contains(frame);
251 abc_archive_bbox_.set(
bounds);
Frames::const_iterator frames_end() const
bool is_xform_frame(double frame) const
ExportSubset export_subset_for_frame(double frame) const
bool is_shape_frame(double frame) const
Frames::const_iterator frames_begin() const
uint32_t time_sampling_index_shapes() const
ABCArchive(const Main *bmain, const Scene *scene, AlembicExportParams params, const std::string &filepath)
Alembic::Abc::OArchive * archive
void update_bounding_box(const Imath::Box3d &bounds)
uint32_t time_sampling_index_transforms() const
size_t total_frame_count() const
static void get_frames(double scene_fps, const AlembicExportParams ¶ms, uint nr_of_samples, std::set< double > &r_frames)
static MetaData create_abc_metadata(const Main *bmain, double scene_fps)
static OArchive * create_archive(std::ofstream *abc_ostream, const std::string &filepath, MetaData &abc_metadata)
static TimeSamplingPtr create_time_sampling(double scene_fps, const AlembicExportParams ¶ms, int nr_of_samples)
static void get_shutter_samples(double scene_fps, const AlembicExportParams ¶ms, int nr_of_samples, bool time_relative, std::vector< double > &r_samples)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
const char * BKE_blender_version_string()
unsigned int frame_samples_shape
unsigned int frame_samples_xform
#define UTF16_ENCODE(in8str)
#define UTF16_UN_ENCODE(in8str)