11 if (_file_path.size() > 4 && !_file_path.substr(_file_path.size()-4).compare(
".obj")) {
14 else if (_file_path.size() > 4 && !_file_path.substr(_file_path.size()-4).compare(
".dat"))
20 std::cout <<
"Valid file extensions are \"obj\" and \"dat\" !" << std::endl;
41 std::cout <<
"Loading geometry from file \"" <<
file_path <<
"\"." << std::endl;
66 std::cout <<
"Failed to open file \"" <<
file_path <<
"\" !" << std::endl;
85 std::ifstream binary_file;
86 binary_file.open(this->
file_path, std::ofstream::binary | std::ofstream::in);
90 binary_file.read(reinterpret_cast< char *>(&
single_ind),
sizeof(
unsigned int));
91 binary_file.read(reinterpret_cast< char *>(&
nr_face_ind),
sizeof(
unsigned int));
105 binary_file.read(reinterpret_cast< char *>(
vert_uvs),
single_ind * 3 *
sizeof(GLfloat));
120 int last_slash = this->
file_path.find_last_of(
"/\\");
121 std::string dir_name =
file_path.substr(0,last_slash);
122 std::string file_name_ext =
file_path.substr(last_slash + 1);
124 int last_dot = file_name_ext.find_last_of(
".");
125 std::string file_name = file_name_ext.substr(0,last_dot);
126 std::string file_ext = file_name_ext.substr(last_dot + 1);
128 std::string binary_file_name = dir_name +
"/" + file_name +
".dat";
129 std::cout <<
"Writing to file : \"" << binary_file_name <<
"\" ..." << std::endl;
132 std::ofstream binary_file;
133 binary_file.open(binary_file_name, std::ofstream::binary | std::ofstream::out);
137 binary_file.write(reinterpret_cast<const char *>(&
single_ind),
sizeof(
unsigned int));
138 binary_file.write(reinterpret_cast<const char *>(&
nr_face_ind),
sizeof(
unsigned int));
141 binary_file.write(reinterpret_cast<const char *>(
vert_uvs),
single_ind * 3 *
sizeof(GLfloat));
160 std::cout <<
"Drive not ready or permission denied" << std::endl;
163 std::cout <<
"Could not find this file" << std::endl;
166 perror(
"opening data file");
184 std::ifstream file_stream(_f);
185 std::string file_line;
186 while (!file_stream.eof())
188 std::getline(file_stream, file_line);
191 if (!file_line.substr(0,2).compare(
"v "))
194 for (
unsigned int i = 0; i < vert_pos.size(); i++)
200 else if (!file_line.substr(0,3).compare(
"vn "))
203 for (
unsigned int i = 0; i < vert_norm.size(); i++)
209 else if (!file_line.substr(0,3).compare(
"vt "))
212 for (
unsigned int i = 0; i < text_coord.size(); i++)
222 else if (!file_line.substr(0,2).compare(
"f "))
225 for (
unsigned int i = 0; i < indices.size(); i++)
248 std::stringstream line_ss(_line);
251 std::string str_item;
252 while(std::getline(line_ss,str_item,
' '))
255 std::stringstream item_ss(str_item);
256 if (!(item_ss>>num).fail())
258 vert_pos.push_back(num);
271 std::stringstream line_ss(_line);
276 std::string str_item;
277 while(std::getline(line_ss,str_item,
' '))
279 std::stringstream item_ss(str_item);
280 std::string str_single_index;
281 while(std::getline(item_ss,str_single_index,
'/'))
284 std::stringstream single_index_ss(str_single_index);
285 if (!(single_index_ss>>ind).fail())
287 face_ind.push_back(ind);
297 if (_ic1.size() < 2 || _ic2.size() < 2 || _ic1.size() != _ic2.size())
303 for (
unsigned int i = 0; i < _ic1.size()-1; i++)
305 equal = equal && (_ic1.at(i) == _ic2.at(i));
328 unsigned int ind_texture_coord =
face_ind_OBJ.at(i * 3 + 1);
329 unsigned int ind_vertex_normal =
face_ind_OBJ.at(i * 3 + 2);
334 next_mult_index.push_back(ind_vertex_pos);
335 next_mult_index.push_back(ind_texture_coord);
336 next_mult_index.push_back(ind_vertex_normal);
342 bool already_used =
false;