Blender V4.3
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
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 "BKE_key.hh"
25#include "BlenderContext.h"
26#include "ExportSettings.h"
27#include "collada_utils.h"
28
29class Normal {
30 public:
31 float x;
32 float y;
33 float z;
34
35 friend bool operator<(const Normal &, const Normal &);
36};
37
38bool operator<(const Normal &, const Normal &);
39
40/* TODO: optimize UV sets by making indexed list with duplicates removed */
41class GeometryExporter : COLLADASW::LibraryGeometries {
42 struct Face {
43 unsigned int v1, v2, v3, v4;
44 };
45
46 public:
47 /* TODO: optimize UV sets by making indexed list with duplicates removed */
48 GeometryExporter(BlenderContext &blender_context,
49 COLLADASW::StreamWriter *sw,
50 BCExportSettings &export_settings)
51 : COLLADASW::LibraryGeometries(sw),
52 blender_context(blender_context),
53 export_settings(export_settings)
54 {
55 }
56
57 void exportGeom();
58
59 void operator()(Object *ob);
60
61 void createLooseEdgeList(Object *ob, Mesh *mesh, std::string &geom_id);
62
64 void create_mesh_primitive_list(short material_index,
65 bool has_uvs,
66 bool has_color,
67 Object *ob,
68 Mesh *mesh,
69 std::string &geom_id,
70 std::vector<BCPolygonNormalsIndices> &norind);
71
73 void createVertsSource(std::string geom_id, Mesh *mesh);
74
75 void createVertexColorSource(std::string geom_id, Mesh *mesh);
76
77 std::string makeTexcoordSourceId(std::string &geom_id, int layer_index, bool is_single_layer);
78
80 void createTexcoordsSource(std::string geom_id, Mesh *mesh);
81
83 void createNormalsSource(std::string geom_id, Mesh *mesh, std::vector<Normal> &nor);
84
85 void create_normals(std::vector<Normal> &nor,
86 std::vector<BCPolygonNormalsIndices> &polygons_normals,
87 Mesh *mesh);
88
89 std::string getIdBySemantics(std::string geom_id,
90 COLLADASW::InputSemantic::Semantics type,
91 std::string other_suffix = "");
92 std::string makeVertexColorSourceId(std::string &geom_id, const char *layer_name);
93
94 COLLADASW::URI getUrlBySemantics(std::string geom_id,
95 COLLADASW::InputSemantic::Semantics type,
96 std::string other_suffix = "");
97
98 COLLADASW::URI makeUrl(std::string id);
99
100 void export_key_mesh(Object *ob, Mesh *mesh, KeyBlock *kb);
101
102 private:
103 std::set<std::string> exportedGeometry;
104 BlenderContext &blender_context;
105 BCExportSettings &export_settings;
106
107 Mesh *get_mesh(Scene *sce, Object *ob, int apply_modifiers);
108};
109
111 /* f should have
112 * void operator()(Object *ob) */
113 template<class Functor>
114 void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
115 {
116 LinkNode *node;
117 for (node = export_set; node; node = node->next) {
118 Object *ob = (Object *)node->link;
119 if (ob->type == OB_MESH) {
120 f(ob);
121 }
122 }
123 }
124};
Object is a sort of wrapper for general info.
@ OB_MESH
bool operator<(const Normal &, const Normal &)
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 &)
OperationNode * node
Frequency::GEOMETRY nor[]
void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
struct LinkNode * next