Cleaned up vertice parser

This commit is contained in:
maxbyte9p
2024-05-21 11:29:08 -04:00
parent 51a68240b0
commit f9085722fd

View File

@@ -275,6 +275,51 @@ std::vector<Vtexture> parse_vt(std::istringstream& s, std::ifstream& f) {
return vt;
}
struct Vertice {
std::vector<float> n;
};
void operator>>(std::istream& in, Vertice& q) {
int i;
for (i=0; i<3; i++) {
float v;
in >> v;
q.n.push_back(v);
}
}
// Parse vertices
std::vector<Vertice> parse_v(std::istringstream& s, std::ifstream& f) {
// get count
int vcnt;
s >> vcnt;
std::cout << "v " << vcnt << std::endl;
// return later
std::vector<Vertice> v;
// parses lines until count
int i;
for (i=0; i<vcnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
Vertice vertice;
stream >> vertice;
v.push_back(vertice);
} else {
break;
}
}
return v;
}
/*
// Parse Vertices
std::vector<std::tuple<float, float, float>> parse_v(std::istringstream& s, std::ifstream& f) {
// Get vertices count
@@ -305,7 +350,7 @@ std::vector<std::tuple<float, float, float>> parse_v(std::istringstream& s, std:
}
return v;
}
}*/
// Parse Animated Object
std::tuple<std::string, int> parse_ao(std::istringstream& s) {
@@ -334,10 +379,19 @@ void Model::loadAMO(const std::string& filename) {
r = parse_ao(stream);
std::cout << get<0>(r) << " " << get<1>(r) << std::endl;
} else if (prefix == "v") {
std::vector<std::tuple<float, float, float>> v;
/*std::vector<std::tuple<float, float, float>> v;
v = parse_v(stream, file);
for (const std::tuple<float, float, float>& i : v) {
std::cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << std::endl;
}*/
std::vector<Vertice> v;
v = parse_v(stream, file);
for (const Vertice& i: v) {
for (const float& ii: i.n) {
std::cout << ii << " ";
}
std::cout << std::endl;
}
} else if (prefix == "vt") {
std::vector<Vtexture> vt;