[Bf-blender-cvs] [f118d51] compositor-2016: fix T48389 (wip) added warning for loops that define holes (polygons with holes not supported)

Gaia Clary noreply at git.blender.org
Wed Jun 8 21:52:50 CEST 2016


Commit: f118d516bb5d1e1656f578a94eeec57e3579e100
Author: Gaia Clary
Date:   Fri Jun 3 18:22:56 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rBf118d516bb5d1e1656f578a94eeec57e3579e100

fix T48389 (wip) added warning for loops that define holes (polygons with holes not supported)

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

M	source/blender/collada/MeshImporter.cpp
M	source/blender/collada/MeshImporter.h

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

diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index 76f2454..3addddd 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -211,15 +211,27 @@ void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol)
 MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {
 }
 
-void MeshImporter::set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, unsigned int *indices, int loop_count)
+bool MeshImporter::set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, unsigned int *indices, int loop_count)
 {
 	mpoly->loopstart = loop_index;
 	mpoly->totloop   = loop_count;
-
+	bool broken_loop = false;
 	for (int index=0; index < loop_count; index++) {
+
+		/* Test if loop defines a hole */
+		if (!broken_loop) {
+			for (int i = 0; i < index; i++) {
+				if (indices[i] == indices[index]) {
+					// duplicate index -> not good
+					broken_loop = true;
+				}
+			}
+		}
+
 		mloop->v = indices[index];
 		mloop++;
 	}
+	return broken_loop;
 }
 
 void MeshImporter::set_vcol(MLoopCol *mlc, VCOLDataWrapper &vob, int loop_index, COLLADAFW::IndexList &index_list, int count)
@@ -698,6 +710,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me)
 			COLLADAFW::IndexListArray& index_list_array_uvcoord = mp->getUVCoordIndicesArray();
 			COLLADAFW::IndexListArray& index_list_array_vcolor  = mp->getColorIndicesArray();
 
+			int invalid_loop_holes = 0;
 			for (unsigned int j = 0; j < prim_totpoly; j++) {
 
 				// Vertices in polygon:
@@ -705,8 +718,12 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me)
 				if (vcount < 0) {
 					continue; // TODO: add support for holes
 				}
-				set_poly_indices(mpoly, mloop, loop_index, position_indices, vcount);
 
+				bool broken_loop = set_poly_indices(mpoly, mloop, loop_index, position_indices, vcount);
+				if (broken_loop)
+				{
+					invalid_loop_holes += 1;
+				}
 
 				for (unsigned int uvset_index = 0; uvset_index < index_list_array_uvcoord.getCount(); uvset_index++) {
 					// get mtface by face index and uv set index
@@ -754,6 +771,11 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me)
 
 				position_indices += vcount;
 			}
+
+			if (invalid_loop_holes > 0)
+			{
+				fprintf(stderr, "Collada import: Mesh [%s] : contains %d unsupported loops (holes).\n", me->id.name, invalid_loop_holes);
+			}
 		}
 
 		else if (collada_meshtype == COLLADAFW::MeshPrimitive::LINES) {
diff --git a/source/blender/collada/MeshImporter.h b/source/blender/collada/MeshImporter.h
index 9d5fefb..d6426fb 100644
--- a/source/blender/collada/MeshImporter.h
+++ b/source/blender/collada/MeshImporter.h
@@ -109,7 +109,7 @@ private:
 	std::map<COLLADAFW::UniqueId, MaterialIdPrimitiveArrayMap> geom_uid_mat_mapping_map; // crazy name!
 	std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId> materials_mapped_to_geom; //< materials that have already been mapped to a geometry. A pair of geom uid and mat uid, one geometry can have several materials
 	
-	void set_poly_indices(MPoly *mpoly,
+	bool set_poly_indices(MPoly *mpoly,
 						  MLoop *mloop,
 						  int loop_index,
 						  unsigned int *indices,




More information about the Bf-blender-cvs mailing list