Don't write library_materials tag when there are no materials.
authorNathan Letwory <nathan@letworyinteractive.com>
Thu, 28 Jul 2011 00:08:03 +0000 (00:08 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Thu, 28 Jul 2011 00:08:03 +0000 (00:08 +0000)
source/blender/collada/MaterialExporter.cpp
source/blender/collada/MaterialExporter.h

index a44fa6802f20a3a460d2007455d69e1f84abfa5d..9d29177578dbedc9290aa9a598ee807426807a30 100644 (file)
@@ -37,12 +37,36 @@ MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw): COLLADASW::Li
 
 void MaterialsExporter::exportMaterials(Scene *sce, bool export_selected)
 {
-       openLibrary();
+       if(hasMaterials(sce)) {
+               openLibrary();
 
-       MaterialFunctor mf;
-       mf.forEachMaterialInScene<MaterialsExporter>(sce, *this, export_selected);
+               MaterialFunctor mf;
+               mf.forEachMaterialInScene<MaterialsExporter>(sce, *this, export_selected);
 
-       closeLibrary();
+               closeLibrary();
+       }
+}
+
+
+bool MaterialsExporter::hasMaterials(Scene *sce)
+{
+       Base *base = (Base *)sce->base.first;
+       
+       while(base) {
+               Object *ob= base->object;
+               int a;
+               for(a = 0; a < ob->totcol; a++)
+               {
+                       Material *ma = give_current_material(ob, a+1);
+
+                       // no material, but check all of the slots
+                       if (!ma) continue;
+
+                       return true;
+               }
+               base= base->next;
+       }
+       return false;
 }
 
 void MaterialsExporter::operator()(Material *ma, Object *ob)
index 0a7a276d8576c5cde574c81f7edbfaaa97bc0fa5..c080e4b05965fed78c68eb5b44a30053ec020bba 100644 (file)
@@ -51,6 +51,9 @@ public:
        MaterialsExporter(COLLADASW::StreamWriter *sw);
        void exportMaterials(Scene *sce, bool export_selected);
        void operator()(Material *ma, Object *ob);
+
+private:
+       bool hasMaterials(Scene *sce);
 };
 
 // used in forEachMaterialInScene