From 6db0fd65abc6e6d0fb75f35771eee5ca8f113147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 16 Jan 2018 15:05:31 +0100 Subject: =?UTF-8?q?T53711:=20Alembic=20don=C2=B4t=20import=20vertex=20colo?= =?UTF-8?q?rs=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An index stored in Alembic wasn't used. Often this index is a no-op (i.e. index[n] = n), in which case the result was fine. However, when it isn't, it caused issues. --- source/blender/alembic/intern/abc_customdata.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'source/blender/alembic') diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc index 8b526616053..ddc83a6aa60 100644 --- a/source/blender/alembic/intern/abc_customdata.cc +++ b/source/blender/alembic/intern/abc_customdata.cc @@ -285,6 +285,7 @@ static void read_custom_data_mcols(const std::string & iobject_full_name, { C3fArraySamplePtr c3f_ptr = C3fArraySamplePtr(); C4fArraySamplePtr c4f_ptr = C4fArraySamplePtr(); + Alembic::Abc::UInt32ArraySamplePtr indices(NULL); bool use_c3f_ptr; bool is_facevarying; @@ -299,6 +300,7 @@ static void read_custom_data_mcols(const std::string & iobject_full_name, config.totloop == sample.getIndices()->size(); c3f_ptr = sample.getVals(); + indices = sample.getIndices(); use_c3f_ptr = true; } else if (IC4fGeomParam::matches(prop_header)) { @@ -311,6 +313,7 @@ static void read_custom_data_mcols(const std::string & iobject_full_name, config.totloop == sample.getIndices()->size(); c4f_ptr = sample.getVals(); + indices = sample.getIndices(); use_c3f_ptr = false; } else { @@ -331,6 +334,12 @@ static void read_custom_data_mcols(const std::string & iobject_full_name, size_t color_index; bool bounds_warning_given = false; + /* The colors can go through two layers of indexing. Often the 'indices' + * array doesn't do anything (i.e. indices[n] = n), but when it does, it's + * important. Blender 2.79 writes indices incorrectly (see T53745), which + * is why we have to check for indices->size() > 0 */ + bool use_dual_indexing = is_facevarying && indices->size() > 0; + for (int i = 0; i < config.totpoly; ++i) { MPoly *poly = &mpolys[i]; MCol *cface = &cfaces[poly->loopstart + poly->totloop]; @@ -340,9 +349,13 @@ static void read_custom_data_mcols(const std::string & iobject_full_name, --cface; --mloop; + color_index = is_facevarying ? face_index : mloop->v; + if (use_dual_indexing) { + color_index = (*indices)[color_index]; + } if (use_c3f_ptr) { color_index = mcols_out_of_bounds_check( - is_facevarying ? face_index : mloop->v, + color_index, c3f_ptr->size(), iobject_full_name, prop_header, bounds_warning_given); @@ -355,7 +368,7 @@ static void read_custom_data_mcols(const std::string & iobject_full_name, } else { color_index = mcols_out_of_bounds_check( - is_facevarying ? face_index : mloop->v, + color_index, c4f_ptr->size(), iobject_full_name, prop_header, bounds_warning_given); -- cgit v1.2.3