Blender  V2.59
InstanceWriter.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: InstanceWriter.cpp 35711 2011-03-22 22:51:02Z 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 
00031 #include <string>
00032 #include <sstream>
00033 
00034 #include "COLLADASWInstanceMaterial.h"
00035 
00036 #include "BKE_customdata.h"
00037 #include "BKE_material.h"
00038 
00039 #include "DNA_mesh_types.h"
00040 
00041 #include "InstanceWriter.h"
00042 
00043 #include "collada_internal.h"
00044 #include "collada_utils.h"
00045 
00046 void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob)
00047 {
00048         for(int a = 0; a < ob->totcol; a++)     {
00049                 Material *ma = give_current_material(ob, a+1);
00050                         
00051                 COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList();
00052 
00053                 if (ma) {
00054                         std::string matid(get_material_id(ma));
00055                         matid = translate_id(matid);
00056                         std::ostringstream ostr;
00057                         ostr << translate_id(id_name(ma)) << a+1;
00058                         COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
00059                         
00060                         // create <bind_vertex_input> for each uv layer
00061                         Mesh *me = (Mesh*)ob->data;
00062                         int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
00063                         
00064                         for (int b = 0; b < totlayer; b++) {
00065                                 char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b);
00066                                 im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", b));
00067                         }
00068                         
00069                         iml.push_back(im);
00070                 }
00071         }
00072 }