Blender V5.3
abc_reader_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_reader_mesh.h"
10#include "abc_axis_conversion.h"
11#include "abc_customdata.h"
12#include "abc_util.h"
13
14#include "DNA_material_types.h"
15#include "DNA_modifier_types.h"
16
17#include "DNA_object_types.h"
18
20#include "BLI_listbase.hh"
21#include "BLI_map.hh"
22#include "BLI_math_vector_c.hh"
23#include "BLI_offset_indices.hh"
24#include "BLI_ordered_edge.hh"
25#include "BLI_vector.hh"
26
27#include "BLT_translation.hh"
28
29#include "BKE_customdata.hh"
30#include "BKE_geometry_set.hh"
31#include "BKE_lib_id.hh"
32#include "BKE_main.hh"
33#include "BKE_material.hh"
34#include "BKE_mesh.hh"
35#include "BKE_modifier.hh"
36#include "BKE_object.hh"
37#include "BKE_subdiv.hh"
38
39#include "CLG_log.h"
40#include "IO_validate.hh"
41
42#include <algorithm>
43
44namespace blender {
45
46using Alembic::Abc::FloatArraySamplePtr;
47using Alembic::Abc::IInt32ArrayProperty;
48using Alembic::Abc::Int32ArraySamplePtr;
49using Alembic::Abc::P3fArraySamplePtr;
50using Alembic::Abc::PropertyHeader;
51using Alembic::Abc::V3fArraySamplePtr;
52
53using Alembic::AbcGeom::IC3fGeomParam;
54using Alembic::AbcGeom::IC4fGeomParam;
55using Alembic::AbcGeom::IFaceSet;
56using Alembic::AbcGeom::IFaceSetSchema;
57using Alembic::AbcGeom::IInt32Property;
58using Alembic::AbcGeom::IN3fGeomParam;
59using Alembic::AbcGeom::IObject;
60using Alembic::AbcGeom::IPolyMesh;
61using Alembic::AbcGeom::IPolyMeshSchema;
62using Alembic::AbcGeom::ISampleSelector;
63using Alembic::AbcGeom::ISubD;
64using Alembic::AbcGeom::ISubDSchema;
65using Alembic::AbcGeom::IV2fGeomParam;
66using Alembic::AbcGeom::kWrapExisting;
67using Alembic::AbcGeom::N3fArraySample;
68using Alembic::AbcGeom::N3fArraySamplePtr;
69using Alembic::AbcGeom::UInt32ArraySamplePtr;
70using Alembic::AbcGeom::V2fArraySamplePtr;
71
72namespace io::alembic {
73
74static CLG_LogRef LOG = {"io.alembic"};
75
76/* NOTE: Alembic's face winding order is clockwise, to match with RenderMan. */
77
78/* Some helpers for mesh generation */
79namespace utils {
80
81static std::map<std::string, Material *> build_material_map(const Main *bmain)
82{
83 std::map<std::string, Material *> mat_map;
84 for (Material &material : bmain->materials) {
85 mat_map[material.id.name + 2] = &material;
86 }
87 return mat_map;
88}
89
90static void assign_materials(Main *bmain,
91 Object *ob,
92 const std::map<std::string, int> &mat_index_map)
93{
94 std::map<std::string, int>::const_iterator it;
95 if (mat_index_map.size() > MAXMAT) {
96 return;
97 }
98
99 std::map<std::string, Material *> matname_to_material = build_material_map(bmain);
100 std::map<std::string, Material *>::iterator mat_iter;
101
102 for (it = mat_index_map.begin(); it != mat_index_map.end(); ++it) {
103 const std::string mat_name = it->first;
104 const int mat_index = it->second;
105
106 Material *assigned_mat;
107 mat_iter = matname_to_material.find(mat_name);
108 if (mat_iter == matname_to_material.end()) {
109 assigned_mat = BKE_material_add(bmain, mat_name.c_str());
110 id_us_min(&assigned_mat->id);
111 matname_to_material[mat_name] = assigned_mat;
112 }
113 else {
114 assigned_mat = mat_iter->second;
115 }
116
117 BKE_object_material_assign_single_obdata(bmain, ob, assigned_mat, mat_index);
118 }
119 if (ob->totcol > 0) {
120 ob->actcol = 1;
121 }
122}
123
124} /* namespace utils */
125
134
135 IInt32ArrayProperty face_indices_property;
136 Int32ArraySamplePtr face_indices;
137
138 IInt32ArrayProperty face_counts_property;
139 Int32ArraySamplePtr face_counts;
140
141 /* Optional settings for reading interpolated vertices. If present, `ceil_positions` has to be
142 * valid. */
143 std::optional<SampleInterpolationSettings> interpolation_settings;
144 P3fArraySamplePtr positions;
145 P3fArraySamplePtr ceil_positions;
146
147 IV2fGeomParam uvs_param;
148 IN3fGeomParam normals_param;
149 V3fArraySamplePtr velocities;
150
151 ICompoundProperty arb_geom_params;
152};
153
154static void read_mverts_interp(float3 *vert_positions,
155 const P3fArraySamplePtr &positions,
156 const P3fArraySamplePtr &ceil_positions,
157 const double weight)
158{
159 float tmp[3];
160 for (int i = 0; i < positions->size(); i++) {
161 const Imath::V3f &floor_pos = (*positions)[i];
162 const Imath::V3f &ceil_pos = (*ceil_positions)[i];
163
164 interp_v3_v3v3(tmp, floor_pos.getValue(), ceil_pos.getValue(), float(weight));
165 copy_zup_from_yup(vert_positions[i], tmp);
166 }
167}
168
169static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data)
170{
171 float3 *vert_positions = config.positions;
172 const P3fArraySamplePtr &positions = mesh_data.positions;
173
174 if (mesh_data.interpolation_settings.has_value()) {
176 mesh_data.ceil_positions != nullptr,
177 "AbcMeshData does not have ceil positions although it has some interpolation settings.");
178
179 const double weight = mesh_data.interpolation_settings->weight;
180 read_mverts_interp(vert_positions, positions, mesh_data.ceil_positions, weight);
181 config.mesh->tag_positions_changed();
182 return;
183 }
184
185 read_mverts(*config.mesh, positions, nullptr);
186}
187
188void read_mverts(Mesh &mesh, const P3fArraySamplePtr positions, const N3fArraySamplePtr normals)
189{
190 MutableSpan<float3> vert_positions = mesh.vert_positions_for_write();
191 for (int i = 0; i < positions->size(); i++) {
192 Imath::V3f pos_in = (*positions)[i];
193
194 copy_zup_from_yup(vert_positions[i], pos_in.getValue());
195 }
196 mesh.tag_positions_changed();
197
198 if (normals) {
199 Vector<float3> vert_normals(mesh.verts_num);
200 for (const int64_t i : IndexRange(normals->size())) {
201 Imath::V3f nor_in = (*normals)[i];
202 copy_zup_from_yup(vert_normals[i], nor_in.getValue());
203 }
204 bke::mesh_vert_normals_assign(mesh, std::move(vert_normals));
205 }
206}
207
208/* Update references to mesh data. */
210{
211 config.positions = config.mesh->vert_positions_for_write().data();
212 config.corner_verts = config.mesh->corner_verts_for_write().data();
213 config.face_offsets = config.mesh->face_offsets_for_write().data();
214 config.totvert = config.mesh->verts_num;
215 config.totloop = config.mesh->corners_num;
216 config.faces_num = config.mesh->faces_num;
217}
218
220{
221 CDStreamConfig config;
222 config.mesh = mesh;
223 config_reload_mesh(config);
224
225 return config;
226}
227
228static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data)
229{
230 int *face_offsets = config.face_offsets;
231 int *corner_verts = config.corner_verts;
232 float2 *uv_maps = config.uv_map.span.data();
233
234 const Int32ArraySamplePtr &face_indices = mesh_data.face_indices;
235 const Int32ArraySamplePtr &face_counts = mesh_data.face_counts;
236 const V2fArraySamplePtr &uvs = config.uvs;
237 const int64_t uvs_size = uvs == nullptr ? 0 : int64_t(uvs->size());
238
239 const UInt32ArraySamplePtr &uvs_indices = config.uvs_indices;
240 const int64_t uvs_indices_size = uvs_indices == nullptr ? 0 : int64_t(uvs_indices->size());
241
242 const bool do_uvs = (uv_maps && uvs && uvs_indices);
243 const bool do_uvs_per_loop = do_uvs && config.uv_scope == ABC_UV_SCOPE_LOOP;
244 BLI_assert(!do_uvs || config.uv_scope != ABC_UV_SCOPE_NONE);
245 int64_t loop_index = 0;
246 int64_t rev_loop_index = 0;
247
248 const int64_t corners_num = int64_t(face_indices->size());
249
250 for (int64_t i = 0; i < face_counts->size(); i++) {
251 int face_size = (*face_counts)[i];
252
253 face_offsets[i] = loop_index;
254
255 /* Polygons are always assumed to be smooth-shaded. If the Alembic mesh should be flat-shaded,
256 * this is encoded in custom loop normals. See #71246. */
257
258 /* NOTE: Alembic data is stored in the reverse order. */
259 if (face_size > 0 && face_size <= corners_num - loop_index) {
260 rev_loop_index = loop_index + (face_size - 1);
261 }
262 else {
263 rev_loop_index = loop_index;
264 face_size = 0;
265 }
266
267 const int64_t last_vertex_index = 0;
268 for (int64_t f = 0; f < face_size; f++, loop_index++, rev_loop_index--) {
269 int vert = (*face_indices)[loop_index];
270 if (!validate::index_in_range(vert, config.mesh->verts_num)) {
271 vert = 0;
272 }
273 corner_verts[rev_loop_index] = vert;
274
275 if (do_uvs) {
276 const int64_t lookup_index = do_uvs_per_loop ? loop_index : last_vertex_index;
277 if (!validate::index_in_range(lookup_index, uvs_indices_size)) {
278 continue;
279 }
280 const int64_t uv_index = (*uvs_indices)[lookup_index];
281
282 /* Some Alembic files are broken (or at least export UVs in a way we don't expect). */
283 if (!validate::index_in_range(uv_index, uvs_size)) {
284 continue;
285 }
286
287 uv_maps[rev_loop_index][0] = (*uvs)[uv_index][0];
288 uv_maps[rev_loop_index][1] = (*uvs)[uv_index][1];
289 }
290 }
291 }
292
293 config.uv_map.finish();
294
295 /* Check for faces with duplicate vertex indices. These will require a mesh validate to fix. */
296 IndexMaskMemory memory;
297 const IndexMask bad_faces = bke::mesh_find_faces_duplicate_verts(*config.mesh, memory);
298 const bool all_faces_ok = bad_faces.is_empty();
299
300 /* If we detect bad faces it would be unsafe to continue beyond this point without first
301 * performing a destructive validate. Any operation requiring mesh connectivity information can
302 * assert or crash if the problem isn't addressed. Performing the check here, before most of the
303 * data has been loaded, unfortunately means any remaining data will be lost. */
304 if (!all_faces_ok) {
305 if (config.modifier_error_message) {
306 *config.modifier_error_message = "Mesh has invalid geometry";
307 }
308 bke::mesh_validate(*config.mesh, false);
309
310 config_reload_mesh(config);
311 }
312
313 bke::mesh_calc_edges(*config.mesh, false, false);
314}
315
316static void process_no_normals(CDStreamConfig & /*config*/)
317{
318 /* Absence of normals in the Alembic mesh is interpreted as 'smooth'. */
319}
320
321static void process_loop_normals(CDStreamConfig &config, const N3fArraySamplePtr loop_normals_ptr)
322{
323 size_t loop_count = loop_normals_ptr->size();
324
325 if (loop_count == 0) {
326 process_no_normals(config);
327 return;
328 }
329
330 Mesh *mesh = config.mesh;
331 if (loop_count != mesh->corners_num) {
332 /* This happens in certain Houdini exports. When a mesh is animated and then replaced by a
333 * fluid simulation, Houdini will still write the original mesh's loop normals, but the mesh
334 * verts/loops/faces are from the simulation. In such cases the normals cannot be mapped to the
335 * mesh, so it's better to ignore them. */
336 process_no_normals(config);
337 return;
338 }
339
340 Array<float3> corner_normals(loop_count);
341
342 const OffsetIndices faces = mesh->faces();
343 const N3fArraySample &loop_normals = *loop_normals_ptr;
344 int abc_index = 0;
345 for (int i = 0, e = mesh->faces_num; i < e; i++) {
346 const IndexRange face = faces[i];
347 /* As usual, ABC orders the loops in reverse. */
348 for (int j = face.size() - 1; j >= 0; j--, abc_index++) {
349 int blender_index = face[j];
350 copy_zup_from_yup(corner_normals[blender_index], loop_normals[abc_index].getValue());
351 }
352 }
353
354 bke::mesh_set_custom_normals(*mesh, corner_normals);
355}
356
358 const N3fArraySamplePtr vertex_normals_ptr)
359{
360 size_t normals_count = vertex_normals_ptr->size();
361 if (normals_count == 0) {
362 process_no_normals(config);
363 return;
364 }
365
366 Array<float3> vert_normals(normals_count);
367
368 const N3fArraySample &vertex_normals = *vertex_normals_ptr;
369 for (int index = 0; index < normals_count; index++) {
370 copy_zup_from_yup(vert_normals[index], vertex_normals[index].getValue());
371 }
372
373 bke::mesh_set_custom_normals_from_verts(*config.mesh, vert_normals);
374}
375
376static void process_normals(CDStreamConfig &config,
377 const IN3fGeomParam &normals,
378 const ISampleSelector &selector)
379{
380 if (!normals.valid()) {
381 process_no_normals(config);
382 return;
383 }
384
385 IN3fGeomParam::Sample normsamp = normals.getExpandedValue(selector);
386 Alembic::AbcGeom::GeometryScope scope = normals.getScope();
387
388 switch (scope) {
389 case Alembic::AbcGeom::kFacevaryingScope: /* 'Vertex Normals' in Houdini. */
390 process_loop_normals(config, normsamp.getVals());
391 break;
392 case Alembic::AbcGeom::kVertexScope:
393 case Alembic::AbcGeom::kVaryingScope: /* 'Point Normals' in Houdini. */
394 process_vertex_normals(config, normsamp.getVals());
395 break;
396 case Alembic::AbcGeom::kConstantScope:
397 case Alembic::AbcGeom::kUniformScope:
398 case Alembic::AbcGeom::kUnknownScope:
399 process_no_normals(config);
400 break;
401 }
402}
403
405 const IV2fGeomParam &uv,
406 const ISampleSelector &selector)
407{
408 if (!uv.valid()) {
409 return;
410 }
411
412 IV2fGeomParam::Sample uvsamp;
413 uv.getIndexed(uvsamp, selector);
414
415 UInt32ArraySamplePtr uvs_indices = uvsamp.getIndices();
416
417 const AbcUvScope uv_scope = get_uv_scope(uv.getScope(), config, uvs_indices);
418
419 if (uv_scope == ABC_UV_SCOPE_NONE) {
420 return;
421 }
422
423 config.uv_scope = uv_scope;
424 config.uvs = uvsamp.getVals();
425 config.uvs_indices = uvs_indices;
426
427 std::string name = Alembic::Abc::GetSourceName(uv.getMetaData());
428
429 /* According to the convention, primary UVs should have had their name
430 * set using Alembic::Abc::SetSourceName, but you can't expect everyone
431 * to follow it! :) */
432 if (name.empty()) {
433 name = uv.getName();
434 }
435
436 bke::MutableAttributeAccessor attributes = config.mesh->attributes_for_write();
438 config.mesh->uv_maps_active_set(name);
439 config.mesh->uv_maps_default_set(name);
440}
441
442template<typename SampleType>
443static bool samples_have_same_topology(const SampleType &sample, const SampleType &ceil_sample)
444{
445 const P3fArraySamplePtr &positions = sample.getPositions();
446 const Alembic::Abc::Int32ArraySamplePtr &face_indices = sample.getFaceIndices();
447 const Alembic::Abc::Int32ArraySamplePtr &face_counts = sample.getFaceCounts();
448
449 const P3fArraySamplePtr &ceil_positions = ceil_sample.getPositions();
450 const Alembic::Abc::Int32ArraySamplePtr &ceil_face_indices = ceil_sample.getFaceIndices();
451 const Alembic::Abc::Int32ArraySamplePtr &ceil_face_counts = ceil_sample.getFaceCounts();
452
453 /* It the counters are different, we can be sure the topology is different. */
454 const bool different_counters = positions->size() != ceil_positions->size() ||
455 face_counts->size() != ceil_face_counts->size() ||
456 face_indices->size() != ceil_face_indices->size();
457 if (different_counters) {
458 return false;
459 }
460
461 /* Otherwise, we need to check the connectivity as files from e.g. videogrammetry may have the
462 * same face count, but different connections between faces. */
463
464 if (memcmp(face_counts->get(), ceil_face_counts->get(), face_counts->size() * sizeof(int)) != 0)
465 {
466 return false;
467 }
468
469 if (memcmp(face_indices->get(), ceil_face_indices->get(), face_indices->size() * sizeof(int)) !=
470 0)
471 {
472 return false;
473 }
474
475 return true;
476}
477
478static bool topology_changed(const AbcMeshData &abc_mesh_data,
479 const Mesh *existing_mesh,
480 const bool is_reading_a_file_sequence)
481{
482 const P3fArraySamplePtr &positions = abc_mesh_data.positions;
483 const Int32ArraySamplePtr &face_indices = abc_mesh_data.face_indices;
484 const Int32ArraySamplePtr &face_counts = abc_mesh_data.face_counts;
485
486 /* It the counters are different, we can be sure the topology is different. */
487 const bool different_counters = positions->size() != existing_mesh->verts_num ||
488 face_counts->size() != existing_mesh->faces_num ||
489 face_indices->size() != existing_mesh->corners_num;
490 if (different_counters) {
491 return true;
492 }
493
494 /* Check first if we indeed have multiple samples, unless we read a file sequence in which case
495 * we need to do a full topology comparison. */
496 if (!is_reading_a_file_sequence && (abc_mesh_data.face_indices_property.getNumSamples() == 1 &&
497 abc_mesh_data.face_counts_property.getNumSamples() == 1))
498 {
499 return false;
500 }
501
502 /* Otherwise, we need to check the connectivity as files from e.g. videogrammetry may have the
503 * same face count, but different connections between faces. */
504 int64_t abc_index = 0;
505
506 const int *mesh_corner_verts = existing_mesh->corner_verts().data();
507 const int *mesh_face_offsets = existing_mesh->face_offsets().data();
508 const int64_t mesh_corners_num = existing_mesh->corners_num;
509 const int64_t abc_corners_num = int64_t(face_indices->size());
510
511 for (int64_t i = 0; i < face_counts->size(); i++) {
512 if (mesh_face_offsets[i] != abc_index) {
513 return true;
514 }
515
516 const int abc_face_size = (*face_counts)[i];
517 /* If the file's face_counts would advance abc_index past either array, the topology must
518 * differ from the existing mesh; treat as changed rather than read out of bounds. */
519 if (abc_face_size < 0 || abc_face_size > abc_corners_num - abc_index ||
520 abc_face_size > mesh_corners_num - abc_index)
521 {
522 return true;
523 }
524 /* NOTE: Alembic data is stored in the reverse order. */
525 int64_t rev_loop_index = abc_index + (abc_face_size > 0 ? abc_face_size - 1 : 0);
526 for (int64_t f = 0; f < abc_face_size; f++, abc_index++, rev_loop_index--) {
527 const int mesh_vert = mesh_corner_verts[rev_loop_index];
528 const int abc_vert = (*face_indices)[abc_index];
529 if (mesh_vert != abc_vert) {
530 return true;
531 }
532 }
533 }
534
535 return false;
536}
537
538static Mesh *read_mesh_sample(const AbcMeshData &abc_mesh_data,
539 const ISampleSelector &selector,
540 const AbcReadGeometryParams &read_params,
541 Mesh *existing_mesh,
542 const char **r_err_str,
543 const bool is_reading_a_file_sequence)
544{
545 const P3fArraySamplePtr &positions = abc_mesh_data.positions;
546 const Int32ArraySamplePtr &face_indices = abc_mesh_data.face_indices;
547 const Int32ArraySamplePtr &face_counts = abc_mesh_data.face_counts;
548
549 /* Do some very minimal mesh validation. */
550 const int64_t poly_count = face_counts->size();
551 const int64_t loop_count = face_indices->size();
552 const int64_t vert_count = positions->size();
553 if (!validate::size_fits_in_int(poly_count) || !validate::size_fits_in_int(loop_count) ||
554 !validate::size_fits_in_int(vert_count))
555 {
556 if (r_err_str != nullptr) {
557 *r_err_str = RPT_("Mesh too large; more detail on the console");
558 }
559 CLOG_WARN(&LOG,
560 "Mesh too large for '%s/%s' at time %f, exceeds max int size",
561 abc_mesh_data.iobject_full_name.data(),
562 abc_mesh_data.schema_name.data(),
563 selector.getRequestedTime());
564 return existing_mesh;
565 }
566 /* This is the same test as in poly_to_tri_count(). */
567 if (poly_count > 0 && loop_count < poly_count * 2) {
568 if (r_err_str != nullptr) {
569 *r_err_str = RPT_("Invalid mesh; more detail on the console");
570 }
571 CLOG_WARN(&LOG,
572 "Invalid mesh sample for '%s/%s' at time %f, less than 2 loops per face",
573 abc_mesh_data.iobject_full_name.data(),
574 abc_mesh_data.schema_name.data(),
575 selector.getRequestedTime());
576 return existing_mesh;
577 }
578
579 Mesh *new_mesh = nullptr;
580
581 /* Only read point data when streaming meshes, unless we need to create new ones. */
582 int read_flag = read_params.read_flag;
583
584 if (topology_changed(abc_mesh_data, existing_mesh, is_reading_a_file_sequence)) {
586 existing_mesh, positions->size(), 0, face_counts->size(), face_indices->size());
587
588 read_flag |= MOD_MESHSEQ_READ_ALL;
589 }
590 else {
591 /* If the face count changed (e.g. by triangulation), only read points.
592 * This prevents crash from #49813.
593 * TODO(kevin): perhaps find a better way to do this? */
594 if (face_counts->size() != existing_mesh->faces_num ||
595 face_indices->size() != existing_mesh->corners_num)
596 {
597 read_flag = MOD_MESHSEQ_READ_VERT;
598
599 if (r_err_str) {
600 *r_err_str = RPT_(
601 "Topology has changed, perhaps by triangulating the mesh. Only vertices will be "
602 "read!");
603 }
604 }
605 }
606
607 Mesh *mesh_to_export = new_mesh ? new_mesh : existing_mesh;
608 CDStreamConfig config = get_config(mesh_to_export);
609 config.time = selector.getRequestedTime();
610 config.modifier_error_message = r_err_str;
611
612 if ((read_flag & MOD_MESHSEQ_READ_UV) != 0) {
613 read_uvs_params(config, abc_mesh_data.uvs_param, selector);
614 }
615
616 if ((read_flag & MOD_MESHSEQ_READ_VERT) != 0) {
617 read_mverts(config, abc_mesh_data);
618 read_generated_coordinates(abc_mesh_data.arb_geom_params, config, selector);
619 }
620
621 if ((read_flag & MOD_MESHSEQ_READ_POLY) != 0) {
622 read_mpolys(config, abc_mesh_data);
623 process_normals(config, abc_mesh_data.normals_param, selector);
624 }
625
626 if ((read_flag & (MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)) != 0) {
628 abc_mesh_data.iobject_full_name, abc_mesh_data.arb_geom_params, config, selector);
629 }
630
631 if (abc_mesh_data.velocities) {
632 read_velocity(abc_mesh_data.velocities, config, read_params.velocity_scale);
633 }
634
635 return mesh_to_export;
636}
637
638/* ************************************************************************** */
639
640static AbcMeshData extract_mesh_data(const IObject &iobject,
641 const IPolyMeshSchema &schema,
642 const ISampleSelector &selector,
643 const AbcReadGeometryParams &params,
644 const bool for_topology_check)
645{
646 IPolyMeshSchema::Sample sample = schema.getValue(selector);
647
649 result.positions = sample.getPositions();
650 result.face_indices_property = schema.getFaceIndicesProperty();
651 result.face_indices = sample.getFaceIndices();
652 result.face_counts_property = schema.getFaceCountsProperty();
653 result.face_counts = sample.getFaceCounts();
654
655 if (!for_topology_check) {
656 result.iobject_full_name = iobject.getFullName();
657 result.schema_name = schema.getName();
658 result.arb_geom_params = schema.getArbGeomParams();
659 result.uvs_param = schema.getUVsParam();
660 result.normals_param = schema.getNormalsParam();
661
662 if (!params.velocity_name.empty() && params.velocity_scale != 0.0f) {
663 result.velocities = get_velocity_prop(schema, selector, params.velocity_name);
664 }
665
666 const std::optional<SampleInterpolationSettings> interpolation_settings =
668 selector, schema.getTimeSampling(), schema.getNumSamples());
669
670 const bool use_vertex_interpolation = params.read_flag & MOD_MESHSEQ_INTERPOLATE_VERTICES;
671 if (use_vertex_interpolation && interpolation_settings.has_value()) {
672 IPolyMeshSchema::Sample ceil_sample;
673 schema.get(ceil_sample, ISampleSelector(interpolation_settings->ceil_index));
674 if (samples_have_same_topology(sample, ceil_sample)) {
675 /* Only set interpolation data if the samples are compatible. */
676 result.ceil_positions = ceil_sample.getPositions();
677 result.interpolation_settings = interpolation_settings;
678 }
679 }
680 }
681
682 return result;
683}
684
686{
688
689 IPolyMesh ipoly_mesh(m_iobject, kWrapExisting);
690 m_schema = ipoly_mesh.getSchema();
691}
692
694{
695 return m_schema.valid();
696}
697
698template<class typedGeomParam>
699bool is_valid_animated(const ICompoundProperty arbGeomParams, const PropertyHeader &prop_header)
700{
701 if (!typedGeomParam::matches(prop_header)) {
702 return false;
703 }
704
705 typedGeomParam geom_param(arbGeomParams, prop_header.getName());
706 return geom_param.valid() && !geom_param.isConstant();
707}
708
709static bool has_animated_geom_params(const ICompoundProperty arbGeomParams)
710{
711 if (!arbGeomParams.valid()) {
712 return false;
713 }
714
715 const int num_props = arbGeomParams.getNumProperties();
716 for (int i = 0; i < num_props; i++) {
717 const PropertyHeader &prop_header = arbGeomParams.getPropertyHeader(i);
718
719 /* These are interpreted as vertex colors later (see 'read_custom_data'). */
720 if (is_valid_animated<IC3fGeomParam>(arbGeomParams, prop_header)) {
721 return true;
722 }
723 if (is_valid_animated<IC4fGeomParam>(arbGeomParams, prop_header)) {
724 return true;
725 }
726 }
727
728 return false;
729}
730
731/* Copy of #IPolyMeshSchema::getFaceSetNames(), to avoid ASAN false positive
732 * when the std::vector is passed from ASAN enabled Blender code to the
733 * Alembic library built without ASAN. */
734static Vector<std::string> get_face_set_names(const IPolyMeshSchema &schema)
735{
736 const IObject object = schema.getObject();
737
739 for (size_t i = 0; i < object.getNumChildren(); i++) {
740 const Alembic::AbcCoreAbstract::ObjectHeader &header = object.getChildHeader(i);
741 if (IFaceSet::matches(header)) {
742 names.append(header.getName());
743 }
744 }
745
746 std::sort(names.begin(), names.end());
747 return names;
748}
749
750/* Specialization of #has_animations() as defined in abc_reader_object.h. */
751template<> bool has_animations(Alembic::AbcGeom::IPolyMeshSchema &schema, ImportSettings *settings)
752{
753 if (settings->is_sequence || !schema.isConstant()) {
754 return true;
755 }
756
757 for (const std::string &face_set_name : get_face_set_names(schema)) {
758 const IFaceSet face_set = schema.getFaceSet(face_set_name);
759 const IFaceSetSchema &face_set_schema = face_set.getSchema();
760 if (!face_set_schema.isConstant()) {
761 return true;
762 }
763 }
764
765 IV2fGeomParam uvsParam = schema.getUVsParam();
766 if (uvsParam.valid() && !uvsParam.isConstant()) {
767 return true;
768 }
769
770 IN3fGeomParam normalsParam = schema.getNormalsParam();
771 if (normalsParam.valid() && !normalsParam.isConstant()) {
772 return true;
773 }
774
775 ICompoundProperty arbGeomParams = schema.getArbGeomParams();
776 if (has_animated_geom_params(arbGeomParams)) {
777 return true;
778 }
779
780 return false;
781}
782
783template<> bool has_animations(Alembic::AbcGeom::ISubDSchema &schema, ImportSettings *settings)
784{
785 if (settings->is_sequence || !schema.isConstant()) {
786 return true;
787 }
788
789 IV2fGeomParam uvsParam = schema.getUVsParam();
790 if (uvsParam.valid() && !uvsParam.isConstant()) {
791 return true;
792 }
793
794 Alembic::AbcGeom::IInt32ArrayProperty creaseIndices = schema.getCreaseIndicesProperty();
795 if (creaseIndices.valid() && !creaseIndices.isConstant()) {
796 return true;
797 }
798 Alembic::AbcGeom::IFloatArrayProperty creaseSharpnesses = schema.getCreaseSharpnessesProperty();
799 if (creaseSharpnesses.valid() && !creaseSharpnesses.isConstant()) {
800 return true;
801 }
802
803 Alembic::AbcGeom::IInt32ArrayProperty cornerIndices = schema.getCornerIndicesProperty();
804 if (cornerIndices.valid() && !cornerIndices.isConstant()) {
805 return true;
806 }
807 Alembic::AbcGeom::IFloatArrayProperty cornerSharpnesses = schema.getCornerSharpnessesProperty();
808 if (cornerSharpnesses.valid() && !cornerSharpnesses.isConstant()) {
809 return true;
810 }
811
812 ICompoundProperty arbGeomParams = schema.getArbGeomParams();
813 if (has_animated_geom_params(arbGeomParams)) {
814 return true;
815 }
816
817 return false;
818}
819
820void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
821{
822 Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
823
825 m_object->data = id_cast<ID *>(mesh);
826
827 AbcReadGeometryParams read_params{};
828 read_params.read_flag = MOD_MESHSEQ_READ_ALL;
829
830 Mesh *read_mesh = this->read_mesh(mesh, sample_sel, read_params, nullptr);
831 if (read_mesh != mesh) {
833 }
834
836 bke::mesh_validate(*mesh, false);
837 }
838
839 readFaceSetsSample(bmain, mesh, sample_sel);
840
843 }
844
845 ICompoundProperty user_props = m_schema.getUserProperties();
846 read_active_and_default_color_attributes(*mesh, user_props, sample_sel);
847}
848
850 const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
851 const Object *const ob,
852 const char **r_err_str) const
853{
854 if (!Alembic::AbcGeom::IPolyMesh::matches(alembic_header)) {
855 *r_err_str = RPT_(
856 "Object type mismatch, Alembic object path pointed to PolyMesh when importing, but not "
857 "any more");
858 return false;
859 }
860
861 if (ob->type != OB_MESH) {
862 *r_err_str = RPT_("Object type mismatch, Alembic object path points to PolyMesh");
863 return false;
864 }
865
866 return true;
867}
868
869bool AbcMeshReader::topology_changed(const Mesh *existing_mesh, const ISampleSelector &sample_sel)
870{
871 AbcMeshData abc_mesh_data;
872 try {
873 AbcReadGeometryParams read_params{};
874 abc_mesh_data = extract_mesh_data(m_iobject, m_schema, sample_sel, read_params, true);
875 }
876 catch (Alembic::Util::Exception &ex) {
877 CLOG_WARN(&LOG,
878 "Error reading mesh sample for '%s/%s' at time %f: %s",
879 m_iobject.getFullName().c_str(),
880 m_schema.getName().c_str(),
881 sample_sel.getRequestedTime(),
882 ex.what());
883 /* A similar error in read_mesh() would just return existing_mesh. */
884 return false;
885 }
886
887 return alembic::topology_changed(abc_mesh_data, existing_mesh, m_is_reading_a_file_sequence);
888}
889
891 const Alembic::Abc::ISampleSelector &sample_sel,
892 const AbcReadGeometryParams &read_params,
893 const char **r_err_str)
894{
895 Mesh *mesh = geometry_set.get_mesh_for_write();
896
897 if (mesh == nullptr) {
898 return;
899 }
900
901 Mesh *new_mesh = read_mesh(mesh, sample_sel, read_params, r_err_str);
902
903 geometry_set.replace_mesh(new_mesh);
904}
905
907 const ISampleSelector &sample_sel,
908 const AbcReadGeometryParams &read_params,
909 const char **r_err_str)
910{
911 AbcMeshData abc_mesh_data;
912 try {
913 abc_mesh_data = extract_mesh_data(m_iobject, m_schema, sample_sel, read_params, false);
914 }
915 catch (Alembic::Util::Exception &ex) {
916 if (r_err_str != nullptr) {
917 *r_err_str = RPT_("Error reading mesh sample; more detail on the console");
918 }
919 CLOG_WARN(&LOG,
920 "Error reading mesh sample for '%s/%s' at time %f: %s",
921 m_iobject.getFullName().c_str(),
922 m_schema.getName().c_str(),
923 sample_sel.getRequestedTime(),
924 ex.what());
925 return existing_mesh;
926 }
927
928 Mesh *new_mesh = read_mesh_sample(abc_mesh_data,
929 sample_sel,
930 read_params,
931 existing_mesh,
932 r_err_str,
934
935 /* Here we assume that the number of materials doesn't change, i.e. that
936 * the material slots that were created when the object was loaded from
937 * Alembic are still valid now. */
938 size_t num_faces = new_mesh->faces_num;
939 if (num_faces > 0) {
940 std::map<std::string, int> mat_map;
941 bke::MutableAttributeAccessor attributes = new_mesh->attributes_for_write();
942 bke::SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
943 "material_index", bke::AttrDomain::Face);
944 assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map);
945 material_indices.finish();
946 }
947
948 if (new_mesh != existing_mesh) {
949 return new_mesh;
950 }
951
952 return existing_mesh;
953}
954
955void AbcMeshReader::assign_facesets_to_material_indices(const ISampleSelector &sample_sel,
956 MutableSpan<int> material_indices,
957 std::map<std::string, int> &r_mat_map)
958{
959 const Vector<std::string> face_sets = get_face_set_names(m_schema);
960
961 if (face_sets.is_empty()) {
962 return;
963 }
964
965 int current_mat = 0;
966
967 /* Avoid preserving old assignments. */
968 material_indices.fill(0);
969
970 for (const std::string &grp_name : face_sets) {
971 if (!r_mat_map.contains(grp_name)) {
972 r_mat_map[grp_name] = ++current_mat;
973 }
974
975 const int assigned_mat = r_mat_map[grp_name];
976
977 const IFaceSet faceset = m_schema.getFaceSet(grp_name);
978
979 if (!faceset.valid()) {
980 std::cerr << " Face set " << grp_name << " invalid for " << m_object_name << "\n";
981 continue;
982 }
983
984 const IFaceSetSchema face_schem = faceset.getSchema();
985 const IFaceSetSchema::Sample face_sample = face_schem.getValue(sample_sel);
986 const Int32ArraySamplePtr group_faces = face_sample.getFaces();
987 const size_t num_group_faces = group_faces->size();
988
989 for (size_t l = 0; l < num_group_faces; l++) {
990 size_t pos = (*group_faces)[l];
991
992 if (pos >= material_indices.size()) {
993 std::cerr << "Faceset overflow on " << faceset.getName() << '\n';
994 break;
995 }
996
997 material_indices[pos] = assigned_mat - 1;
998 }
999 }
1000}
1001
1002void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const ISampleSelector &sample_sel)
1003{
1004 std::map<std::string, int> mat_map;
1005 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1006 bke::SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
1007 "material_index", bke::AttrDomain::Face);
1008 assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map);
1009 material_indices.finish();
1010 utils::assign_materials(bmain, m_object, mat_map);
1011}
1012
1013/* ************************************************************************** */
1014
1015static AbcMeshData extract_mesh_data(const IObject &iobject,
1016 const ISubDSchema &schema,
1017 const ISampleSelector &selector,
1018 const AbcReadGeometryParams &params,
1019 const bool for_topology_check)
1020{
1021 ISubDSchema::Sample sample = schema.getValue(selector);
1022
1024 result.positions = sample.getPositions();
1025 result.face_indices_property = schema.getFaceIndicesProperty();
1026 result.face_indices = sample.getFaceIndices();
1027 result.face_counts_property = schema.getFaceCountsProperty();
1028 result.face_counts = sample.getFaceCounts();
1029
1030 if (!for_topology_check) {
1031 result.iobject_full_name = iobject.getFullName();
1032 result.schema_name = schema.getName();
1033 result.arb_geom_params = schema.getArbGeomParams();
1034 result.uvs_param = schema.getUVsParam();
1035
1036 if (!params.velocity_name.empty() && params.velocity_scale != 0.0f) {
1037 result.velocities = get_velocity_prop(schema, selector, params.velocity_name);
1038 }
1039
1040 const std::optional<SampleInterpolationSettings> interpolation_settings =
1042 selector, schema.getTimeSampling(), schema.getNumSamples());
1043
1044 const bool use_vertex_interpolation = params.read_flag & MOD_MESHSEQ_INTERPOLATE_VERTICES;
1045 if (use_vertex_interpolation && interpolation_settings.has_value()) {
1046 ISubDSchema::Sample ceil_sample;
1047 schema.get(ceil_sample, Alembic::Abc::ISampleSelector(interpolation_settings->ceil_index));
1048 if (samples_have_same_topology(sample, ceil_sample)) {
1049 /* Only set interpolation data if the samples are compatible. */
1050 result.ceil_positions = ceil_sample.getPositions();
1051 result.interpolation_settings = interpolation_settings.value();
1052 }
1053 }
1054 }
1055
1056 return result;
1057}
1058
1060 const Int32ArraySamplePtr &indices,
1061 const FloatArraySamplePtr &sharpnesses,
1062 const ImportSettings *settings)
1063{
1064 if (!(indices && sharpnesses && indices->size() == sharpnesses->size() && indices->size() != 0))
1065 {
1066 return;
1067 }
1068
1069 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1071 "crease_vert", bke::AttrDomain::Point);
1072 creases.span.fill(0.0f);
1073
1074 const int totvert = mesh->verts_num;
1075 const int64_t indices_num = indices->size();
1076
1077 for (int64_t i = 0, v = indices_num; i < v; ++i) {
1078 const int idx = (*indices)[i];
1079
1080 if (!validate::index_in_range(idx, totvert)) {
1081 continue;
1082 }
1083
1084 const float crease = settings->blender_archive_version_prior_44 ?
1085 (*sharpnesses)[i] :
1086 bke::subdiv::sharpness_to_crease((*sharpnesses)[i]);
1087 creases.span[idx] = std::clamp(crease, 0.0f, 1.0f);
1088 }
1089
1090 creases.finish();
1091}
1092
1094 const Int32ArraySamplePtr &indices,
1095 const FloatArraySamplePtr &sharpnesses,
1096 const ImportSettings *settings)
1097{
1098 if (!(indices && sharpnesses)) {
1099 return;
1100 }
1101
1102 const Span<int2> edges = mesh->edges_for_write();
1103 Map<OrderedEdge, int> edge_hash;
1104 edge_hash.reserve(edges.size());
1105 for (const int i : edges.index_range()) {
1106 edge_hash.add(edges[i], i);
1107 }
1108
1109 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1111 "crease_edge", bke::AttrDomain::Edge);
1112
1113 const int64_t sharp_num = int64_t(sharpnesses->size());
1114 const int64_t indices_num = int64_t(indices->size());
1115 for (int64_t i = 0, s = 0; i + 1 < indices_num && s < sharp_num; i += 2, s++) {
1116 int v1 = (*indices)[i];
1117 int v2 = (*indices)[i + 1];
1118 const int *index = edge_hash.lookup_ptr({v1, v2});
1119 if (!index) {
1120 continue;
1121 }
1122
1123 const float crease = settings->blender_archive_version_prior_44 ?
1124 (*sharpnesses)[s] :
1125 bke::subdiv::sharpness_to_crease((*sharpnesses)[s]);
1126 creases.span[*index] = std::clamp(crease, 0.0f, 1.0f);
1127 }
1128
1129 creases.finish();
1130}
1131
1132/* ************************************************************************** */
1133
1135{
1137
1138 ISubD isubd_mesh(m_iobject, kWrapExisting);
1139 m_schema = isubd_mesh.getSchema();
1140}
1141
1143{
1144 return m_schema.valid();
1145}
1146
1148 const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
1149 const Object *const ob,
1150 const char **r_err_str) const
1151{
1152 if (!Alembic::AbcGeom::ISubD::matches(alembic_header)) {
1153 *r_err_str = RPT_(
1154 "Object type mismatch, Alembic object path pointed to SubD when importing, but not any "
1155 "more");
1156 return false;
1157 }
1158
1159 if (ob->type != OB_MESH) {
1160 *r_err_str = RPT_("Object type mismatch, Alembic object path points to SubD");
1161 return false;
1162 }
1163
1164 return true;
1165}
1166
1167void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
1168{
1169 Mesh *mesh = BKE_mesh_add(bmain, m_data_name.c_str());
1170
1172 m_object->data = id_cast<ID *>(mesh);
1173
1174 AbcReadGeometryParams read_params{};
1175 read_params.read_flag = MOD_MESHSEQ_READ_ALL;
1176
1177 Mesh *read_mesh = this->read_mesh(mesh, sample_sel, read_params, nullptr);
1178 if (read_mesh != mesh) {
1180 }
1181
1183 bke::mesh_validate(*mesh, false);
1184 }
1185
1188 }
1189
1190 add_subdiv_modifier();
1191
1192 ICompoundProperty user_props = m_schema.getUserProperties();
1193 read_active_and_default_color_attributes(*mesh, user_props, sample_sel);
1194}
1195
1196bool AbcSubDReader::topology_changed(const Mesh *existing_mesh, const ISampleSelector &sample_sel)
1197{
1198 AbcMeshData abc_mesh_data;
1199 try {
1200 AbcReadGeometryParams read_params{};
1201 abc_mesh_data = extract_mesh_data(m_iobject, m_schema, sample_sel, read_params, true);
1202 }
1203 catch (Alembic::Util::Exception &ex) {
1204 CLOG_WARN(&LOG,
1205 "Error reading mesh sample for '%s/%s' at time %f: %s",
1206 m_iobject.getFullName().c_str(),
1207 m_schema.getName().c_str(),
1208 sample_sel.getRequestedTime(),
1209 ex.what());
1210 /* A similar error in read_mesh() would just return existing_mesh. */
1211 return false;
1212 }
1213
1214 return alembic::topology_changed(abc_mesh_data, existing_mesh, m_is_reading_a_file_sequence);
1215}
1216
1217Mesh *AbcSubDReader::read_mesh(Mesh *existing_mesh,
1218 const ISampleSelector &sample_sel,
1219 const AbcReadGeometryParams &read_params,
1220 const char **r_err_str)
1221{
1222 AbcMeshData abc_mesh_data;
1223 try {
1224 abc_mesh_data = extract_mesh_data(m_iobject, m_schema, sample_sel, read_params, false);
1225 }
1226 catch (Alembic::Util::Exception &ex) {
1227 if (r_err_str != nullptr) {
1228 *r_err_str = RPT_("Error reading mesh sample; more detail on the console");
1229 }
1230 CLOG_WARN(&LOG,
1231 "Error reading mesh sample for '%s/%s' at time %f: %s",
1232 m_iobject.getFullName().c_str(),
1233 m_schema.getName().c_str(),
1234 sample_sel.getRequestedTime(),
1235 ex.what());
1236 return existing_mesh;
1237 }
1238
1239 Mesh *mesh_to_export = read_mesh_sample(abc_mesh_data,
1240 sample_sel,
1241 read_params,
1242 existing_mesh,
1243 r_err_str,
1245
1246 /* Access to m_schema.getValue is safe if the above extract_mesh_data succeeds. */
1247 ISubDSchema::Sample sample = m_schema.getValue(sample_sel);
1248
1250 mesh_to_export, sample.getCreaseIndices(), sample.getCreaseSharpnesses(), m_settings);
1251
1253 mesh_to_export, sample.getCornerIndices(), sample.getCornerSharpnesses(), m_settings);
1254
1255 return mesh_to_export;
1256}
1257
1259 const Alembic::Abc::ISampleSelector &sample_sel,
1260 const AbcReadGeometryParams &read_params,
1261 const char **r_err_str)
1262{
1263 Mesh *mesh = geometry_set.get_mesh_for_write();
1264
1265 if (mesh == nullptr) {
1266 return;
1267 }
1268
1269 Mesh *new_mesh = read_mesh(mesh, sample_sel, read_params, r_err_str);
1270
1271 geometry_set.replace_mesh(new_mesh);
1272}
1273
1274void AbcSubDReader::add_subdiv_modifier()
1275{
1279
1280 SubsurfModifierData *subdiv_data = reinterpret_cast<SubsurfModifierData *>(md);
1281
1282 try {
1283 /* We only read the first sample as it is unlikely that those value are animated. */
1284 ISampleSelector sample_selector = ISampleSelector(Alembic::Abc::index_t(0));
1285 ISubDSchema::Sample sample = m_schema.getValue(sample_selector);
1286
1287 const AbcFaceVaryingInterpolateBoundary fvar_interpolate_boundary =
1288 AbcFaceVaryingInterpolateBoundary(sample.getFaceVaryingInterpolateBoundary());
1289
1290 const AbcInterpolateBoundary interpolate_boundary = AbcInterpolateBoundary(
1291 sample.getInterpolateBoundary());
1292
1293 /* FaceVaryingPropagateCorners should have a value of either 0 (false) or 1 (true). Consider
1294 * only values that are greater than 0 as true to allow for bad values, but discard negative
1295 * values for the potential set of true values are the value used by Alembic to tell that the
1296 * property has not been initialized is negative. */
1297 const bool propagate_corners = sample.getFaceVaryingPropagateCorners() > 0;
1298
1299 /* Confusingly, ALL is NONE and NONE is ALL. */
1300 switch (fvar_interpolate_boundary) {
1302 subdiv_data->uv_smooth = SUBSURF_UV_SMOOTH_NONE;
1303 break;
1305 if (propagate_corners) {
1307 }
1308 else {
1310 }
1311 break;
1312 }
1314 subdiv_data->uv_smooth = SUBSURF_UV_SMOOTH_ALL;
1315 break;
1318 break;
1319 }
1320
1321 switch (interpolate_boundary) {
1323 /* Blender has no concept for this. */
1324 break;
1327 break;
1330 break;
1331 }
1332
1333 ICompoundProperty user_properties = m_schema.getUserProperties();
1334
1335 if (user_properties.valid() && user_properties.getPropertyHeader("subdivRenderLevels") &&
1336 user_properties.getPropertyHeader("subdivViewportLevels"))
1337 {
1338 IInt32Property render_levels(user_properties, "subdivRenderLevels");
1339 IInt32Property viewport_levels(user_properties, "subdivViewportLevels");
1340
1341 subdiv_data->renderLevels = short(render_levels.getValue(sample_selector));
1342 subdiv_data->levels = short(viewport_levels.getValue(sample_selector));
1343 }
1344 }
1345 catch (Alembic::Util::Exception &ex) {
1346 CLOG_WARN(&LOG,
1347 "Error reading subdivision parameter for '%s/%s' : %s",
1348 m_iobject.getFullName().c_str(),
1349 m_schema.getName().c_str(),
1350 ex.what());
1351 }
1352}
1353
1354} // namespace io::alembic
1355} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define RPT_(msgid)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define MAXMAT
#define MOD_MESHSEQ_READ_ALL
Object is a sort of wrapper for general info.
#define BLI_INLINE
#define BLI_assert_msg(a, msg)
constexpr int64_t size() const
constexpr IndexRange()=default
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:508
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
void reserve(int64_t n)
Definition BLI_map.hh:1028
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr void fill(const T &value) const
Definition BLI_span.hh:523
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
void append(const T &value)
bool is_empty() const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
constexpr const char * data() const
struct Mesh * read_mesh(struct Mesh *existing_mesh, const Alembic::Abc::ISampleSelector &sample_sel, const AbcReadGeometryParams &read_params, const char **r_err_str)
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) override
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, const Object *const ob, const char **r_err_str) const override
bool topology_changed(const Mesh *existing_mesh, const Alembic::Abc::ISampleSelector &sample_sel) override
void read_geometry(bke::GeometrySet &geometry_set, const Alembic::Abc::ISampleSelector &sample_sel, const AbcReadGeometryParams &read_params, const char **r_err_str) override
AbcMeshReader(const AbcReaderConstructorArgs &args)
AbcObjectReader(const AbcReaderConstructorArgs &args)
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, const Object *const ob, const char **r_err_str) const override
AbcSubDReader(const AbcReaderConstructorArgs &args)
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) override
bool topology_changed(const Mesh *existing_mesh, const Alembic::Abc::ISampleSelector &sample_sel) override
void read_geometry(bke::GeometrySet &geometry_set, const Alembic::Abc::ISampleSelector &sample_sel, const AbcReadGeometryParams &read_params, const char **r_err_str) override
BLI_INLINE float sharpness_to_crease(float sharpness)
IndexMask mesh_find_faces_duplicate_verts(const Mesh &mesh, IndexMaskMemory &memory)
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
void mesh_set_custom_normals_from_verts(Mesh &mesh, MutableSpan< float3 > vert_normals)
void mesh_vert_normals_assign(Mesh &mesh, Span< float3 > vert_normals)
bool mesh_validate(Mesh &mesh, bool verbose=false, bool allow_missing_edges=false)
void mesh_set_custom_normals(Mesh &mesh, MutableSpan< float3 > corner_normals)
static void assign_materials(Main *bmain, Object *ob, const std::map< std::string, int > &mat_index_map)
static std::map< std::string, Material * > build_material_map(const Main *bmain)
static Mesh * read_mesh_sample(const AbcMeshData &abc_mesh_data, const ISampleSelector &selector, const AbcReadGeometryParams &read_params, Mesh *existing_mesh, const char **r_err_str, const bool is_reading_a_file_sequence)
AbcUvScope get_uv_scope(const Alembic::AbcGeom::GeometryScope scope, const CDStreamConfig &config, const Alembic::AbcGeom::UInt32ArraySamplePtr &indices)
static void process_normals(CDStreamConfig &config, const IN3fGeomParam &normals, const ISampleSelector &selector)
static void read_vertex_creases(Mesh *mesh, const Int32ArraySamplePtr &indices, const FloatArraySamplePtr &sharpnesses, const ImportSettings *settings)
BLI_INLINE void read_uvs_params(CDStreamConfig &config, const IV2fGeomParam &uv, const ISampleSelector &selector)
void read_velocity(const V3fArraySamplePtr &velocities, const CDStreamConfig &config, const float velocity_scale)
static bool topology_changed(const AbcMeshData &abc_mesh_data, const Mesh *existing_mesh, const bool is_reading_a_file_sequence)
static Vector< std::string > get_face_set_names(const IPolyMeshSchema &schema)
static void read_mverts_interp(float3 *vert_positions, const P3fArraySamplePtr &positions, const P3fArraySamplePtr &ceil_positions, const double weight)
static void process_loop_normals(CDStreamConfig &config, const N3fArraySamplePtr loop_normals_ptr)
bool is_valid_animated(const ICompoundProperty arbGeomParams, const PropertyHeader &prop_header)
static CDStreamConfig get_config(Mesh *mesh)
static void config_reload_mesh(CDStreamConfig &config)
static bool samples_have_same_topology(const SampleType &sample, const SampleType &ceil_sample)
BLI_INLINE void copy_zup_from_yup(float zup[3], const float yup[3])
static void process_vertex_normals(CDStreamConfig &config, const N3fArraySamplePtr vertex_normals_ptr)
void read_custom_data(const std::string &iobject_full_name, const ICompoundProperty &prop, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss)
static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data)
static bool has_animated_geom_params(const ICompoundProperty arbGeomParams)
V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema, const Alembic::AbcGeom::ISampleSelector &selector, const std::string &name)
Definition abc_util.cc:91
static void process_no_normals(CDStreamConfig &)
void read_generated_coordinates(const ICompoundProperty &prop, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss)
bool has_animations(Alembic::AbcGeom::ICurvesSchema &schema, ImportSettings *settings)
static void read_mverts(CDStreamConfig &config, const AbcMeshData &mesh_data)
static AbcMeshData extract_mesh_data(const IObject &iobject, const IPolyMeshSchema &schema, const ISampleSelector &selector, const AbcReadGeometryParams &params, const bool for_topology_check)
static CLG_LogRef LOG
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:129
static void read_edge_creases(Mesh *mesh, const Int32ArraySamplePtr &indices, const FloatArraySamplePtr &sharpnesses, const ImportSettings *settings)
void read_active_and_default_color_attributes(Mesh &mesh, const ICompoundProperty &user_props, const Alembic::AbcGeom::ISampleSelector &sample_sel)
bool size_fits_in_int(const int64_t size)
bool index_in_range(const int64_t index, const int64_t size)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
ATTR_WARN_UNUSED_RESULT const BMLoop * l
@ SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS
@ SUBSURF_UV_SMOOTH_PRESERVE_CORNERS_JUNCTIONS_AND_CONCAVE
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys=true)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
VecBase< float, 2 > float2
ModifierData * BKE_modifier_new(int type)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
@ MOD_MESHSEQ_INTERPOLATE_VERTICES
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
ATTR_WARN_UNUSED_RESULT const BMVert * v2
@ SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS
@ SUBSURF_BOUNDARY_SMOOTH_ALL
Mesh * BKE_mesh_new_nomain_from_template(const Mesh *me_src, int verts_num, int edges_num, int faces_num, int corners_num)
static CLG_LogRef LOG
void BKE_object_material_assign_single_obdata(Main *bmain, Object *ob, Material *ma, short act)
Material * BKE_material_add(Main *bmain, const char *name)
VecBase< float, 3 > float3
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
Definition object.cc:2265
Mesh * BKE_mesh_add(Main *bmain, const char *name)
void id_us_min(ID *id)
Definition lib_id.cc:441
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ListBaseT< Material > materials
Definition BKE_main.hh:392
ListBaseT< ModifierData > modifiers
eSubsurfBoundarySmooth boundary_smooth
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
IInt32ArrayProperty face_indices_property
std::optional< SampleInterpolationSettings > interpolation_settings
bke::SpanAttributeWriter< float2 > uv_map