12#include <Alembic/Abc/ArchiveInfo.h>
13#include <Alembic/Abc/ErrorHandler.h>
14#include <Alembic/Abc/Foundation.h>
15#include <Alembic/Abc/OArchive.h>
16#include <Alembic/AbcCoreAbstract/MetaData.h>
17#include <Alembic/AbcCoreAbstract/TimeSampling.h>
18#include <Alembic/AbcCoreAbstract/TimeSamplingType.h>
19#include <Alembic/AbcCoreOgawa/ReadWrite.h>
20#include <Alembic/AbcGeom/ArchiveBounds.h>
31using Alembic::Abc::ErrorHandler;
32using Alembic::Abc::kWrapExisting;
33using Alembic::Abc::MetaData;
34using Alembic::Abc::OArchive;
35using Alembic::Abc::TimeSampling;
36using Alembic::Abc::TimeSamplingPtr;
37using Alembic::Abc::TimeSamplingType;
41 MetaData abc_metadata;
43 std::string abc_user_description(bmain->
filepath);
44 if (abc_user_description.empty()) {
45 abc_user_description =
"unknown";
48 abc_metadata.set(Alembic::Abc::kApplicationNameKey,
"Blender");
49 abc_metadata.set(Alembic::Abc::kUserDescriptionKey, abc_user_description);
51 abc_metadata.set(
"FramesPerTimeUnit", std::to_string(scene_fps));
57#if defined _WIN32 || defined _WIN64
58 ctime_s(buffer, 128, &raw_time);
60 ctime_r(&raw_time, buffer);
63 const std::size_t buffer_len = strlen(buffer);
64 if (buffer_len > 0 && buffer[buffer_len - 1] ==
'\n') {
65 buffer[buffer_len - 1] =
'\0';
68 abc_metadata.set(Alembic::Abc::kDateWrittenKey, buffer);
73 const std::string &filepath,
74 MetaData &abc_metadata)
82 std::wstring wstr(filepath_cstr_16);
83 abc_ostream->open(wstr.c_str(), std::ios::out | std::ios::binary);
86 abc_ostream->open(filepath, std::ios::out | std::ios::binary);
89 ErrorHandler::Policy policy = ErrorHandler::kThrowPolicy;
91 Alembic::AbcCoreOgawa::WriteArchive archive_writer;
92 return new OArchive(archive_writer(abc_ostream, abc_metadata), kWrapExisting, policy);
109 std::vector<double> &r_samples)
111 double frame_offset = time_relative ?
params.frame_start : 0.0;
112 double time_factor = time_relative ? scene_fps : 1.0;
113 double shutter_open =
params.shutter_open;
114 double shutter_close =
params.shutter_close;
115 double time_inc = (shutter_close - shutter_open) / nr_of_samples;
119 double sample_time = shutter_open + time_inc *
sample;
120 double time = (frame_offset + sample_time) / time_factor;
122 r_samples.push_back(time);
130 std::vector<double> samples;
133 return TimeSamplingPtr(
new TimeSampling());
138 TimeSamplingType ts(
uint32_t(samples.size()), 1.0 / scene_fps);
139 return TimeSamplingPtr(
new TimeSampling(ts, samples));
145 std::set<double> &r_frames)
148 std::vector<double> shutter_samples;
151 for (
double frame =
params.frame_start; frame <=
params.frame_end; frame += 1.0) {
152 for (
size_t j = 0; j < nr_of_samples; j++) {
153 r_frames.insert(frame + shutter_samples[j]);
163 const std::string &filepath)
166 double scene_fps =
FPS;
173 TimeSamplingPtr ts_xform;
174 TimeSamplingPtr ts_shapes;
177 time_sampling_index_transforms_ =
archive->addTimeSampling(*ts_xform);
179 const bool export_animation =
params.frame_start !=
params.frame_end;
180 if (!export_animation ||
params.frame_samples_shape ==
params.frame_samples_xform) {
181 ts_shapes = ts_xform;
182 time_sampling_index_shapes_ = time_sampling_index_transforms_;
186 time_sampling_index_shapes_ =
archive->addTimeSampling(*ts_shapes);
194 export_frames_.insert(xform_frames_.begin(), xform_frames_.end());
195 export_frames_.insert(shape_frames_.begin(), shape_frames_.end());
197 abc_archive_bbox_ = Alembic::AbcGeom::CreateOArchiveBounds(*
archive,
198 time_sampling_index_transforms_);
208 return time_sampling_index_transforms_;
213 return time_sampling_index_shapes_;
218 return export_frames_.begin();
222 return export_frames_.end();
226 return export_frames_.size();
231 return xform_frames_.find(frame) != xform_frames_.end();
235 return shape_frames_.find(frame) != shape_frames_.end();
247 abc_archive_bbox_.set(bounds);
const char * BKE_blender_version_string(void)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
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)
#define UTF16_ENCODE(in8str)
#define UTF16_UN_ENCODE(in8str)