From c0a7b5c2a85f15a714ff0b00a3dbc54688cd039e Mon Sep 17 00:00:00 2001 From: Arystanbek Dyussenov Date: Mon, 4 Oct 2010 03:38:37 +0000 Subject: COLLADA exporter fix: do not create a duplicate if an object has NULL materials linked along with normal materials. --- source/blender/collada/DocumentExporter.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'source/blender/collada/DocumentExporter.cpp') diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index c2d937f3d43..d10fa4ca94c 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -497,13 +497,11 @@ public: // XXX slow if (ob->totcol) { for(int a = 0; a < ob->totcol; a++) { - // account for NULL materials, this should not normally happen? - Material *ma = give_current_material(ob, a + 1); - createPolylist(ma != NULL, a, has_uvs, has_color, ob, geom_id, norind); + createPolylist(a, has_uvs, has_color, ob, geom_id, norind); } } else { - createPolylist(false, 0, has_uvs, has_color, ob, geom_id, norind); + createPolylist(0, has_uvs, has_color, ob, geom_id, norind); } closeMesh(); @@ -515,8 +513,7 @@ public: } // powerful because it handles both cases when there is material and when there's not - void createPolylist(bool has_material, - int material_index, + void createPolylist(int material_index, bool has_uvs, bool has_color, Object *ob, @@ -536,7 +533,7 @@ public: for (i = 0; i < totfaces; i++) { MFace *f = &mfaces[i]; - if ((has_material && f->mat_nr == material_index) || !has_material) { + if (f->mat_nr == material_index) { faces_in_polylist++; if (f->v4 == 0) { vcount_list.push_back(3); @@ -549,17 +546,18 @@ public: // no faces using this material if (faces_in_polylist == 0) { + fprintf(stderr, "%s: no faces use material %d\n", id_name(ob).c_str(), material_index); return; } - Material *ma = has_material ? give_current_material(ob, material_index + 1) : NULL; + Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL; COLLADASW::Polylist polylist(mSW); // sets count attribute in polylist.setCount(faces_in_polylist); // sets material name - if (has_material) { + if (ma) { polylist.setMaterial(translate_id(id_name(ma))); } @@ -603,7 +601,7 @@ public: for (i = 0; i < totfaces; i++) { MFace *f = &mfaces[i]; - if ((has_material && f->mat_nr == material_index) || !has_material) { + if (f->mat_nr == material_index) { unsigned int *v = &f->v1; unsigned int *n = &norind[i].v1; -- cgit v1.2.3