[Bf-blender-cvs] [4fda0c0] alembic_basic_io: Fix UVs reading.

Kévin Dietrich noreply at git.blender.org
Thu Jun 16 16:54:24 CEST 2016


Commit: 4fda0c00de3b9d77f07fd3fdfacdc7f589883e59
Author: Kévin Dietrich
Date:   Thu Jun 16 16:27:15 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB4fda0c00de3b9d77f07fd3fdfacdc7f589883e59

Fix UVs reading.

UVs were indexed using the faces indices instead of their own UV
indices.

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

M	source/blender/alembic/intern/abc_customdata.cc
M	source/blender/alembic/intern/abc_mesh.cc
M	source/blender/alembic/intern/abc_mesh.h
M	source/blender/alembic/intern/alembic_capi.cc

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

diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc
index 3293e4f..3bb4294 100644
--- a/source/blender/alembic/intern/abc_customdata.cc
+++ b/source/blender/alembic/intern/abc_customdata.cc
@@ -274,21 +274,17 @@ static void read_uvs(const CDStreamConfig &config, void *data,
                      const Alembic::AbcGeom::UInt32ArraySamplePtr &indices)
 {
 	MPoly *mpolys = config.mpoly;
-	MLoop *mloops = config.mloop;
 	MLoopUV *mloopuvs = static_cast<MLoopUV *>(data);
 
-	unsigned int vert_index, loop_index;
+	unsigned int uv_index, loop_index;
 
 	for (int i = 0; i < config.totpoly; ++i) {
 		MPoly &poly = mpolys[i];
 
 		for (int f = 0; f < poly.totloop; ++f) {
 			loop_index = poly.loopstart + f;
-
-			MLoop &loop = mloops[loop_index];
-			vert_index = (*indices)[loop.v];
-
-			const Imath::V2f &uv = (*uvs)[vert_index];
+			uv_index = (*indices)[loop_index];
+			const Imath::V2f &uv = (*uvs)[uv_index];
 
 			MLoopUV &loopuv = mloopuvs[loop_index];
 			loopuv.uv[0] = uv[0];
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index dc5d375..25445cb 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -906,6 +906,27 @@ static void *add_customdata_cb(void *user_data, const char *name, int data_type)
 	return cd_ptr;
 }
 
+#if 0
+void print_scope(const std::string &prefix, const int scope, std::ostream &os)
+{
+	os << prefix << ": ";
+
+	switch (scope) {
+		case kVaryingScope:
+			os << "Varying Scope";
+			break;
+		case kFacevaryingScope:
+			os << "Face Varying Scope";
+			break;
+		case kVertexScope:
+			os << "Vertex Scope";
+			break;
+	}
+
+	os << '\n';
+}
+#endif
+
 void AbcMeshReader::readPolyDataSample(Mesh *mesh,
                                        const Int32ArraySamplePtr &face_indices,
                                        const Int32ArraySamplePtr &face_counts,
@@ -917,19 +938,23 @@ void AbcMeshReader::readPolyDataSample(Mesh *mesh,
 	utils::mesh_add_mpolygons(mesh, num_poly);
 	utils::mesh_add_mloops(mesh, num_loops);
 
-	IV2fGeomParam::Sample::samp_ptr_type uvsamp_vals;
+	Alembic::AbcGeom::V2fArraySamplePtr uvs;
+	Alembic::Abc::UInt32ArraySamplePtr uvs_indices;
 	const IV2fGeomParam uv = (m_subd_schema.valid() ? m_subd_schema.getUVsParam()
 	                                                : m_schema.getUVsParam());
 
 	if (uv.valid()) {
 		IV2fGeomParam::Sample uvsamp = uv.getExpandedValue();
-		uvsamp_vals = uvsamp.getVals();
+		uv.getIndexed(uvsamp, Alembic::Abc::ISampleSelector(0.0f));
+
+		uvs = uvsamp.getVals();
+		uvs_indices = uvsamp.getIndices();
 
 		ED_mesh_uv_texture_add(mesh, Alembic::Abc::GetSourceName(uv.getMetaData()).c_str(), true);
 	}
 
 	read_mpolys(mesh->mpoly, mesh->mloop, mesh->mloopuv, &mesh->pdata,
-	            face_indices, face_counts, uvsamp_vals, normals);
+	            face_indices, face_counts, uvs, uvs_indices, normals);
 
 	const ICompoundProperty &arb_geom_params = (m_schema.valid() ? m_schema.getArbGeomParams()
 	                                                             : m_subd_schema.getArbGeomParams());
@@ -1026,10 +1051,11 @@ void read_mverts(MVert *mverts,
 	}
 }
 
-void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData *pdata,
+void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData */*pdata*/,
                  const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
                  const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
                  const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
+                 const Alembic::AbcGeom::UInt32ArraySamplePtr &uvs_indices,
                  const Alembic::AbcGeom::N3fArraySamplePtr &/*normals*/)
 {
 	int loopcount = 0;
@@ -1059,14 +1085,16 @@ void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData *pd
 
 		/* TODO: reverse. */
 		int rev_loop = loopcount;
-		for (int f = face_size; f-- ;) {
+		for (int f = face_size; f-- ; ++loopcount) {
 			MLoop &loop = mloops[rev_loop + f];
 
-			vert_index = (*face_indices)[loopcount++];
+			vert_index = (*face_indices)[loopcount];
 			loop.v = vert_index;
 
-			if (mloopuvs && uvs) {
+			if (mloopuvs && uvs && uvs_indices) {
 				MLoopUV &loopuv = mloopuvs[rev_loop + f];
+
+				vert_index = (*uvs_indices)[loopcount];
 				loopuv.uv[0] = (*uvs)[vert_index][0];
 				loopuv.uv[1] = (*uvs)[vert_index][1];
 			}
diff --git a/source/blender/alembic/intern/abc_mesh.h b/source/blender/alembic/intern/abc_mesh.h
index fe7324b..3b194e0 100644
--- a/source/blender/alembic/intern/abc_mesh.h
+++ b/source/blender/alembic/intern/abc_mesh.h
@@ -131,6 +131,7 @@ void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData *pd
                  const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
                  const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
                  const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
+                 const Alembic::AbcGeom::UInt32ArraySamplePtr &uvs_indices,
                  const Alembic::AbcGeom::N3fArraySamplePtr &normals);
 
 void read_uvs(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, size_t face_count,
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 6b4c91e..4f9a142 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -716,11 +716,13 @@ static DerivedMesh *read_mesh_sample(DerivedMesh *dm, const IObject &iobject, co
 	}
 
 	const IV2fGeomParam uv = schema.getUVsParam();
-	IV2fGeomParam::Sample::samp_ptr_type uvsamp_vals;
+	Alembic::Abc::V2fArraySamplePtr uvs;
+	Alembic::Abc::UInt32ArraySamplePtr uvs_indices;
 
 	if (uv.valid()) {
 		IV2fGeomParam::Sample uvsamp = uv.getExpandedValue(sample_sel);
-		uvsamp_vals = uvsamp.getVals();
+		uvs = uvsamp.getVals();
+		uvs_indices = uvsamp.getIndices();
 	}
 
 	N3fArraySamplePtr vertex_normals, poly_normals;
@@ -746,7 +748,7 @@ static DerivedMesh *read_mesh_sample(DerivedMesh *dm, const IObject &iobject, co
 	CustomData *pdata = dm->getPolyDataLayout(dm);
 
 	read_mverts(mverts, positions, vertex_normals);
-	read_mpolys(mpolys, mloops, mloopuvs, pdata, face_indices, face_counts, uvsamp_vals, poly_normals);
+	read_mpolys(mpolys, mloops, mloopuvs, pdata, face_indices, face_counts, uvs, uvs_indices, poly_normals);
 
 	CDDM_calc_edges(dm);
 	dm->dirty = static_cast<DMDirtyFlag>(static_cast<int>(dm->dirty) | static_cast<int>(DM_DIRTY_NORMALS));




More information about the Bf-blender-cvs mailing list