[6db0fd65abc] master: T53711: Alembic don´t import vertex colors correctly

Sybren A. Stüvel noreply at git.blender.org
Tue Jan 16 16:23:23 CET 2018


Commit: 6db0fd65abc6e6d0fb75f35771eee5ca8f113147
Author: Sybren A. Stüvel
Date:   Tue Jan 16 15:05:31 2018 +0100
Branches: master
https://developer.blender.org/rB6db0fd65abc6e6d0fb75f35771eee5ca8f113147

T53711: Alembic don´t import vertex colors correctly

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.

===================================================================

M	source/blender/alembic/intern/abc_customdata.cc

===================================================================

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);



More information about the Bf-blender-cvs mailing list