Blender V2.61 - r43446

GeometryExporter.h

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 
00028 #ifndef __GEOMETRYEXPORTER_H__
00029 #define __GEOMETRYEXPORTER_H__
00030 
00031 #include <string>
00032 #include <vector>
00033 #include <set>
00034 
00035 #include "COLLADASWStreamWriter.h"
00036 #include "COLLADASWLibraryGeometries.h"
00037 #include "COLLADASWInputList.h"
00038 
00039 #include "DNA_mesh_types.h"
00040 #include "DNA_object_types.h"
00041 #include "DNA_scene_types.h"
00042 
00043 #include "ExportSettings.h"
00044 
00045 // TODO: optimize UV sets by making indexed list with duplicates removed
00046 class GeometryExporter : COLLADASW::LibraryGeometries
00047 {
00048     struct Face
00049     {
00050         unsigned int v1, v2, v3, v4;
00051     };
00052 
00053     struct Normal
00054     {
00055         float x, y, z;
00056     };
00057 
00058     Scene *mScene;
00059 
00060 public:
00061     GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
00062 
00063     void exportGeom(Scene *sce);
00064 
00065     void operator()(Object *ob);
00066 
00067     // powerful because it handles both cases when there is material and when there's not
00068     void createPolylist(short material_index,
00069                         bool has_uvs,
00070                         bool has_color,
00071                         Object *ob,
00072                         std::string& geom_id,
00073                         std::vector<Face>& norind);
00074     
00075     // creates <source> for positions
00076     void createVertsSource(std::string geom_id, Mesh *me);
00077 
00078     void createVertexColorSource(std::string geom_id, Mesh *me);
00079 
00080     std::string makeTexcoordSourceId(std::string& geom_id, int layer_index);
00081 
00082     //creates <source> for texcoords
00083     void createTexcoordsSource(std::string geom_id, Mesh *me);
00084 
00085     //creates <source> for normals
00086     void createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal>& nor);
00087 
00088     void create_normals(std::vector<Normal> &nor, std::vector<Face> &ind, Mesh *me);
00089     
00090     std::string getIdBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix = "");
00091     
00092     COLLADASW::URI getUrlBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix = "");
00093 
00094     COLLADASW::URI makeUrl(std::string id);
00095     
00096     /* int getTriCount(MFace *faces, int totface);*/
00097 private:
00098     std::set<std::string> exportedGeometry;
00099     
00100     const ExportSettings *export_settings;
00101 };
00102 
00103 struct GeometryFunctor {
00104     // f should have
00105     // void operator()(Object* ob)
00106     template<class Functor>
00107     void forEachMeshObjectInScene(Scene *sce, Functor &f, bool export_selected)
00108     {
00109         
00110         Base *base= (Base*) sce->base.first;
00111         while(base) {
00112             Object *ob = base->object;
00113             
00114             if (ob->type == OB_MESH && ob->data
00115                 && !(export_selected && !(ob->flag && SELECT))
00116                 && ((sce->lay & ob->lay)!=0)) {
00117                 f(ob);
00118             }
00119             base= base->next;
00120             
00121         }
00122     }
00123 };
00124 
00125 #endif