diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2010-10-06 13:53:06 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2010-10-06 13:53:06 +0400 |
commit | c88a46e585ff5924be6ec2b5b8cdf9d2ff8faefa (patch) | |
tree | 8a721b8bd8ec95c889d9a6433448deff44c51158 /source/blender/collada/GeometryExporter.h | |
parent | d6b235f3ef70811e035a13f1110de95592c09324 (diff) |
COLLADACOLLADA exporter: split geometry export into own files.
Diffstat (limited to 'source/blender/collada/GeometryExporter.h')
-rw-r--r-- | source/blender/collada/GeometryExporter.h | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h new file mode 100644 index 00000000000..4ea3cb4efdf --- /dev/null +++ b/source/blender/collada/GeometryExporter.h @@ -0,0 +1,114 @@ +/** + * $Id: DocumentExporter.cpp 32309 2010-10-05 00:05:14Z jesterking $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed, + * Nathan Letwory + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __GEOMETRYEXPORTER_H__ +#define __GEOMETRYEXPORTER_H__ + +#include <string> +#include <vector> + +#include "COLLADASWStreamWriter.h" +#include "COLLADASWLibraryGeometries.h" +#include "COLLADASWInputList.h" + +#include "DNA_mesh_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +// TODO: optimize UV sets by making indexed list with duplicates removed +class GeometryExporter : COLLADASW::LibraryGeometries +{ + struct Face + { + unsigned int v1, v2, v3, v4; + }; + + struct Normal + { + float x, y, z; + }; + + Scene *mScene; + +public: + GeometryExporter(COLLADASW::StreamWriter *sw); + + void exportGeom(Scene *sce); + + void operator()(Object *ob); + + // powerful because it handles both cases when there is material and when there's not + void createPolylist(int material_index, + bool has_uvs, + bool has_color, + Object *ob, + std::string& geom_id, + std::vector<Face>& norind); + + // creates <source> for positions + void createVertsSource(std::string geom_id, Mesh *me); + + void createVertexColorSource(std::string geom_id, Mesh *me); + + std::string makeTexcoordSourceId(std::string& geom_id, int layer_index); + + //creates <source> for texcoords + void createTexcoordsSource(std::string geom_id, Mesh *me); + + //creates <source> for normals + void createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal>& nor); + + void create_normals(std::vector<Normal> &nor, std::vector<Face> &ind, Mesh *me); + + std::string getIdBySemantics(std::string geom_id, COLLADASW::Semantics type, std::string other_suffix = ""); + + COLLADASW::URI getUrlBySemantics(std::string geom_id, COLLADASW::Semantics type, std::string other_suffix = ""); + + COLLADASW::URI makeUrl(std::string id); + + /* int getTriCount(MFace *faces, int totface);*/ +}; + +struct GeometryFunctor { + // f should have + // void operator()(Object* ob) + template<class Functor> + void forEachMeshObjectInScene(Scene *sce, Functor &f) + { + + Base *base= (Base*) sce->base.first; + while(base) { + Object *ob = base->object; + + if (ob->type == OB_MESH && ob->data) { + f(ob); + } + base= base->next; + + } + } +}; + +#endif |