more cleanup

This commit is contained in:
maxbyte9p
2024-05-21 10:48:33 -04:00
parent 7dc9fc2f23
commit 40d88cdb9f

View File

@@ -13,8 +13,6 @@ struct Joint {
std::vector<float> n;
};
//template<> Joint joint(const std::string& str) {
//template<typename T>
void operator>>(std::istream& in, Joint& q) {
in >> q.name >> q.x;
@@ -26,15 +24,18 @@ void operator>>(std::istream& in, Joint& q) {
}
}
// Parse joints
std::vector<Joint> parse_j(std::istringstream& s, std::ifstream& f) {
// get count
int jcnt;
s >> jcnt;
std::cout << "j " << jcnt << std::endl;
// return later
std::vector<Joint> js;
// parse lines until count
int i;
for (i=0; i<jcnt; i++) {
std::string l;
@@ -53,31 +54,6 @@ std::vector<Joint> parse_j(std::istringstream& s, std::ifstream& f) {
return js;
}
// Parse joints
/*
std::vector<std::tuple<std::string, int, float>>
parse_j(std::istringstream& s, std::ifstream& f) {
int jcnt;
s >> jcnt;
std::cout << "j " << jcnt << std::endl;
std::vector<std::tuple<std::string, int, float>> j;
int i;
for (i=0; i<jcnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
stream >> j[i];
} else {
break;
}
}
return j;
}
*/
struct Face {
std::vector<int> n;
@@ -92,13 +68,17 @@ void operator>>(std::istream& in, Face& q) {
}
}
// Parse faces
std::vector<Face> parse_f(std::istringstream& s, std::ifstream& f) {
// get count
int facescnt;
s >> facescnt;
std::cout << "f " << facescnt << std::endl;
// return later
std::vector<Face> faces;
// parse until count
int i;
for (i=0; i<facescnt; i++) {
std::string l;
@@ -119,78 +99,42 @@ std::vector<Face> parse_f(std::istringstream& s, std::ifstream& f) {
return faces;
}
/*
// Parse faces
std::vector<std::tuple<int,int,int,int,int,int,int,int,int,int,int,int,int,int,int>>
parse_f(std::istringstream& s, std::ifstream& f) {
// Get faces count
int facescnt;
s >> facescnt;
std::cout << "f " << facescnt << std::endl;
struct Vweight {
std::vector<float> n;
};
// store faces for returning later
std::vector<std::tuple<int,int,int,int,int,int,int,int,int,int,int,int,int,int,int>> faces;
// Parse until fcnt
void operator>>(std::istream& in, Vweight& q) {
int i;
for (i=0; i<facescnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
int x = 0;
int y = 0;
int z = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int g = 0;
int h = 0;
int j = 0;
int k = 0;
int m = 0;
int n = 0;
int o = 0;
stream >> x >> y >> z >> a >> b >> c >> d >> e >> g >> h >> j >> k >> m >> n >> o;
faces.push_back({x, y, z, a, b, c, d, e, g, h, j, k, m, n, o});
} else {
break;
}
for (i=0; i<4; i++) {
float v;
in >> v;
q.n.push_back(v);
}
return faces;
}
*/
// Parse vertex weights
std::vector<std::tuple<float, float, float, float>> parse_vw(std::istringstream& s, std::ifstream& f) {
// Get vertex weights count
std::vector<Vweight> parse_vw(std::istringstream& s, std::ifstream& f) {
// get count
int vwcnt;
s >> vwcnt;
std::cout << "vw " << vwcnt << std::endl;
// Store our vertex weights for returning later
std::vector<std::tuple<float, float, float, float>> vw;
// return later
std::vector<Vweight> vw;
// Parse until vwcnt
// parse lines until count
int i;
for (i=0; i<vwcnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
float x = 0;
float y = 0;
float z = 0;
float a = 0;
stream >> x >> y >> z >> a;
// For debugging -> std::cout << l << std::endl;
vw.push_back({x,y,z,a});
Vweight vweight;
stream >> vweight;
vw.push_back(vweight);
} else {
break;
}
@@ -199,33 +143,43 @@ std::vector<std::tuple<float, float, float, float>> parse_vw(std::istringstream&
return vw;
}
struct Vjoint {
std::vector<int> n;
};
void operator>>(std::istream& in, Vjoint& q) {
int i;
for (i=0; i<4; i++) {
int v;
in >> v;
q.n.push_back(v);
}
}
// Parse vertex joints
std::vector<std::tuple<int, int, int, int>> parse_vj(std::istringstream& s, std::ifstream& f) {
// Get vertex joints count
std::vector<Vjoint> parse_vj(std::istringstream& s, std::ifstream& f) {
// get count
int vjcnt;
s >> vjcnt;
std::cout << "vj " << vjcnt << std::endl;
// Store our vertex joints for returning later
std::vector<std::tuple<int, int, int, int>> vj;
// return later
std::vector<Vjoint> vj;
// Parse until vjcnt
// parse lines until count
int i;
for (i=0; i<vjcnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
int x = 0;
int y = 0;
int z = 0;
int a = 0;
stream >> x >> y >> z >> a;
// For debugging -> std::cout << l << std::endl;
vj.push_back({x,y,z,a});
} else {
Vjoint vjoint;
stream >> vjoint;
vj.push_back(vjoint);
} else {
break;
}
}
@@ -394,17 +348,40 @@ void Model::loadAMO(const std::string& filename) {
std::cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << std::endl;
}
} else if (prefix == "vj") {
std::vector<std::tuple<int, int, int, int>> vj;
/*std::vector<std::tuple<int, int, int, int>> vj;
vj = parse_vj(stream, file);
for (const std::tuple<int, int, int, int>& i : vj) {
std::cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << " " << get<3>(i) << std::endl;
}
*/
std::vector<Vjoint> vj;
vj = parse_vj(stream, file);
for (const Vjoint& i: vj) {
for (const int& ii: i.n) {
std::cout << ii << " ";
}
std::cout << std::endl;
}
} else if (prefix == "vw") {
/*
std::vector<std::tuple<float, float, float, float>> vw;
vw = parse_vw(stream, file);
for (const std::tuple<float, float, float, float>& i : vw) {
std::cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << " " << get<3>(i) << std::endl;
}
*/
std::vector<Vweight> vw;
vw = parse_vw(stream, file);
for (const Vweight& i: vw) {
for (const float& ii: i.n) {
std::cout << ii << " ";
}
std::cout << std::endl;
}
} else if (prefix == "f") {
/*
std::vector<std::tuple<int,int,int,int,int,int,int,int,int,int,int,int,int,int,int>> faces;