Blender V2.61 - r43446

MaterialExporter.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
00019  *                 Nathan Letwory
00020  *
00021  * ***** END GPL LICENSE BLOCK *****
00022  */
00023 
00030 #include "MaterialExporter.h"
00031 #include "COLLADABUUtils.h"
00032 #include "collada_internal.h"
00033 
00034 MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryMaterials(sw), export_settings(export_settings) {}
00035 
00036 void MaterialsExporter::exportMaterials(Scene *sce)
00037 {
00038     if(hasMaterials(sce)) {
00039         openLibrary();
00040 
00041         MaterialFunctor mf;
00042         mf.forEachMaterialInScene<MaterialsExporter>(sce, *this, this->export_settings->selected);
00043 
00044         closeLibrary();
00045     }
00046 }
00047 
00048 
00049 bool MaterialsExporter::hasMaterials(Scene *sce)
00050 {
00051     Base *base = (Base *)sce->base.first;
00052     
00053     while(base) {
00054         Object *ob= base->object;
00055         int a;
00056         for(a = 0; a < ob->totcol; a++)
00057         {
00058             Material *ma = give_current_material(ob, a+1);
00059 
00060             // no material, but check all of the slots
00061             if (!ma) continue;
00062 
00063             return true;
00064         }
00065         base= base->next;
00066     }
00067     return false;
00068 }
00069 
00070 void MaterialsExporter::operator()(Material *ma, Object *ob)
00071 {
00072     std::string name(id_name(ma));
00073 
00074     openMaterial(get_material_id(ma), name);
00075 
00076     std::string efid = translate_id(name) + "-effect";
00077     addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, efid));
00078 
00079     closeMaterial();
00080 }