From b000a01725aff8715ad24b9202ed711a1edffec5 Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Fri, 3 Jun 2016 18:22:56 +0200 Subject: fix T48389 (wip) added warning for loops that define holes (polygons with holes not supported) --- source/blender/collada/MeshImporter.cpp | 28 +++++++++++++++++++++++++--- source/blender/collada/MeshImporter.h | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 76f24545248..3adddddb8e7 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 9d5fefb83f2..d6426fbaf56 100644 --- a/source/blender/collada/MeshImporter.h +++ b/source/blender/collada/MeshImporter.h @@ -109,7 +109,7 @@ private: std::map geom_uid_mat_mapping_map; // crazy name! std::multimap 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, -- cgit v1.2.3