Blender V5.3
abc_writer_mesh.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "abc_writer_mesh.h"
12#include "intern/abc_util.h"
13
15#include "BKE_attribute.h"
16#include "BKE_attribute.hh"
17#include "BKE_lib_id.hh"
18#include "BKE_material.hh"
19#include "BKE_mesh.hh"
20#include "BKE_mesh_wrapper.hh"
21#include "BKE_object.hh"
22#include "BKE_subdiv.hh"
23
24#include "bmesh.hh"
25#include "bmesh_tools.hh"
26
28#include "DNA_material_types.h"
29#include "DNA_mesh_types.h"
30#include "DNA_modifier_types.h"
31#include "DNA_object_types.h"
32
33#include "CLG_log.h"
34
35namespace blender {
36
37static CLG_LogRef LOG = {"io.alembic"};
38
39using Alembic::Abc::FloatArraySample;
40using Alembic::Abc::Int32ArraySample;
41using Alembic::Abc::OObject;
42using Alembic::Abc::V2fArraySample;
43using Alembic::Abc::V3fArraySample;
44
45using Alembic::AbcGeom::kFacevaryingScope;
46using Alembic::AbcGeom::OBoolProperty;
47using Alembic::AbcGeom::OCompoundProperty;
48using Alembic::AbcGeom::OFaceSet;
49using Alembic::AbcGeom::OFaceSetSchema;
50using Alembic::AbcGeom::OInt32Property;
51using Alembic::AbcGeom::ON3fGeomParam;
52using Alembic::AbcGeom::OPolyMesh;
53using Alembic::AbcGeom::OPolyMeshSchema;
54using Alembic::AbcGeom::OStringProperty;
55using Alembic::AbcGeom::OSubD;
56using Alembic::AbcGeom::OSubDSchema;
57using Alembic::AbcGeom::OV2fGeomParam;
58using Alembic::AbcGeom::UInt32ArraySample;
59
60namespace io::alembic {
61
62/* NOTE: Alembic's polygon winding order is clockwise, to match with RenderMan. */
63
64static void get_topology(Mesh *mesh,
65 std::vector<int32_t> &face_verts,
66 std::vector<int32_t> &loop_counts);
67static void get_edge_creases(Mesh *mesh,
68 std::vector<int32_t> &indices,
69 std::vector<int32_t> &lengths,
70 std::vector<float> &sharpnesses);
71static void get_vert_creases(Mesh *mesh,
72 std::vector<int32_t> &indices,
73 std::vector<float> &sharpnesses);
74static void get_loop_normals(const Mesh *mesh, std::vector<Imath::V3f> &normals);
75
76/* Get the last subdiv modifier ignoring subsequent particle systems modifiers, regardless of
77 * enable/disable status.
78 * TODO(kevindietrich) : deduplicate this with USD, but USD does not ignore particle systems. */
80{
82
83 /* Return the subdiv modifier if it is the last modifier and has
84 * the required mode enabled. */
85
86 ModifierData *md = obj->modifiers.last();
87
88 while (md != nullptr) {
90 break;
91 }
92 md = md->prev;
93 }
94
95 if (!md) {
96 return nullptr;
97 }
98
99 /* Determine if the modifier is enabled for the current evaluation mode. */
100 ModifierMode mod_mode = (eval_mode == DAG_EVAL_RENDER) ? eModifierMode_Render :
102
103 if ((md->mode & mod_mode) != mod_mode) {
104 return nullptr;
105 }
106
107 if (md->type == eModifierType_Subsurf) {
108 return reinterpret_cast<SubsurfModifierData *>(md);
109 }
110
111 return nullptr;
112}
113
118
120{
123 }
124
125 if (is_subd_) {
126 CLOG_DEBUG(&LOG, "exporting OSubD %s", args_.abc_path.c_str());
127 abc_subdiv_ = OSubD(args_.abc_parent, args_.abc_name, timesample_index_);
128 abc_subdiv_schema_ = abc_subdiv_.getSchema();
129
130 abc_custom_data_container_ = abc_subdiv_schema_.getUserProperties();
131 abc_subdiv_render_levels_ = OInt32Property(
132 abc_custom_data_container_, "subdivRenderLevels", timesample_index_);
133 abc_subdiv_viewport_levels_ = OInt32Property(
134 abc_custom_data_container_, "subdivViewportLevels", timesample_index_);
135 }
136 else {
137 CLOG_DEBUG(&LOG, "exporting OPolyMesh %s", args_.abc_path.c_str());
138 abc_poly_mesh_ = OPolyMesh(args_.abc_parent, args_.abc_name, timesample_index_);
139 abc_poly_mesh_schema_ = abc_poly_mesh_.getSchema();
140
141 abc_custom_data_container_ = abc_poly_mesh_.getSchema().getUserProperties();
142 OBoolProperty type(abc_custom_data_container_, "meshtype");
143 type.set(subsurf_modifier_ == nullptr);
144 }
145
146 if (context->object->data->id_type() == ID_ME) {
147 Mesh *mesh = id_cast<Mesh *>(context->object->data);
148 if (mesh->active_color_attribute && mesh->default_color_attribute) {
149 /* We need to the get the valid versions of the names as the attributes are exported with
150 * validated names. */
151 OStringProperty active_color_attribute(abc_custom_data_container_,
152 ABC_ACTIVE_COLOR_ATTRIBUTE_PROPNAME);
153 active_color_attribute.set(get_valid_abc_name(mesh->active_color_attribute));
154
155 OStringProperty default_color_attribute(abc_custom_data_container_,
156 ABC_DEFAULT_COLOR_ATTRIBUTE_PROPNAME);
157 default_color_attribute.set(get_valid_abc_name(mesh->default_color_attribute));
158 }
159 }
160}
161
162Alembic::Abc::OObject ABCGenericMeshWriter::get_alembic_object() const
163{
164 if (is_subd_) {
165 return abc_subdiv_;
166 }
167 return abc_poly_mesh_;
168}
169
170Alembic::Abc::OCompoundProperty ABCGenericMeshWriter::abc_prop_for_custom_props()
171{
172 if (is_subd_) {
173 return abc_schema_prop_for_custom_props(abc_subdiv_schema_);
174 }
175 return abc_schema_prop_for_custom_props(abc_poly_mesh_schema_);
176}
177
179{
180 ModifierData *md = ob_eval->modifiers.last();
181
182 for (; md; md = md->prev) {
183 /* This modifier has been temporarily disabled by SubdivModifierDisabler,
184 * so this indicates this is to be exported as subdivision surface. */
186 return true;
187 }
188 }
189
190 return false;
191}
192
194{
195 return context->is_object_visible(args_.export_params->evaluation_mode);
196}
197
199{
200 Object *object = context.object;
201 bool needsfree = false;
202
203 Mesh *mesh = get_export_mesh(object, needsfree);
204
205 if (mesh == nullptr) {
206 return;
207 }
208
209 /* Ensure data exists if currently in edit mode. */
211
213 const bool tag_only = false;
214 const int quad_method = args_.export_params->quad_method;
215 const int ngon_method = args_.export_params->ngon_method;
216
217 BMeshCreateParams bmesh_create_params{};
218 BMeshFromMeshParams bmesh_from_mesh_params{};
219 bmesh_from_mesh_params.calc_face_normal = true;
220 bmesh_from_mesh_params.calc_vert_normal = true;
221 BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, &bmesh_create_params, &bmesh_from_mesh_params);
222
223 BM_mesh_triangulate(bm, quad_method, ngon_method, 4, tag_only, nullptr, nullptr, nullptr);
224
225 Mesh *triangulated_mesh = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, mesh);
227
228 if (needsfree) {
230 }
231 mesh = triangulated_mesh;
232 needsfree = true;
233 }
234
235 m_custom_data_config.pack_uvs = args_.export_params->packuv;
236 m_custom_data_config.mesh = mesh;
237 m_custom_data_config.face_offsets = mesh->face_offsets_for_write().data();
238 m_custom_data_config.corner_verts = mesh->corner_verts_for_write().data();
239 m_custom_data_config.faces_num = mesh->faces_num;
240 m_custom_data_config.totloop = mesh->corners_num;
241 m_custom_data_config.totvert = mesh->verts_num;
242 m_custom_data_config.timesample_index = timesample_index_;
243
244 try {
245 if (is_subd_) {
246 write_subd(context, mesh);
247 }
248 else {
249 write_mesh(context, mesh);
250 }
251
252 if (needsfree) {
254 }
255 }
256 catch (...) {
257 if (needsfree) {
259 }
260 throw;
261 }
262}
263
268
269void ABCGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh)
270{
271 std::vector<Imath::V3f> points, normals;
272 std::vector<int32_t> face_verts, loop_counts;
273 std::vector<Imath::V3f> velocities;
274
275 get_positions(mesh->vert_positions(), points);
276 get_topology(mesh, face_verts, loop_counts);
277
279 write_face_sets(context.object, mesh, abc_poly_mesh_schema_);
280 }
281
282 OPolyMeshSchema::Sample mesh_sample = OPolyMeshSchema::Sample(
283 V3fArraySample(points), Int32ArraySample(face_verts), Int32ArraySample(loop_counts));
284
285 UVSample uvs_and_indices;
286
287 if (args_.export_params->uvs) {
288 const char *name = get_uv_sample(uvs_and_indices, m_custom_data_config, *mesh);
289
290 if (!uvs_and_indices.indices.empty() && !uvs_and_indices.uvs.empty()) {
291 OV2fGeomParam::Sample uv_sample;
292 uv_sample.setVals(V2fArraySample(uvs_and_indices.uvs));
293 uv_sample.setIndices(UInt32ArraySample(uvs_and_indices.indices));
294 uv_sample.setScope(kFacevaryingScope);
295
296 abc_poly_mesh_schema_.setUVSourceName(name);
297 mesh_sample.setUVs(uv_sample);
298 }
299
300 write_uv_maps(abc_poly_mesh_schema_.getArbGeomParams(), m_custom_data_config, *mesh);
301 }
302
304 get_loop_normals(mesh, normals);
305
306 ON3fGeomParam::Sample normals_sample;
307 if (!normals.empty()) {
308 normals_sample.setScope(kFacevaryingScope);
309 normals_sample.setVals(V3fArraySample(normals));
310 }
311
312 mesh_sample.setNormals(normals_sample);
313 }
314
316 write_generated_coordinates(abc_poly_mesh_schema_.getArbGeomParams(), m_custom_data_config);
317 }
318
319 if (get_velocities(mesh->attributes(), velocities)) {
320 mesh_sample.setVelocities(V3fArraySample(velocities));
321 }
322
324 mesh_sample.setSelfBounds(bounding_box_);
325
326 abc_poly_mesh_schema_.set(mesh_sample);
327
328 write_arb_geo_params(mesh, *context.object, abc_poly_mesh_schema_.getNumSamples());
329}
330
331void ABCGenericMeshWriter::write_subd(HierarchyContext &context, Mesh *mesh)
332{
333 std::vector<float> edge_crease_sharpness, vert_crease_sharpness;
334 std::vector<Imath::V3f> points;
335 std::vector<int32_t> face_verts, loop_counts;
336 std::vector<int32_t> edge_crease_indices, edge_crease_lengths, vert_crease_indices;
337
338 get_positions(mesh->vert_positions(), points);
339 get_topology(mesh, face_verts, loop_counts);
340 get_edge_creases(mesh, edge_crease_indices, edge_crease_lengths, edge_crease_sharpness);
341 get_vert_creases(mesh, vert_crease_indices, vert_crease_sharpness);
342
344 write_face_sets(context.object, mesh, abc_subdiv_schema_);
345 }
346
347 OSubDSchema::Sample subdiv_sample = OSubDSchema::Sample(
348 V3fArraySample(points), Int32ArraySample(face_verts), Int32ArraySample(loop_counts));
349
350 UVSample sample;
351 if (args_.export_params->uvs) {
352 const char *name = get_uv_sample(sample, m_custom_data_config, *mesh);
353
354 if (!sample.indices.empty() && !sample.uvs.empty()) {
355 OV2fGeomParam::Sample uv_sample;
356 uv_sample.setVals(V2fArraySample(sample.uvs));
357 uv_sample.setIndices(UInt32ArraySample(sample.indices));
358 uv_sample.setScope(kFacevaryingScope);
359
360 abc_subdiv_schema_.setUVSourceName(name);
361 subdiv_sample.setUVs(uv_sample);
362 }
363
364 write_uv_maps(abc_subdiv_schema_.getArbGeomParams(), m_custom_data_config, *mesh);
365 }
366
368 write_generated_coordinates(abc_subdiv_schema_.getArbGeomParams(), m_custom_data_config);
369 }
370
371 if (!edge_crease_indices.empty()) {
372 subdiv_sample.setCreaseIndices(Int32ArraySample(edge_crease_indices));
373 subdiv_sample.setCreaseLengths(Int32ArraySample(edge_crease_lengths));
374 subdiv_sample.setCreaseSharpnesses(FloatArraySample(edge_crease_sharpness));
375 }
376
377 if (!vert_crease_indices.empty()) {
378 subdiv_sample.setCornerIndices(Int32ArraySample(vert_crease_indices));
379 subdiv_sample.setCornerSharpnesses(FloatArraySample(vert_crease_sharpness));
380 }
381
382 const SubsurfModifierData *subsurf_data = get_last_subdiv_modifier(
384
385 if (subsurf_data) {
386 AbcFaceVaryingInterpolateBoundary fvar_interpolate_boundary =
389 int propagate_corners = 0;
390
391 /* Confusingly, ALL is NONE and NONE is ALL. */
392 switch (subsurf_data->uv_smooth) {
394 fvar_interpolate_boundary = AbcFaceVaryingInterpolateBoundary::ALL;
395 break;
398 fvar_interpolate_boundary = AbcFaceVaryingInterpolateBoundary::EDGE_AND_CORNERS;
399 break;
401 fvar_interpolate_boundary = AbcFaceVaryingInterpolateBoundary::EDGE_AND_CORNERS;
402 propagate_corners = 1;
403 break;
405 fvar_interpolate_boundary = AbcFaceVaryingInterpolateBoundary::BOUNDARIES;
406 break;
408 fvar_interpolate_boundary = AbcFaceVaryingInterpolateBoundary::NONE;
409 break;
410 }
411
412 switch (subsurf_data->boundary_smooth) {
414 interpolate_boundary = AbcInterpolateBoundary::EDGE_AND_CORNERS;
415 break;
417 interpolate_boundary = AbcInterpolateBoundary::EDGE_ONLY;
418 break;
419 }
420
421 subdiv_sample.setFaceVaryingInterpolateBoundary(int(fvar_interpolate_boundary));
422 subdiv_sample.setFaceVaryingPropagateCorners(propagate_corners);
423 subdiv_sample.setInterpolateBoundary(int(interpolate_boundary));
424
425 abc_subdiv_viewport_levels_.set(subsurf_data->levels);
426 abc_subdiv_render_levels_.set(subsurf_data->renderLevels);
427 }
428
430 subdiv_sample.setSelfBounds(bounding_box_);
431 abc_subdiv_schema_.set(subdiv_sample);
432
433 write_arb_geo_params(mesh, *context.object, abc_subdiv_schema_.getNumSamples());
434}
435
436static void write_empty_samples(OFaceSet &face_set, const size_t num_geom_samples)
437{
438 OFaceSetSchema &face_set_schema = face_set.getSchema();
439 OFaceSetSchema::Sample samp;
440
441 /* Write empty samples for missing frames.
442 * NOTE: we need a non-null pointer for the array sample otherwise Alembic will treat it as a
443 * null sample and either throw an exception on the first frame, or reuse the last frame's
444 * data. */
445 static int address_for_empty_sample = 0;
446 samp.setFaces(Int32ArraySample(&address_for_empty_sample, 0));
447 for (size_t i = face_set_schema.getNumSamples(); i < num_geom_samples; i++) {
448 face_set_schema.set(samp);
449 }
450}
451
452template<typename Schema>
453void ABCGenericMeshWriter::write_face_sets(Object *object, Mesh *mesh, Schema &schema)
454{
455 std::map<std::string, std::vector<int32_t>> geo_groups;
456 get_geo_groups(object, mesh, geo_groups);
457
458 std::map<std::string, std::vector<int32_t>>::iterator it;
459 for (it = geo_groups.begin(); it != geo_groups.end(); ++it) {
460 OFaceSet face_set;
461 if (schema.hasFaceSet(it->first)) {
462 face_set = schema.getFaceSet(it->first);
463 }
464 else {
465 face_set = schema.createFaceSet(it->first);
466 face_set_names_.append(it->first);
467 }
468
469 write_empty_samples(face_set, schema.getNumSamples());
470
471 OFaceSetSchema &face_set_schema = face_set.getSchema();
472 face_set_schema.setTimeSampling(timesample_index());
473
474 OFaceSetSchema::Sample samp;
475 samp.setFaces(Int32ArraySample(it->second));
476 face_set_schema.set(samp);
477 }
478
479 /* Write empty samples for facesets which were not used in this frame. */
480 for (const std::string &name : face_set_names_) {
481 OFaceSet face_set = schema.getFaceSet(name);
482 /* +1 because we wrote a sample above. */
483 write_empty_samples(face_set, schema.getNumSamples() + 1);
484 }
485}
486
487void ABCGenericMeshWriter::write_arb_geo_params(Mesh *mesh,
488 const Object &object,
489 const size_t num_geom_samples)
490{
491 OCompoundProperty arb_geom_params;
492 if (is_subd_) {
493 arb_geom_params = abc_subdiv_.getSchema().getArbGeomParams();
494 }
495 else {
496 arb_geom_params = abc_poly_mesh_.getSchema().getArbGeomParams();
497 }
498
499 const bke::AttributeAccessor attributes = mesh->attributes();
500
501 if (attribute_maps_) {
502 /* Write empty samples for attributes up until this frame, so everything lines up. */
503 BLI_assert(num_geom_samples >= 1);
504 attribute_maps_->write_empty_samples(num_geom_samples - 1);
505 }
506
507 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
508 /* Skip "internal" Blender properties and attributes dealt with elsewhere.
509 * Skip edge domain because Alembic doesn't have a good conversion for them. */
510 if (iter.name[0] == '.' || bke::attribute_name_is_anonymous(iter.name) ||
511 iter.domain == bke::AttrDomain::Edge ||
512 ELEM(iter.name,
513 "position",
514 "material_index",
515 "velocity",
516 "crease_vert",
517 "custom_normal",
518 "sharp_face"))
519 {
520 return;
521 }
522
523 if (iter.domain == bke::AttrDomain::Corner) {
524 if (iter.data_type == bke::AttrType::Float2) {
525 /* UVs are written on a different path. */
526 return;
527 }
528
529 if (iter.data_type == bke::AttrType::ColorByte ||
530 iter.data_type == bke::AttrType::ColorFloat)
531 {
533 return;
534 }
535 }
536 }
537
538 AttributeParamMaps &param_maps = get_attribute_param_maps();
539 /* Pass num_geom_samples - 1 so we write empty samples up until this frame. */
540 BLI_assert(num_geom_samples >= 1);
541 create_geom_param_for_attribute(arb_geom_params,
542 param_maps,
543 iter,
545 mesh->faces(),
546 BKE_id_name(object.id),
547 num_geom_samples - 1);
548 });
549
550 if (attribute_maps_) {
551 /* If an attribute was missing this frame, write empty samples for it.
552 * This is mostly to ensure that attributes have the same number of samples as the geometry
553 * data if some disappear midway in the animation and never come back. */
554 attribute_maps_->write_empty_samples(num_geom_samples);
555 }
556}
557
558AttributeParamMaps &ABCGenericMeshWriter::get_attribute_param_maps()
559{
560 if (!attribute_maps_) {
561 attribute_maps_ = std::make_unique<AttributeParamMaps>();
562 }
563 return *attribute_maps_.get();
564}
565
566void ABCGenericMeshWriter::get_geo_groups(Object *object,
567 Mesh *mesh,
568 std::map<std::string, std::vector<int32_t>> &geo_groups)
569{
570 const bke::AttributeAccessor attributes = mesh->attributes();
571 const VArraySpan<int> material_indices = *attributes.lookup_or_default<int>(
572 "material_index", bke::AttrDomain::Face, 0);
573
574 for (const int i : material_indices.index_range()) {
575 short mnr = material_indices[i];
576
577 Material *mat = BKE_object_material_get_eval(object, mnr + 1);
578
579 if (!mat) {
580 continue;
581 }
582
583 std::string name = args_.hierarchy_iterator->get_id_name(&mat->id);
584
585 if (!geo_groups.contains(name)) {
586 std::vector<int32_t> faceArray;
587 geo_groups[name] = faceArray;
588 }
589
590 geo_groups[name].push_back(i);
591 }
592
593 if (geo_groups.empty()) {
594 Material *mat = BKE_object_material_get_eval(object, 1);
595
596 std::string name = (mat) ? args_.hierarchy_iterator->get_id_name(&mat->id) : "default";
597
598 std::vector<int32_t> faceArray;
599
600 for (int i = 0, e = mesh->faces().size(); i < e; i++) {
601 faceArray.push_back(i);
602 }
603
604 geo_groups[name] = faceArray;
605 }
606}
607
608/* NOTE: Alembic's polygon winding order is clockwise, to match with RenderMan. */
609
610static void get_topology(Mesh *mesh,
611 std::vector<int32_t> &face_verts,
612 std::vector<int32_t> &loop_counts)
613{
614 const OffsetIndices faces = mesh->faces();
615 const Span<int> corner_verts = mesh->corner_verts();
616
617 face_verts.clear();
618 loop_counts.clear();
619 face_verts.reserve(corner_verts.size());
620 loop_counts.reserve(faces.size());
621
622 /* NOTE: data needs to be written in the reverse order. */
623 for (const int i : faces.index_range()) {
624 const IndexRange face = faces[i];
625 loop_counts.push_back(face.size());
626
627 int corner = face.start() + (face.size() - 1);
628 for (int j = 0; j < face.size(); j++, corner--) {
629 face_verts.push_back(corner_verts[corner]);
630 }
631 }
632}
633
635 std::vector<int32_t> &indices,
636 std::vector<int32_t> &lengths,
637 std::vector<float> &sharpnesses)
638{
639 indices.clear();
640 lengths.clear();
641 sharpnesses.clear();
642
643 const bke::AttributeAccessor attributes = mesh->attributes();
644 const bke::AttributeReader attribute = attributes.lookup<float>("crease_edge",
646 if (!attribute) {
647 return;
648 }
649 const VArraySpan creases(*attribute);
650 const Span<int2> edges = mesh->edges();
651 for (const int i : edges.index_range()) {
652 const float crease = std::clamp(creases[i], 0.0f, 1.0f);
653
654 if (crease != 0.0f) {
655 indices.push_back(edges[i][0]);
656 indices.push_back(edges[i][1]);
657 sharpnesses.push_back(bke::subdiv::crease_to_sharpness(crease));
658 }
659 }
660
661 lengths.resize(sharpnesses.size(), 2);
662}
663
665 std::vector<int32_t> &indices,
666 std::vector<float> &sharpnesses)
667{
668 indices.clear();
669 sharpnesses.clear();
670
671 const bke::AttributeAccessor attributes = mesh->attributes();
672 const bke::AttributeReader attribute = attributes.lookup<float>("crease_vert",
674 if (!attribute) {
675 return;
676 }
677 const VArraySpan creases(*attribute);
678 for (const int i : creases.index_range()) {
679 const float crease = std::clamp(creases[i], 0.0f, 1.0f);
680
681 if (crease != 0.0f) {
682 indices.push_back(i);
683 sharpnesses.push_back(bke::subdiv::crease_to_sharpness(crease));
684 }
685 }
686}
687
688static void get_loop_normals(const Mesh *mesh, std::vector<Imath::V3f> &normals)
689{
690 normals.clear();
691
692 switch (mesh->normals_domain()) {
694 /* If all faces are smooth shaded, and there are no custom normals, we don't need to
695 * export normals at all. This is also done by other software, see #71246. */
696 break;
697 }
699 normals.resize(mesh->corners_num);
700 MutableSpan dst_normals(reinterpret_cast<float3 *>(normals.data()), normals.size());
701
702 const OffsetIndices faces = mesh->faces();
703 const Span<float3> face_normals = mesh->face_normals();
704 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
705 for (const int i : range) {
706 float3 y_up;
707 copy_yup_from_zup(y_up, face_normals[i]);
708 dst_normals.slice(faces[i]).fill(y_up);
709 }
710 });
711 break;
712 }
714 normals.resize(mesh->corners_num);
715 MutableSpan dst_normals(reinterpret_cast<float3 *>(normals.data()), normals.size());
716
717 /* NOTE: data needs to be written in the reverse order. */
718 const OffsetIndices faces = mesh->faces();
719 const Span<float3> corner_normals = mesh->corner_normals();
720 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
721 for (const int i : range) {
722 const IndexRange face = faces[i];
723 for (const int i : face.index_range()) {
724 copy_yup_from_zup(dst_normals[face.last(i)], corner_normals[face[i]]);
725 }
726 }
727 });
728 break;
729 }
730 }
731}
732
734
735Mesh *ABCMeshWriter::get_export_mesh(Object *object_eval, bool & /*r_needsfree*/)
736{
737 return BKE_object_get_evaluated_mesh(object_eval);
738}
739
740} // namespace io::alembic
741} // namespace blender
Generic geometry attributes built on CustomData.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
Object is a sort of wrapper for general info.
#define BLI_assert(a)
#define ELEM(...)
AttributeSet attributes
constexpr int64_t size() const
constexpr int64_t start() const
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
GAttributeReader lookup(const StringRef name) const
constexpr IndexRange index_range() const
virtual std::string get_id_name(const ID *id) const
ABCAbstractWriter(const ABCWriterConstructorArgs &args)
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
const ABCWriterConstructorArgs args_
virtual void update_bounding_box(Object *object)
void do_write(HierarchyContext &context) override
ABCGenericMeshWriter(const ABCWriterConstructorArgs &args)
Alembic::Abc::OObject get_alembic_object() const override
bool is_supported(const HierarchyContext *context) const override
virtual Mesh * get_export_mesh(Object *object_eval, bool &r_needsfree)=0
Alembic::Abc::OCompoundProperty abc_prop_for_custom_props() override
void create_alembic_objects(const HierarchyContext *context) override
virtual bool export_as_subdivision_surface(Object *ob_eval) const
Mesh * get_export_mesh(Object *object_eval, bool &r_needsfree) override
ABCMeshWriter(const ABCWriterConstructorArgs &args)
#define attribute(slot)
BLI_INLINE float crease_to_sharpness(float crease)
bool attribute_name_is_anonymous(const StringRef name)
int context(const bContext *C, const char *member, bContextDataResult *result)
void write_uv_maps(const OCompoundProperty &prop, CDStreamConfig &config, const Mesh &mesh)
void create_geom_param_for_attribute(const Alembic::Abc::OCompoundProperty &prop, AttributeParamMaps &param_maps, const bke::AttributeIter &attr, const int timesample_index, const OffsetIndices< int > faces, const StringRefNull object_name, const size_t num_geom_samples)
static void get_vert_creases(Mesh *mesh, std::vector< int32_t > &indices, std::vector< float > &sharpnesses)
static void get_edge_creases(Mesh *mesh, std::vector< int32_t > &indices, std::vector< int32_t > &lengths, std::vector< float > &sharpnesses)
static const SubsurfModifierData * get_last_subdiv_modifier(eEvaluationMode eval_mode, Object *obj)
std::string get_valid_abc_name(const char *name)
Definition abc_util.cc:36
static void get_loop_normals(const Mesh *mesh, std::vector< Imath::V3f > &normals)
static void get_topology(Mesh *mesh, std::vector< int32_t > &face_verts, std::vector< int32_t > &loop_counts)
static void write_empty_samples(OFaceSet &face_set, const size_t num_geom_samples)
bool get_velocities(const bke::AttributeAccessor &attributes, std::vector< Imath::V3f > &velocities)
void write_generated_coordinates(const OCompoundProperty &prop, CDStreamConfig &config)
void get_positions(const Span< float3 > positions, std::vector< Imath::V3f > &points)
const char * get_uv_sample(UVSample &sample, const CDStreamConfig &config, const Mesh &mesh)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_AND_JUNCTIONS
@ SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_JUNCTIONS_AND_CONCAVE
@ eModifierType_ParticleSystem
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
const char * BKE_id_name(const ID &id)
BMesh * BKE_mesh_to_bmesh_ex(const Mesh *mesh, const BMeshCreateParams *create_params, const BMeshFromMeshParams *convert_params)
@ eModifierMode_DisableTemporary
void BKE_id_free(Main *bmain, void *idv)
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
@ SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS
@ SUBSURF_BOUNDARY_SMOOTH_ALL
Material * BKE_object_material_get_eval(Object *ob, short act)
static CLG_LogRef LOG
Definition logging.cpp:12
void BM_mesh_triangulate(BMesh *bm, const int quad_method, const int ngon_method, const int min_vertices, const bool tag_only, BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_facemap_double_out)
VecBase< float, 3 > float3
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Definition object.cc:4436
enum eEvaluationMode evaluation_mode
Definition ABC_alembic.h:55
struct ModifierData * prev
ListBaseT< ModifierData > modifiers
std::vector< Imath::V2f > uvs
std::vector< uint32_t > indices