Blender V4.5
abc_util.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
9
10#include "abc_reader_object.h"
11
12#include <Alembic/Abc/Foundation.h>
13#include <Alembic/Abc/ICompoundProperty.h>
14#include <Alembic/Abc/IObject.h>
15#include <Alembic/Abc/ISampleSelector.h>
16#include <Alembic/Abc/TypedArraySample.h>
17#include <Alembic/AbcCoreAbstract/Foundation.h>
18#include <Alembic/AbcCoreAbstract/TimeSampling.h>
19#include <Alembic/AbcGeom/IXform.h>
20
21#include <optional>
22#include <string>
23#include <vector>
24
25using Alembic::Abc::chrono_t;
26using Alembic::Abc::V3fArraySamplePtr;
27
28struct ID;
29struct Object;
30
31namespace blender::io::alembic {
32
33class AbcObjectReader;
34struct ImportSettings;
35
36std::string get_id_name(const ID *const id);
37std::string get_id_name(const Object *const ob);
38std::string get_valid_abc_name(const char *name);
48std::string get_object_dag_path_name(const Object *const ob, Object *dupli_parent);
49
50/* Convert from float to Alembic matrix representations. Does NOT convert from Z-up to Y-up. */
51Imath::M44d convert_matrix_datatype(const float mat[4][4]);
52/* Convert from Alembic to float matrix representations. Does NOT convert from Y-up to Z-up. */
53void convert_matrix_datatype(const Imath::M44d &xform, float r_mat[4][4]);
54
55void split(const std::string &s, char delim, std::vector<std::string> &tokens);
56
57template<class TContainer> bool begins_with(const TContainer &input, const TContainer &match)
58{
59 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
60}
61
62template<typename Schema>
63void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
64{
65 const Alembic::Abc::TimeSamplingPtr &time_samp = schema.getTimeSampling();
66
67 if (!schema.isConstant()) {
68 const size_t num_samps = schema.getNumSamples();
69
70 if (num_samps > 0) {
71 const chrono_t min_time = time_samp->getSampleTime(0);
72 min = std::min(min, min_time);
73
74 const chrono_t max_time = time_samp->getSampleTime(num_samps - 1);
75 max = std::max(max, max_time);
76 }
77 }
78}
79
80template<typename Schema>
81void get_min_max_time(const Alembic::AbcGeom::IObject &object,
82 const Schema &schema,
83 chrono_t &min,
84 chrono_t &max)
85{
86 get_min_max_time_ex(schema, min, max);
87
88 const Alembic::AbcGeom::IObject &parent = object.getParent();
89 if (parent.valid() && Alembic::AbcGeom::IXform::matches(parent.getMetaData())) {
90 Alembic::AbcGeom::IXform xform(parent, Alembic::AbcGeom::kWrapExisting);
91 get_min_max_time_ex(xform.getSchema(), min, max);
92 }
93}
94
95bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name);
96V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema,
97 const Alembic::AbcGeom::ISampleSelector &selector,
98 const std::string &name);
99
105 /* Index of the first ("floor") sample. */
106 Alembic::AbcGeom::index_t index;
107 /* Index of the second ("ceil") sample. */
108 Alembic::AbcGeom::index_t ceil_index;
109 /* Factor to interpolate between the `index` and `ceil_index`. */
110 double weight;
111};
112
119std::optional<SampleInterpolationSettings> get_sample_interpolation_settings(
120 const Alembic::AbcGeom::ISampleSelector &selector,
121 const Alembic::AbcCoreAbstract::TimeSamplingPtr &time_sampling,
122 size_t samples_number);
123
124AbcObjectReader *create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings);
125
126/* *************************** */
127
128#undef ABC_DEBUG_TIME
129
131 const char *m_message;
132 double m_start;
133
134 public:
135 ScopeTimer(const char *message);
136 ~ScopeTimer();
137};
138
139#ifdef ABC_DEBUG_TIME
140# define SCOPE_TIMER(message) ScopeTimer prof(message)
141#else
142# define SCOPE_TIMER(message)
143#endif
144
145/* *************************** */
146
157 std::ostringstream m_stream;
158
159 public:
163 std::string str() const;
164
168 void clear();
169
174 std::ostringstream &stream();
175};
176
177#define ABC_LOG(logger) logger.stream()
178
182std::ostream &operator<<(std::ostream &os, const SimpleLogger &logger);
183
184} // namespace blender::io::alembic
struct ID ID
struct Object Object
ScopeTimer(const char *message)
Definition abc_util.cc:245
std::ostringstream & stream()
Definition abc_util.cc:267
#define input
bool begins_with(const TContainer &input, const TContainer &match)
Definition abc_util.h:57
void get_min_max_time(const Alembic::AbcGeom::IObject &object, const Schema &schema, chrono_t &min, chrono_t &max)
Definition abc_util.h:81
std::string get_valid_abc_name(const char *name)
Definition abc_util.cc:47
std::ostream & operator<<(std::ostream &os, const SimpleLogger &logger)
Definition abc_util.cc:272
std::string get_object_dag_path_name(const Object *const ob, Object *dupli_parent)
get_object_dag_path_name returns the name under which the object will be exported in the Alembic file...
Definition abc_util.cc:57
V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema, const Alembic::AbcGeom::ISampleSelector &selector, const std::string &name)
Definition abc_util.cc:120
std::string get_id_name(const Object *const ob)
Definition abc_util.cc:33
Imath::M44d convert_matrix_datatype(const float mat[4][4])
Definition abc_util.cc:75
bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name)
Definition abc_util.cc:111
void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
Definition abc_util.h:63
AbcObjectReader * create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings)
Definition abc_util.cc:191
std::optional< SampleInterpolationSettings > get_sample_interpolation_settings(const Alembic::AbcGeom::ISampleSelector &selector, const Alembic::AbcCoreAbstract::TimeSamplingPtr &time_sampling, size_t samples_number)
Definition abc_util.cc:158
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:97
#define min(a, b)
Definition sort.cc:36
Definition DNA_ID.h:404
max
Definition text_draw.cc:251