Blender  V2.93
GeometryExporter.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #pragma once
22 
23 #include <set>
24 #include <string>
25 #include <vector>
26 
27 #include "COLLADASWInputList.h"
28 #include "COLLADASWLibraryGeometries.h"
29 #include "COLLADASWStreamWriter.h"
30 
31 #include "DNA_key_types.h"
32 #include "DNA_mesh_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_scene_types.h"
35 
36 #include "BKE_key.h"
37 #include "BlenderContext.h"
38 #include "ExportSettings.h"
39 #include "collada_utils.h"
40 
41 class Normal {
42  public:
43  float x;
44  float y;
45  float z;
46 
47  friend bool operator<(const Normal &, const Normal &);
48 };
49 
50 bool operator<(const Normal &, const Normal &);
51 
52 /* TODO: optimize UV sets by making indexed list with duplicates removed */
53 class GeometryExporter : COLLADASW::LibraryGeometries {
54  struct Face {
55  unsigned int v1, v2, v3, v4;
56  };
57 
58  public:
59  /* TODO: optimize UV sets by making indexed list with duplicates removed */
60  GeometryExporter(BlenderContext &blender_context,
61  COLLADASW::StreamWriter *sw,
62  BCExportSettings &export_settings)
63  : COLLADASW::LibraryGeometries(sw),
64  blender_context(blender_context),
65  export_settings(export_settings)
66  {
67  }
68 
69  void exportGeom();
70 
71  void operator()(Object *ob);
72 
73  void createLooseEdgeList(Object *ob, Mesh *me, std::string &geom_id);
74 
75  /* powerful because it handles both cases when there is material and when there's not */
76  void create_mesh_primitive_list(short material_index,
77  bool has_uvs,
78  bool has_color,
79  Object *ob,
80  Mesh *me,
81  std::string &geom_id,
82  std::vector<BCPolygonNormalsIndices> &norind);
83 
84  /* creates <source> for positions */
85  void createVertsSource(std::string geom_id, Mesh *me);
86 
87  void createVertexColorSource(std::string geom_id, Mesh *me);
88 
89  std::string makeTexcoordSourceId(std::string &geom_id, int layer_index, bool is_single_layer);
90 
91  /* creates <source> for texcoords */
92  void createTexcoordsSource(std::string geom_id, Mesh *me);
93 
94  /* creates <source> for normals */
95  void createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal> &nor);
96 
97  void create_normals(std::vector<Normal> &nor,
98  std::vector<BCPolygonNormalsIndices> &polygons_normals,
99  Mesh *me);
100 
101  std::string getIdBySemantics(std::string geom_id,
102  COLLADASW::InputSemantic::Semantics type,
103  std::string other_suffix = "");
104  std::string makeVertexColorSourceId(std::string &geom_id, char *layer_name);
105 
106  COLLADASW::URI getUrlBySemantics(std::string geom_id,
107  COLLADASW::InputSemantic::Semantics type,
108  std::string other_suffix = "");
109 
110  COLLADASW::URI makeUrl(std::string id);
111 
112  void export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb);
113 
114  private:
115  std::set<std::string> exportedGeometry;
116  BlenderContext &blender_context;
117  BCExportSettings &export_settings;
118 
119  Mesh *get_mesh(Scene *sce, Object *ob, int apply_modifiers);
120 };
121 
123  /* f should have
124  * void operator()(Object *ob) */
125  template<class Functor>
126  void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
127  {
128  LinkNode *node;
129  for (node = export_set; node; node = node->next) {
130  Object *ob = (Object *)node->link;
131  if (ob->type == OB_MESH) {
132  f(ob);
133  }
134  }
135  }
136 };
Object is a sort of wrapper for general info.
@ OB_MESH
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
bool operator<(const Normal &, const Normal &)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
GeometryExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
void create_normals(std::vector< Normal > &nor, std::vector< BCPolygonNormalsIndices > &polygons_normals, Mesh *me)
COLLADASW::URI getUrlBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix="")
COLLADASW::URI makeUrl(std::string id)
std::string makeTexcoordSourceId(std::string &geom_id, int layer_index, bool is_single_layer)
std::string makeVertexColorSourceId(std::string &geom_id, char *layer_name)
void export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb)
void operator()(Object *ob)
void create_mesh_primitive_list(short material_index, bool has_uvs, bool has_color, Object *ob, Mesh *me, std::string &geom_id, std::vector< BCPolygonNormalsIndices > &norind)
void createVertexColorSource(std::string geom_id, Mesh *me)
std::string getIdBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix="")
void createLooseEdgeList(Object *ob, Mesh *me, std::string &geom_id)
void createTexcoordsSource(std::string geom_id, Mesh *me)
void createVertsSource(std::string geom_id, Mesh *me)
void createNormalsSource(std::string geom_id, Mesh *me, std::vector< Normal > &nor)
friend bool operator<(const Normal &, const Normal &)
OperationNode * node
uint nor
struct Face Face
void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)