Blender V4.5
GeometryExporter.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <set>
12#include <string>
13#include <vector>
14
15#include "COLLADASWInputList.h"
16#include "COLLADASWLibraryGeometries.h"
17#include "COLLADASWStreamWriter.h"
18
19#include "DNA_key_types.h"
20#include "DNA_mesh_types.h"
21#include "DNA_object_types.h"
22#include "DNA_scene_types.h"
23
24#include "BlenderContext.h"
25#include "ExportSettings.h"
26#include "collada_utils.h"
27
28class Normal {
29 public:
30 float x;
31 float y;
32 float z;
33
34 friend bool operator<(const Normal &, const Normal &);
35};
36
37bool operator<(const Normal &, const Normal &);
38
39/* TODO: optimize UV sets by making indexed list with duplicates removed */
40class GeometryExporter : COLLADASW::LibraryGeometries {
41 struct Face {
42 unsigned int v1, v2, v3, v4;
43 };
44
45 public:
46 /* TODO: optimize UV sets by making indexed list with duplicates removed */
48 COLLADASW::StreamWriter *sw,
49 BCExportSettings &export_settings)
50 : COLLADASW::LibraryGeometries(sw),
51 blender_context(blender_context),
52 export_settings(export_settings)
53 {
54 }
55
56 void exportGeom();
57
58 void operator()(Object *ob);
59
60 void createLooseEdgeList(Object *ob, Mesh *mesh, std::string &geom_id);
61
63 void create_mesh_primitive_list(short material_index,
64 bool has_uvs,
65 bool has_color,
66 Object *ob,
67 Mesh *mesh,
68 std::string &geom_id,
69 std::vector<BCPolygonNormalsIndices> &norind);
70
72 void createVertsSource(std::string geom_id, Mesh *mesh);
73
74 void createVertexColorSource(std::string geom_id, Mesh *mesh);
75
76 std::string makeTexcoordSourceId(std::string &geom_id, int layer_index, bool is_single_layer);
77
79 void createTexcoordsSource(std::string geom_id, Mesh *mesh);
80
82 void createNormalsSource(std::string geom_id, Mesh *mesh, std::vector<Normal> &nor);
83
84 void create_normals(std::vector<Normal> &nor,
85 std::vector<BCPolygonNormalsIndices> &polygons_normals,
86 Mesh *mesh);
87
88 std::string getIdBySemantics(std::string geom_id,
89 COLLADASW::InputSemantic::Semantics type,
90 std::string other_suffix = "");
91 std::string makeVertexColorSourceId(std::string &geom_id, const char *layer_name);
92
93 COLLADASW::URI getUrlBySemantics(std::string geom_id,
94 COLLADASW::InputSemantic::Semantics type,
95 std::string other_suffix = "");
96
97 COLLADASW::URI makeUrl(std::string id);
98
99 void export_key_mesh(Object *ob, Mesh *mesh, KeyBlock *kb);
100
101 private:
102 std::set<std::string> exportedGeometry;
103 BlenderContext &blender_context;
104 BCExportSettings &export_settings;
105
106 Mesh *get_mesh(Scene *sce, Object *ob, int apply_modifiers);
107};
108
110 /* f should have
111 * void operator()(Object *ob) */
112 template<class Functor>
113 void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
114 {
115 LinkNode *node;
116 for (node = export_set; node; node = node->next) {
117 Object *ob = (Object *)node->link;
118 if (ob->type == OB_MESH) {
119 f(ob);
120 }
121 }
122 }
123};
Object is a sort of wrapper for general info.
@ OB_MESH
bool operator<(const Normal &, const Normal &)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void createVertsSource(std::string geom_id, Mesh *mesh)
GeometryExporter(BlenderContext &blender_context, COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
void createLooseEdgeList(Object *ob, Mesh *mesh, std::string &geom_id)
void createTexcoordsSource(std::string geom_id, Mesh *mesh)
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)
void createNormalsSource(std::string geom_id, Mesh *mesh, std::vector< Normal > &nor)
void operator()(Object *ob)
void create_mesh_primitive_list(short material_index, bool has_uvs, bool has_color, Object *ob, Mesh *mesh, std::string &geom_id, std::vector< BCPolygonNormalsIndices > &norind)
std::string getIdBySemantics(std::string geom_id, COLLADASW::InputSemantic::Semantics type, std::string other_suffix="")
void create_normals(std::vector< Normal > &nor, std::vector< BCPolygonNormalsIndices > &polygons_normals, Mesh *mesh)
std::string makeVertexColorSourceId(std::string &geom_id, const char *layer_name)
void export_key_mesh(Object *ob, Mesh *mesh, KeyBlock *kb)
void createVertexColorSource(std::string geom_id, Mesh *mesh)
friend bool operator<(const Normal &, const Normal &)
uint nor
void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
void * link
struct LinkNode * next