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