cleaned up vn parsing

This commit is contained in:
maxbyte9p
2024-05-21 11:01:16 -04:00
parent 40d88cdb9f
commit b1a6202a3b

View File

@@ -187,30 +187,42 @@ std::vector<Vjoint> parse_vj(std::istringstream& s, std::ifstream& f) {
return vj;
}
// Parse Vertex Normals
std::vector<std::tuple<float, float, float>> parse_vn(std::istringstream& s, std::ifstream& f) {
// Get vertex normals count
struct Vnormal {
std::vector<float> n;
};
void operator>>(std::istream& in, Vnormal& q) {
int i;
for (i=0; i<3; i++) {
float v;
in >> v;
q.n.push_back(v);
}
}
// Parse vertex normals
std::vector<Vnormal> parse_vn(std::istringstream& s, std::ifstream& f) {
// get count
int vncnt;
s >> vncnt;
std::cout << "vn " << vncnt << std::endl;
// store our vertex normals for returning later
std::vector<std::tuple<float, float, float>> vn;
// return later
std::vector<Vnormal> vn;
// Parse until vncnt
// parse lines until count
int i;
for (i=0; i<vncnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
float x = 0;
float y = 0;
float z = 0;
stream >> x >> y >> z;
// For debugging -> std::cout << l << std::endl;
vn.push_back({x, y, z});
Vnormal vnormal;
stream >> vnormal;
vn.push_back(vnormal);
} else {
break;
}
@@ -342,10 +354,19 @@ void Model::loadAMO(const std::string& filename) {
std::cout << get<0>(i) << " " << get<1>(i) << std::endl;
}
} else if (prefix == "vn") {
std::vector<std::tuple<float, float, float>> vn;
/*std::vector<std::tuple<float, float, float>> vn;
vn = parse_vn(stream, file);
for (const std::tuple<float, float, float>& i : vn) {
std::cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << std::endl;
}*/
std::vector<Vnormal> vn;
vn = parse_vn(stream, file);
for (const Vnormal& i: vn) {
for (const float& ii: i.n) {
std::cout << ii << " ";
}
std::cout << std::endl;
}
} else if (prefix == "vj") {
/*std::vector<std::tuple<int, int, int, int>> vj;