101 std::unique_ptr<
Curves, std::function<void(
Curves *)>> converted_curves;
103 switch (context.object->type) {
105 const Curve *legacy_curve = id_cast<Curve *>(context.object->data);
106 converted_curves = std::unique_ptr<
Curves, std::function<void(
Curves *)>>(
108 curves_id = converted_curves.get();
112 curves_id = id_cast<Curves *>(context.object->data);
123 const std::array<int, CURVE_TYPES_NUM> &curve_type_counts =
curves.curve_type_counts();
124 const int number_of_curve_types = std::count_if(curve_type_counts.begin(),
125 curve_type_counts.end(),
126 [](
const int count) { return count > 0; });
127 if (number_of_curve_types > 1) {
128 CLOG_WARN(&
LOG,
"Cannot export mixed curve types in the same Curves object");
133 CLOG_WARN(&
LOG,
"Cannot export mixed cyclic and non-cyclic curves in the same Curves object");
141 OCompoundProperty user_props = abc_curve_schema_.getUserProperties();
142 const Alembic::Abc::PropertyHeader *prop_header = user_props.getPropertyHeader(
143 ABC_CURVE_RESOLUTION_U_PROPNAME);
145 const int resolution_u =
curves.resolution().first();
146 OInt16Property user_prop_resolu(user_props, ABC_CURVE_RESOLUTION_U_PROPNAME);
147 user_prop_resolu.set(resolution_u);
151 const bool is_cyclic = !
curves.is_empty() &&
curves.cyclic().first();
152 Alembic::AbcGeom::BasisType curve_basis = Alembic::AbcGeom::kNoBasis;
153 Alembic::AbcGeom::CurveType curve_type = Alembic::AbcGeom::kLinear;
154 Alembic::AbcGeom::CurvePeriodicity periodicity = is_cyclic ? Alembic::AbcGeom::kPeriodic :
155 Alembic::AbcGeom::kNonPeriodic;
158 switch (blender_curve_type) {
160 curve_basis = Alembic::AbcGeom::kNoBasis;
161 curve_type = Alembic::AbcGeom::kLinear;
164 curve_basis = Alembic::AbcGeom::kCatmullromBasis;
165 curve_type = Alembic::AbcGeom::kLinear;
168 curve_basis = Alembic::AbcGeom::kBezierBasis;
169 curve_type = Alembic::AbcGeom::kCubic;
172 curve_basis = Alembic::AbcGeom::kBsplineBasis;
173 curve_type = Alembic::AbcGeom::kVariableOrder;
177 std::vector<Imath::V3f> verts;
178 std::vector<int32_t> vert_counts;
179 std::vector<float> widths;
180 std::vector<float> weights;
181 std::vector<float> knots;
182 std::vector<uint8_t> orders;
185 const std::optional<Span<float>> nurbs_weights =
curves.nurbs_weights();
189 Alembic::AbcGeom::GeometryScope width_scope = kVertexScope;
191 width_scope = kConstantScope;
192 widths.push_back(radii[0] * 2.0f);
195 vert_counts.resize(
curves.curves_num());
197 const std::optional<Span<float3>> handles_l =
curves.handle_positions_left();
198 const std::optional<Span<float3>> handles_r =
curves.handle_positions_right();
201 for (
const int i_curve :
curves.curves_range()) {
202 const IndexRange points = points_by_curve[i_curve];
203 const size_t current_vert_count = verts.size();
205 const int start_point_index = points.
first();
206 const int last_point_index = points.
last();
214 for (
const int i_point : points.
drop_back(1)) {
215 verts.push_back(
to_yup_V3f(positions[i_point]));
216 if (width_scope != kConstantScope) {
217 widths.push_back(radii[i_point] * 2.0f);
220 verts.push_back(
to_yup_V3f((*handles_r)[i_point]));
221 verts.push_back(
to_yup_V3f((*handles_l)[i_point + 1]));
226 verts.push_back(
to_yup_V3f(positions[last_point_index]));
227 if (width_scope != kConstantScope) {
228 widths.push_back(radii[last_point_index] * 2.0f);
234 verts.push_back(
to_yup_V3f((*handles_r)[last_point_index]));
235 verts.push_back(
to_yup_V3f((*handles_l)[start_point_index]));
238 vert_counts[i_curve] = verts.size() - current_vert_count;
242 verts.resize(
curves.points_num());
243 if (width_scope != kConstantScope) {
244 widths.resize(
curves.points_num());
246 for (
const int i_point :
curves.points_range()) {
247 verts[i_point] =
to_yup_V3f(positions[i_point]);
248 if (width_scope != kConstantScope) {
249 widths[i_point] = radii[i_point] * 2.0f;
255 weights.resize(
curves.points_num());
256 std::copy_n(nurbs_weights->data(), weights.size(), weights.data());
259 orders.resize(
curves.curves_num());
260 for (
const int i_curve :
curves.curves_range()) {
261 orders[i_curve] = nurbs_orders[i_curve];
268 Alembic::AbcGeom::OFloatGeomParam::Sample width_sample;
269 width_sample.setVals(widths);
270 width_sample.setScope(width_scope);
272 OCurvesSchema::Sample
sample(verts,
277 OV2fGeomParam::Sample(),
278 ON3fGeomParam::Sample(),
284 std::vector<Imath::V3f> velocities;
286 sample.setVelocities(velocities);
291 abc_curve_schema_.set(
sample);
293 write_arb_geo_params(
curves, *context.object, abc_curve_schema_.getNumSamples());