diff options
Diffstat (limited to 'source/blender/io/alembic')
-rw-r--r-- | source/blender/io/alembic/ABC_alembic.h | 30 | ||||
-rw-r--r-- | source/blender/io/alembic/exporter/abc_writer_mesh.cc | 13 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_customdata.cc | 2 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_mesh.cc | 30 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_mesh.h | 9 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/alembic_capi.cc | 22 |
6 files changed, 62 insertions, 44 deletions
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h index ded3258ff18..05025861857 100644 --- a/source/blender/io/alembic/ABC_alembic.h +++ b/source/blender/io/alembic/ABC_alembic.h @@ -60,6 +60,28 @@ struct AlembicExportParams { float global_scale; }; +struct AlembicImportParams { + /* Multiplier for the cached data scale. Mostly useful if the data is stored in a different unit + * as what Blender expects (e.g. centimeters instead of meters). */ + float global_scale; + + /* Number of consecutive files to expect if the cached animation is split in a sequence. */ + int sequence_len; + /* Start frame of the sequence, offset from 0. */ + int sequence_offset; + /* True if the cache is split in multiple files. */ + bool is_sequence; + + /* True if the importer should set the current scene's start and end frame based on the start and + * end frames of the cached animation. */ + bool set_frame_range; + /* True if imported meshes should be validated. Error messages are sent to the console. */ + bool validate_meshes; + /* True if a cache reader should be added regardless of whether there is animated data in the + * cached file. */ + bool always_add_cache_reader; +}; + /* The ABC_export and ABC_import functions both take a as_background_job * parameter, and return a boolean. * @@ -78,13 +100,7 @@ bool ABC_export(struct Scene *scene, bool ABC_import(struct bContext *C, const char *filepath, - float scale, - bool is_sequence, - bool set_frame_range, - int sequence_len, - int offset, - bool validate_meshes, - bool always_add_cache_reader, + const struct AlembicImportParams *params, bool as_background_job); struct CacheArchiveHandle *ABC_create_handle(struct Main *bmain, diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index 07b185ffd64..83f970d3965 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -12,6 +12,7 @@ #include "BLI_math_vector.h" #include "BKE_attribute.h" +#include "BKE_attribute.hh" #include "BKE_customdata.h" #include "BKE_lib_id.h" #include "BKE_material.h" @@ -366,7 +367,7 @@ bool ABCGenericMeshWriter::get_velocities(struct Mesh *mesh, std::vector<Imath:: { /* Export velocity attribute output by fluid sim, sequence cache modifier * and geometry nodes. */ - CustomDataLayer *velocity_layer = BKE_id_attribute_find( + const CustomDataLayer *velocity_layer = BKE_id_attribute_find( &mesh->id, "velocity", CD_PROP_FLOAT3, ATTR_DOMAIN_POINT); if (velocity_layer == nullptr) { @@ -390,12 +391,12 @@ void ABCGenericMeshWriter::get_geo_groups(Object *object, struct Mesh *mesh, std::map<std::string, std::vector<int32_t>> &geo_groups) { - const int num_poly = mesh->totpoly; - MPoly *polygons = mesh->mpoly; + const bke::AttributeAccessor attributes = bke::mesh_attributes(*mesh); + const VArraySpan<int> material_indices = attributes.lookup_or_default<int>( + "material_index", ATTR_DOMAIN_FACE, 0); - for (int i = 0; i < num_poly; i++) { - MPoly ¤t_poly = polygons[i]; - short mnr = current_poly.mat_nr; + for (const int i : material_indices.index_range()) { + short mnr = material_indices[i]; Material *mat = BKE_object_material_get(object, mnr + 1); diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index 35be9f9fc4d..60d593c1684 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -540,7 +540,7 @@ void read_generated_coordinates(const ICompoundProperty &prop, cd_data = CustomData_get_layer(&mesh->vdata, CD_ORCO); } else { - cd_data = CustomData_add_layer(&mesh->vdata, CD_ORCO, CD_CALLOC, nullptr, totvert); + cd_data = CustomData_add_layer(&mesh->vdata, CD_ORCO, CD_CONSTRUCT, nullptr, totvert); } float(*orcodata)[3] = static_cast<float(*)[3]>(cd_data); diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index bacc1f06599..16e5ee968a3 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -25,7 +25,7 @@ #include "BLI_listbase.h" #include "BLI_math_geom.h" -#include "BKE_attribute.h" +#include "BKE_attribute.hh" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mesh.h" @@ -391,7 +391,7 @@ static void *add_customdata_cb(Mesh *mesh, const char *name, int data_type) /* Create a new layer. */ int numloops = mesh->totloop; cd_ptr = CustomData_add_layer_named( - &mesh->ldata, cd_data_type, CD_DEFAULT, nullptr, numloops, name); + &mesh->ldata, cd_data_type, CD_SET_DEFAULT, nullptr, numloops, name); return cd_ptr; } @@ -766,7 +766,11 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh, size_t num_polys = new_mesh->totpoly; if (num_polys > 0) { std::map<std::string, int> mat_map; - assign_facesets_to_mpoly(sample_sel, new_mesh->mpoly, num_polys, mat_map); + bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*new_mesh); + bke::SpanAttributeWriter<int> material_indices = + attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE); + assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map); + material_indices.finish(); } return new_mesh; @@ -775,10 +779,9 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh, return existing_mesh; } -void AbcMeshReader::assign_facesets_to_mpoly(const ISampleSelector &sample_sel, - MPoly *mpoly, - int totpoly, - std::map<std::string, int> &r_mat_map) +void AbcMeshReader::assign_facesets_to_material_indices(const ISampleSelector &sample_sel, + MutableSpan<int> material_indices, + std::map<std::string, int> &r_mat_map) { std::vector<std::string> face_sets; m_schema.getFaceSetNames(face_sets); @@ -811,13 +814,12 @@ void AbcMeshReader::assign_facesets_to_mpoly(const ISampleSelector &sample_sel, for (size_t l = 0; l < num_group_faces; l++) { size_t pos = (*group_faces)[l]; - if (pos >= totpoly) { + if (pos >= material_indices.size()) { std::cerr << "Faceset overflow on " << faceset.getName() << '\n'; break; } - MPoly &poly = mpoly[pos]; - poly.mat_nr = assigned_mat - 1; + material_indices[pos] = assigned_mat - 1; } } } @@ -825,7 +827,11 @@ void AbcMeshReader::assign_facesets_to_mpoly(const ISampleSelector &sample_sel, void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const ISampleSelector &sample_sel) { std::map<std::string, int> mat_map; - assign_facesets_to_mpoly(sample_sel, mesh->mpoly, mesh->totpoly, mat_map); + bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh); + bke::SpanAttributeWriter<int> material_indices = + attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE); + assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map); + material_indices.finish(); utils::assign_materials(bmain, m_object, mat_map); } @@ -890,7 +896,7 @@ static void read_vertex_creases(Mesh *mesh, } float *vertex_crease_data = (float *)CustomData_add_layer( - &mesh->vdata, CD_CREASE, CD_DEFAULT, nullptr, mesh->totvert); + &mesh->vdata, CD_CREASE, CD_SET_DEFAULT, nullptr, mesh->totvert); const int totvert = mesh->totvert; for (int i = 0, v = indices->size(); i < v; ++i) { diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.h b/source/blender/io/alembic/intern/abc_reader_mesh.h index f97525297b7..151f4d82226 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.h +++ b/source/blender/io/alembic/intern/abc_reader_mesh.h @@ -5,6 +5,8 @@ * \ingroup balembic */ +#include "BLI_span.hh" + #include "abc_customdata.h" #include "abc_reader_object.h" @@ -38,10 +40,9 @@ class AbcMeshReader final : public AbcObjectReader { Mesh *mesh, const Alembic::AbcGeom::ISampleSelector &sample_sel); - void assign_facesets_to_mpoly(const Alembic::Abc::ISampleSelector &sample_sel, - MPoly *mpoly, - int totpoly, - std::map<std::string, int> &r_mat_map); + void assign_facesets_to_material_indices(const Alembic::Abc::ISampleSelector &sample_sel, + MutableSpan<int> material_indices, + std::map<std::string, int> &r_mat_map); }; class AbcSubDReader final : public AbcObjectReader { diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc index 27df23b38c6..86622719f6e 100644 --- a/source/blender/io/alembic/intern/alembic_capi.cc +++ b/source/blender/io/alembic/intern/alembic_capi.cc @@ -672,13 +672,7 @@ static void import_freejob(void *user_data) bool ABC_import(bContext *C, const char *filepath, - float scale, - bool is_sequence, - bool set_frame_range, - int sequence_len, - int offset, - bool validate_meshes, - bool always_add_cache_reader, + const AlembicImportParams *params, bool as_background_job) { /* Using new here since MEM_* functions do not call constructor to properly initialize data. */ @@ -691,13 +685,13 @@ bool ABC_import(bContext *C, job->import_ok = false; BLI_strncpy(job->filename, filepath, 1024); - job->settings.scale = scale; - job->settings.is_sequence = is_sequence; - job->settings.set_frame_range = set_frame_range; - job->settings.sequence_len = sequence_len; - job->settings.sequence_offset = offset; - job->settings.validate_meshes = validate_meshes; - job->settings.always_add_cache_reader = always_add_cache_reader; + job->settings.scale = params->global_scale; + job->settings.is_sequence = params->is_sequence; + job->settings.set_frame_range = params->set_frame_range; + job->settings.sequence_len = params->sequence_len; + job->settings.sequence_offset = params->sequence_offset; + job->settings.validate_meshes = params->validate_meshes; + job->settings.always_add_cache_reader = params->always_add_cache_reader; job->error_code = ABC_NO_ERROR; job->was_cancelled = false; job->archive = nullptr; |