1 #ifndef slic3r_Format_objparser_hpp_
2 #define slic3r_Format_objparser_hpp_
3
4 #include <string>
5 #include <vector>
6 #include <istream>
7
8 namespace ObjParser {
9
10 struct ObjVertex
11 {
12 int coordIdx;
13 int textureCoordIdx;
14 int normalIdx;
15 };
16
operator ==(const ObjVertex & v1,const ObjVertex & v2)17 inline bool operator==(const ObjVertex &v1, const ObjVertex &v2)
18 {
19 return
20 v1.coordIdx == v2.coordIdx &&
21 v1.textureCoordIdx == v2.textureCoordIdx &&
22 v1.normalIdx == v2.normalIdx;
23 }
24
25 struct ObjUseMtl
26 {
27 int vertexIdxFirst;
28 std::string name;
29 };
30
operator ==(const ObjUseMtl & v1,const ObjUseMtl & v2)31 inline bool operator==(const ObjUseMtl &v1, const ObjUseMtl &v2)
32 {
33 return
34 v1.vertexIdxFirst == v2.vertexIdxFirst &&
35 v1.name.compare(v2.name) == 0;
36 }
37
38 struct ObjObject
39 {
40 int vertexIdxFirst;
41 std::string name;
42 };
43
operator ==(const ObjObject & v1,const ObjObject & v2)44 inline bool operator==(const ObjObject &v1, const ObjObject &v2)
45 {
46 return
47 v1.vertexIdxFirst == v2.vertexIdxFirst &&
48 v1.name.compare(v2.name) == 0;
49 }
50
51 struct ObjGroup
52 {
53 int vertexIdxFirst;
54 std::string name;
55 };
56
operator ==(const ObjGroup & v1,const ObjGroup & v2)57 inline bool operator==(const ObjGroup &v1, const ObjGroup &v2)
58 {
59 return
60 v1.vertexIdxFirst == v2.vertexIdxFirst &&
61 v1.name.compare(v2.name) == 0;
62 }
63
64 struct ObjSmoothingGroup
65 {
66 int vertexIdxFirst;
67 int smoothingGroupID;
68 };
69
operator ==(const ObjSmoothingGroup & v1,const ObjSmoothingGroup & v2)70 inline bool operator==(const ObjSmoothingGroup &v1, const ObjSmoothingGroup &v2)
71 {
72 return
73 v1.vertexIdxFirst == v2.vertexIdxFirst &&
74 v1.smoothingGroupID == v2.smoothingGroupID;
75 }
76
77 struct ObjData {
78 // Version of the data structure for load / store in the private binary format.
79 int version;
80
81 // x, y, z, w
82 std::vector<float> coordinates;
83 // u, v, w
84 std::vector<float> textureCoordinates;
85 // x, y, z
86 std::vector<float> normals;
87 // u, v, w
88 std::vector<float> parameters;
89
90 std::vector<std::string> mtllibs;
91 std::vector<ObjUseMtl> usemtls;
92 std::vector<ObjObject> objects;
93 std::vector<ObjGroup> groups;
94 std::vector<ObjSmoothingGroup> smoothingGroups;
95
96 // List of faces, delimited by an ObjVertex with all members set to -1.
97 std::vector<ObjVertex> vertices;
98 };
99
100 extern bool objparse(const char *path, ObjData &data);
101 extern bool objparse(std::istream &stream, ObjData &data);
102
103 extern bool objbinsave(const char *path, const ObjData &data);
104
105 extern bool objbinload(const char *path, ObjData &data);
106
107 extern bool objequal(const ObjData &data1, const ObjData &data2);
108
109 } // namespace ObjParser
110
111 #endif /* slic3r_Format_objparser_hpp_ */
112