@@ -29,22 +29,21 @@ Mesh ReadMesh(const std::string& filename) {
29
29
auto mesh = Mesh{};
30
30
31
31
// Positions.
32
- auto add_position = thinks::obj_io::MakeAddFunc <
33
- thinks::obj_io::Position <float , 3 >>([&mesh](const auto & pos) {
32
+ auto add_position = thinks::MakeObjAddFunc <
33
+ thinks::ObjPosition <float , 3 >>([&mesh](const auto & pos) {
34
34
mesh.positions .push_back (Vec3{pos.values [0 ], pos.values [1 ], pos.values [2 ]});
35
35
});
36
36
37
37
// Normals.
38
- auto add_normal = thinks::obj_io::MakeAddFunc <
39
- thinks::obj_io::Normal <float >>([&mesh](const auto & nml) {
38
+ auto add_normal = thinks::MakeObjAddFunc <
39
+ thinks::ObjNormal <float >>([&mesh](const auto & nml) {
40
40
mesh.normals .push_back (Vec3{nml.values [0 ], nml.values [1 ], nml.values [2 ]});
41
41
});
42
42
43
43
// Faces.
44
- using ObjFaceType =
45
- thinks::obj_io::TriangleFace<thinks::obj_io::IndexGroup<uint16_t >>;
44
+ using ObjFaceType = thinks::ObjTriangleFace<thinks::ObjIndexGroup<uint16_t >>;
46
45
auto add_face =
47
- thinks::obj_io::MakeAddFunc <ObjFaceType>([&mesh](const auto & face) {
46
+ thinks::MakeObjAddFunc <ObjFaceType>([&mesh](const auto & face) {
48
47
mesh.position_indices .push_back (face.values [0 ].position_index .value );
49
48
mesh.position_indices .push_back (face.values [1 ].position_index .value );
50
49
mesh.position_indices .push_back (face.values [2 ].position_index .value );
@@ -61,9 +60,9 @@ Mesh ReadMesh(const std::string& filename) {
61
60
62
61
auto ifs = std::ifstream (filename);
63
62
assert (ifs);
64
- const auto result = thinks::obj_io::Read (ifs, add_position, add_face,
65
- nullptr , // no texture coordinates.
66
- add_normal);
63
+ const auto result = thinks::ReadObj (ifs, add_position, add_face,
64
+ nullptr , // no texture coordinates.
65
+ add_normal);
67
66
ifs.close ();
68
67
69
68
return mesh;
@@ -74,14 +73,14 @@ void WriteMesh(const std::string& filename, const Mesh& mesh) {
74
73
const auto pos_iend = std::end (mesh.positions );
75
74
auto pos_iter = std::begin (mesh.positions );
76
75
auto pos_mapper = [&pos_iter, pos_iend]() {
77
- using ObjPositionType = thinks::obj_io::Position <float , 3 >;
76
+ using ObjPositionType = thinks::ObjPosition <float , 3 >;
78
77
79
78
if (pos_iter == pos_iend) {
80
- return thinks::obj_io::End <ObjPositionType>();
79
+ return thinks::ObjEnd <ObjPositionType>();
81
80
}
82
81
83
82
const auto pos = *pos_iter++;
84
- return thinks::obj_io::Map (ObjPositionType (pos.x , pos.y , pos.z ));
83
+ return thinks::ObjMap (ObjPositionType (pos.x , pos.y , pos.z ));
85
84
};
86
85
87
86
// Faces.
@@ -91,12 +90,12 @@ void WriteMesh(const std::string& filename, const Mesh& mesh) {
91
90
auto nml_idx_iter = std::begin (mesh.normal_indices );
92
91
auto face_mapper = [&pos_idx_iter, &nml_idx_iter, pos_idx_iend,
93
92
nml_idx_iend]() {
94
- using ObjIndexType = thinks::obj_io::IndexGroup <uint16_t >;
95
- using ObjFaceType = thinks::obj_io::TriangleFace <ObjIndexType>;
93
+ using ObjIndexType = thinks::ObjIndexGroup <uint16_t >;
94
+ using ObjFaceType = thinks::ObjTriangleFace <ObjIndexType>;
96
95
97
96
if (distance (pos_idx_iter, pos_idx_iend) < 3 ||
98
97
distance (nml_idx_iter, nml_idx_iend) < 3 ) {
99
- return thinks::obj_io::End <ObjFaceType>();
98
+ return thinks::ObjEnd <ObjFaceType>();
100
99
}
101
100
102
101
const auto pos_idx0 = *pos_idx_iter++;
@@ -107,40 +106,34 @@ void WriteMesh(const std::string& filename, const Mesh& mesh) {
107
106
const auto nml_idx2 = *nml_idx_iter++;
108
107
109
108
// No texture coordinates.
110
- return thinks::obj_io::Map (
111
- ObjFaceType (ObjIndexType (
112
- pos_idx0,
113
- std::make_pair (0 , false ),
114
- std::make_pair (nml_idx0, true )),
115
- ObjIndexType (
116
- pos_idx1,
117
- std::make_pair (0 , false ),
118
- std::make_pair (nml_idx1, true )),
119
- ObjIndexType (
120
- pos_idx2,
121
- std::make_pair (0 , false ),
122
- std::make_pair (nml_idx2, true ))));
109
+ return thinks::ObjMap (
110
+ ObjFaceType (ObjIndexType (pos_idx0, std::make_pair (0 , false ),
111
+ std::make_pair (nml_idx0, true )),
112
+ ObjIndexType (pos_idx1, std::make_pair (0 , false ),
113
+ std::make_pair (nml_idx1, true )),
114
+ ObjIndexType (pos_idx2, std::make_pair (0 , false ),
115
+ std::make_pair (nml_idx2, true ))));
123
116
};
124
117
125
118
// Normals.
126
119
const auto nml_iend = end (mesh.normals );
127
120
auto nml_iter = begin (mesh.normals );
128
121
auto nml_mapper = [&nml_iter, nml_iend]() {
129
- using ObjNormalType = thinks::obj_io::Normal <float >;
122
+ using ObjNormalType = thinks::ObjNormal <float >;
130
123
131
124
if (nml_iter == nml_iend) {
132
- return thinks::obj_io::End <ObjNormalType>();
125
+ return thinks::ObjEnd <ObjNormalType>();
133
126
}
134
127
135
128
const auto nml = *nml_iter++;
136
- return thinks::obj_io::Map (ObjNormalType (nml.x , nml.y , nml.z ));
129
+ return thinks::ObjMap (ObjNormalType (nml.x , nml.y , nml.z ));
137
130
};
138
131
139
132
auto ofs = std::ofstream (filename);
140
133
assert (ofs);
141
- const auto result = thinks::obj_io::Write (ofs, pos_mapper, face_mapper,
142
- nullptr , // No texture coordinates.
143
- nml_mapper);
134
+ const auto result = thinks::WriteObj (ofs, pos_mapper, face_mapper,
135
+ nullptr , // No texture coordinates.
136
+ nml_mapper);
144
137
ofs.close ();
145
138
}
146
139
0 commit comments