31
31
#include < vclib/load_save/settings.h>
32
32
#include < vclib/misc/logger.h>
33
33
#include < vclib/space/complex/mesh_info.h>
34
+ #include < vclib/space/core/texture.h>
34
35
35
36
#include < map>
36
37
@@ -79,6 +80,21 @@ ObjMaterial objMaterialFromFace(
79
80
return mat;
80
81
}
81
82
83
+ template <EdgeConcept EdgeType, MeshConcept MeshType>
84
+ ObjMaterial objMaterialFromEdge (const EdgeType& e, const MeshInfo& fi)
85
+ {
86
+ ObjMaterial mat;
87
+ if constexpr (HasPerEdgeColor<MeshType>) {
88
+ if (fi.hasEdgeColors ()) {
89
+ mat.hasColor = true ;
90
+ mat.Kd .x () = e.color ().redF ();
91
+ mat.Kd .y () = e.color ().greenF ();
92
+ mat.Kd .z () = e.color ().blueF ();
93
+ }
94
+ }
95
+ return mat;
96
+ }
97
+
82
98
template <
83
99
ElementConcept ElementType,
84
100
MeshConcept MeshType,
@@ -97,6 +113,7 @@ void writeElementObjMaterial(
97
113
ObjMaterial mat;
98
114
constexpr bool EL_IS_VERTEX = ElementType::ELEMENT_ID == ElemId::VERTEX;
99
115
constexpr bool EL_IS_FACE = ElementType::ELEMENT_ID == ElemId::FACE;
116
+ constexpr bool EL_IS_EDGE = ElementType::ELEMENT_ID == ElemId::EDGE;
100
117
101
118
if constexpr (EL_IS_VERTEX) {
102
119
mat = objMaterialFromVertex<typename MeshType::VertexType, MeshType>(
@@ -105,6 +122,9 @@ void writeElementObjMaterial(
105
122
if constexpr (EL_IS_FACE) {
106
123
mat = objMaterialFromFace (e, m, fi);
107
124
}
125
+ if constexpr (EL_IS_EDGE) {
126
+ mat = objMaterialFromEdge<typename MeshType::EdgeType, MeshType>(e, fi);
127
+ }
108
128
if (!mat.isEmpty ()) {
109
129
static const std::string MATERIAL_PREFIX = " MATERIAL_" ;
110
130
std::string mname; // name of the material of the vertex
@@ -200,6 +220,9 @@ void saveObj(
200
220
201
221
// vertices
202
222
using VertexType = MeshType::VertexType;
223
+
224
+ fp << std::endl << " # Vertices" << std::endl;
225
+
203
226
for (const VertexType& v : m.vertices ()) {
204
227
if (useMtl) { // mtl management
205
228
detail::writeElementObjMaterial<VertexType, MeshType>(
@@ -243,6 +266,8 @@ void saveObj(
243
266
using VertexType = MeshType::VertexType;
244
267
using FaceType = MeshType::FaceType;
245
268
269
+ fp << std::endl << " # Faces" << std::endl;
270
+
246
271
// indices of vertices that do not consider deleted vertices
247
272
std::vector<uint> vIndices = m.vertexCompactIndices ();
248
273
@@ -295,6 +320,34 @@ void saveObj(
295
320
fp << std::endl;
296
321
}
297
322
}
323
+
324
+ if constexpr (HasEdges<MeshType>) {
325
+ using VertexType = MeshType::VertexType;
326
+ using EdgeType = MeshType::EdgeType;
327
+
328
+ fp << std::endl << " # Edges" << std::endl;
329
+
330
+ // indices of vertices that do not consider deleted vertices
331
+ std::vector<uint> vIndices = m.vertexCompactIndices ();
332
+
333
+ for (const EdgeType& e : m.edges ()) {
334
+ if (useMtl) { // mtl management
335
+ detail::writeElementObjMaterial (
336
+ e,
337
+ m,
338
+ meshInfo,
339
+ lastMaterial,
340
+ materialMap,
341
+ fp,
342
+ *mtlfp,
343
+ settings,
344
+ log);
345
+ }
346
+ fp << " l " ;
347
+ fp << vIndices[m.index (e.vertex (0 ))] + 1 << " " ;
348
+ fp << vIndices[m.index (e.vertex (1 ))] + 1 << std::endl;
349
+ }
350
+ }
298
351
}
299
352
300
353
} // namespace detail
0 commit comments