diff options
Diffstat (limited to 'source/blender/io/alembic/intern')
-rw-r--r-- | source/blender/io/alembic/intern/abc_customdata.cc | 4 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_mesh.cc | 10 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/alembic_capi.cc | 48 |
3 files changed, 37 insertions, 25 deletions
diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index 633611cf1a6..2820a128072 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -257,7 +257,7 @@ void write_generated_coordinates(const OCompoundProperty &prop, CDStreamConfig & /* ORCOs are always stored in the normalized 0..1 range in Blender, but Alembic stores them * unnormalized, so we need to unnormalize (invert transform) them. */ BKE_mesh_orco_verts_transform( - mesh, reinterpret_cast<float(*)[3]>(&coords[0]), mesh->totvert, true); + mesh, reinterpret_cast<float(*)[3]>(coords.data()), mesh->totvert, true); if (!config.abc_orco.valid()) { /* Create the Alembic property and keep a reference so future frames can reuse it. */ @@ -273,7 +273,7 @@ void write_custom_data(const OCompoundProperty &prop, CustomData *data, int data_type) { - CustomDataType cd_data_type = static_cast<CustomDataType>(data_type); + eCustomDataType cd_data_type = static_cast<eCustomDataType>(data_type); if (!CustomData_has_layer(data, cd_data_type)) { return; diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 219bba285a7..df3559c108c 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -77,10 +77,8 @@ static void assign_materials(Main *bmain, const std::map<std::string, int> &mat_index_map) { std::map<std::string, int>::const_iterator it; - for (it = mat_index_map.begin(); it != mat_index_map.end(); ++it) { - if (!BKE_object_material_slot_add(bmain, ob)) { - return; - } + if (mat_index_map.size() > MAXMAT) { + return; } std::map<std::string, Material *> matname_to_material = build_material_map(bmain); @@ -100,7 +98,7 @@ static void assign_materials(Main *bmain, assigned_mat = mat_iter->second; } - BKE_object_material_assign(bmain, ob, assigned_mat, mat_index, BKE_MAT_ASSIGN_OBDATA); + BKE_object_material_assign_single_obdata(bmain, ob, assigned_mat, mat_index); } } @@ -376,7 +374,7 @@ BLI_INLINE void read_uvs_params(CDStreamConfig &config, static void *add_customdata_cb(Mesh *mesh, const char *name, int data_type) { - CustomDataType cd_data_type = static_cast<CustomDataType>(data_type); + eCustomDataType cd_data_type = static_cast<eCustomDataType>(data_type); /* unsupported custom data type -- don't do anything. */ if (!ELEM(cd_data_type, CD_MLOOPUV, CD_PROP_BYTE_COLOR)) { diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc index 0d4e1d04db0..27df23b38c6 100644 --- a/source/blender/io/alembic/intern/alembic_capi.cc +++ b/source/blender/io/alembic/intern/alembic_capi.cc @@ -50,6 +50,7 @@ #include "BLI_math.h" #include "BLI_path_util.h" #include "BLI_string.h" +#include "BLI_timeit.hh" #include "WM_api.h" #include "WM_types.h" @@ -434,8 +435,17 @@ struct ImportJobData { bool was_cancelled; bool import_ok; bool is_background_job; + blender::timeit::TimePoint start_time; }; +static void report_job_duration(const ImportJobData *data) +{ + blender::timeit::Nanoseconds duration = blender::timeit::Clock::now() - data->start_time; + std::cout << "Alembic import of '" << data->filename << "' took "; + blender::timeit::print_duration(duration); + std::cout << '\n'; +} + static void import_startjob(void *user_data, short *stop, short *do_update, float *progress) { SCOPE_TIMER("Alembic import, objects reading and creation"); @@ -445,6 +455,7 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa data->stop = stop; data->do_update = do_update; data->progress = progress; + data->start_time = blender::timeit::Clock::now(); WM_set_locked_interface(data->wm, true); @@ -526,14 +537,14 @@ static void import_startjob(void *user_data, short *stop, short *do_update, floa Scene *scene = data->scene; if (data->settings.is_sequence) { - SFRA = data->settings.sequence_offset; - EFRA = SFRA + (data->settings.sequence_len - 1); - CFRA = SFRA; + scene->r.sfra = data->settings.sequence_offset; + scene->r.efra = scene->r.sfra + (data->settings.sequence_len - 1); + scene->r.cfra = scene->r.sfra; } else if (min_time < max_time) { - SFRA = static_cast<int>(round(min_time * FPS)); - EFRA = static_cast<int>(round(max_time * FPS)); - CFRA = SFRA; + scene->r.sfra = static_cast<int>(round(min_time * FPS)); + scene->r.efra = static_cast<int>(round(max_time * FPS)); + scene->r.cfra = scene->r.sfra; } } @@ -573,12 +584,10 @@ static void import_endjob(void *user_data) ImportJobData *data = static_cast<ImportJobData *>(user_data); - std::vector<AbcObjectReader *>::iterator iter; - /* Delete objects on cancellation. */ if (data->was_cancelled) { - for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { - Object *ob = (*iter)->object(); + for (AbcObjectReader *reader : data->readers) { + Object *ob = reader->object(); /* It's possible that cancellation occurred between the creation of * the reader and the creation of the Blender object. */ @@ -590,7 +599,6 @@ static void import_endjob(void *user_data) } } else { - /* Add object to scene. */ Base *base; LayerCollection *lc; ViewLayer *view_layer = data->view_layer; @@ -599,11 +607,17 @@ static void import_endjob(void *user_data) lc = BKE_layer_collection_get_active(view_layer); - for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { - Object *ob = (*iter)->object(); - + /* Add all objects to the collection (don't do sync for each object). */ + BKE_layer_collection_resync_forbid(); + for (AbcObjectReader *reader : data->readers) { + Object *ob = reader->object(); BKE_collection_object_add(data->bmain, lc->collection, ob); - + } + /* Sync the collection, and do view layer operations. */ + BKE_layer_collection_resync_allow(); + BKE_main_collection_sync(data->bmain); + for (AbcObjectReader *reader : data->readers) { + Object *ob = reader->object(); base = BKE_view_layer_base_find(view_layer, ob); /* TODO: is setting active needed? */ BKE_view_layer_base_select_and_set_active(view_layer, base); @@ -625,8 +639,7 @@ static void import_endjob(void *user_data) } } - for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { - AbcObjectReader *reader = *iter; + for (AbcObjectReader *reader : data->readers) { reader->decref(); if (reader->refcount() == 0) { @@ -647,6 +660,7 @@ static void import_endjob(void *user_data) } WM_main_add_notifier(NC_SCENE | ND_FRAME, data->scene); + report_job_duration(data); } static void import_freejob(void *user_data) |