318{
319 const size_t expected_vertex_count = std::accumulate(
320 sample.vertex_counts_per_curve.begin(), sample.vertex_counts_per_curve.end(), size_t { 0 },
321 [](size_t acc, int32_t n) { return acc + static_cast<size_t>(n); });
322 if (expected_vertex_count != sample.positions.size()) {
323 set_error(
"write: vertex_counts_per_curve sum does not match positions.size()");
326 return false;
327 }
328
329 auto it =
m_impl->curves_streams.find(stream_name);
330 if (it ==
m_impl->curves_streams.end()) {
331 MetaData md;
332 auto mit =
m_impl->pending_metadata.find(stream_name);
333 if (mit !=
m_impl->pending_metadata.end()) {
334 md = mit->second;
335 m_impl->pending_metadata.erase(mit);
336 }
337 auto stream = std::make_unique<CurvesStream>();
338 stream->object = OCurves(
m_impl->archive->getTop(), stream_name, md);
339 it =
m_impl->curves_streams.emplace(stream_name, std::move(stream)).first;
340 }
341 auto& stream = *it->second;
342 auto& schema = stream.object.getSchema();
343
344 const P3fArraySample pos_sample(
345 reinterpret_cast<const V3f*>(sample.positions.data()), sample.positions.size());
346 const Int32ArraySample nverts_sample(
347 sample.vertex_counts_per_curve.data(), sample.vertex_counts_per_curve.size());
348
349 schema.set(OCurvesSchema::Sample(pos_sample, nverts_sample, kLinear, kNonPeriodic));
350
351 for (const auto& attr : sample.attributes) {
352 const size_t expected = curves_attribute_count(
353 attr.scope, sample.positions.size(), sample.vertex_counts_per_curve.size());
354 if (!set_attribute(stream.geom_params, schema.getArbGeomParams(), attr, expected)) {
355 set_error(
"write: attribute '" + attr.name +
"' has an unsupported type, wrong "
356 + "element count, or was redeclared with a different type");
359 return false;
360 }
361 }
362
363 return true;
364}
#define MF_ERROR(comp, ctx,...)
std::unique_ptr< Impl > m_impl
std::string get_last_error() const
void set_error(std::string msg) const
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.