14 #include <Alembic/AbcCoreOgawa/All.h>
15 #include <Alembic/AbcGeom/All.h>
26 using Alembic::Abc::ErrorHandler;
27 using Alembic::Abc::kWrapExisting;
28 using Alembic::Abc::MetaData;
29 using Alembic::Abc::OArchive;
30 using Alembic::Abc::TimeSampling;
31 using Alembic::Abc::TimeSamplingPtr;
32 using Alembic::Abc::TimeSamplingType;
36 MetaData abc_metadata;
38 std::string abc_user_description(bmain->
filepath);
39 if (abc_user_description.empty()) {
40 abc_user_description =
"unknown";
43 abc_metadata.set(Alembic::Abc::kApplicationNameKey,
"Blender");
44 abc_metadata.set(Alembic::Abc::kUserDescriptionKey, abc_user_description);
52 #if defined _WIN32 || defined _WIN64
53 ctime_s(
buffer, 128, &raw_time);
55 ctime_r(&raw_time,
buffer);
58 const std::size_t buffer_len = strlen(
buffer);
59 if (buffer_len > 0 &&
buffer[buffer_len - 1] ==
'\n') {
60 buffer[buffer_len - 1] =
'\0';
63 abc_metadata.set(Alembic::Abc::kDateWrittenKey,
buffer);
68 const std::string &filename,
69 MetaData &abc_metadata)
77 std::wstring wstr(filename_cstr_16);
78 abc_ostream->open(wstr.c_str(),
std::ios::out | std::ios::binary);
81 abc_ostream->open(filename,
std::ios::out | std::ios::binary);
84 ErrorHandler::Policy policy = ErrorHandler::kThrowPolicy;
86 Alembic::AbcCoreOgawa::WriteArchive archive_writer;
87 return new OArchive(archive_writer(abc_ostream, abc_metadata), kWrapExisting, policy);
104 std::vector<double> &r_samples)
106 double frame_offset = time_relative ?
params.frame_start : 0.0;
107 double time_factor = time_relative ? scene_fps : 1.0;
108 double shutter_open =
params.shutter_open;
109 double shutter_close =
params.shutter_close;
110 double time_inc = (shutter_close - shutter_open) / nr_of_samples;
114 double sample_time = shutter_open + time_inc *
sample;
115 double time = (frame_offset + sample_time) / time_factor;
117 r_samples.push_back(
time);
125 std::vector<double> samples;
128 return TimeSamplingPtr(
new TimeSampling());
133 TimeSamplingType ts(
static_cast<uint32_t>(samples.size()), 1.0 / scene_fps);
134 return TimeSamplingPtr(
new TimeSampling(ts, samples));
139 unsigned int nr_of_samples,
140 std::set<double> &r_frames)
143 std::vector<double> shutter_samples;
146 for (
double frame =
params.frame_start; frame <=
params.frame_end; frame += 1.0) {
147 for (
size_t j = 0; j < nr_of_samples; j++) {
148 r_frames.insert(frame + shutter_samples[j]);
158 std::string filename)
161 double scene_fps =
FPS;
168 TimeSamplingPtr ts_xform;
169 TimeSamplingPtr ts_shapes;
172 time_sampling_index_transforms_ =
archive->addTimeSampling(*ts_xform);
174 const bool export_animation =
params.frame_start !=
params.frame_end;
175 if (!export_animation ||
params.frame_samples_shape ==
params.frame_samples_xform) {
176 ts_shapes = ts_xform;
177 time_sampling_index_shapes_ = time_sampling_index_transforms_;
181 time_sampling_index_shapes_ =
archive->addTimeSampling(*ts_shapes);
189 export_frames_.insert(xform_frames_.begin(), xform_frames_.end());
190 export_frames_.insert(shape_frames_.begin(), shape_frames_.end());
192 abc_archive_bbox_ = Alembic::AbcGeom::CreateOArchiveBounds(*
archive,
193 time_sampling_index_transforms_);
203 return time_sampling_index_transforms_;
208 return time_sampling_index_shapes_;
213 return export_frames_.begin();
217 return export_frames_.end();
221 return export_frames_.size();
226 return xform_frames_.find(frame) != xform_frames_.end();
230 return shape_frames_.find(frame) != shape_frames_.end();
242 abc_archive_bbox_.set(
bounds);
const char * BKE_blender_version_string(void)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Frames::const_iterator frames_end() const
ABCArchive(const Main *bmain, const Scene *scene, AlembicExportParams params, std::string filename)
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
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
ccl_global float * buffer
static void get_frames(double scene_fps, const AlembicExportParams ¶ms, unsigned int 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 &filename, 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)
std::string to_string(const T &n)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
#define UTF16_ENCODE(in8str)
#define UTF16_UN_ENCODE(in8str)