rewriting shittastic AMO parsing.
This commit is contained in:
202
src/amo.cpp
202
src/amo.cpp
@@ -3,9 +3,169 @@
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <Collage/types/model.h>
|
||||
|
||||
struct Joint {
|
||||
std::string name;
|
||||
int x;
|
||||
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;
|
||||
|
||||
int i;
|
||||
for (i=0; i<16; i++) {
|
||||
float f;
|
||||
in >> f;
|
||||
q.n.push_back(f);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Joint> parse_j(std::istringstream& s, std::ifstream& f) {
|
||||
int jcnt;
|
||||
s >> jcnt;
|
||||
std::cout << "j " << jcnt << std::endl;
|
||||
|
||||
std::vector<Joint> js;
|
||||
|
||||
int i;
|
||||
|
||||
for (i=0; i<jcnt; i++) {
|
||||
std::string l;
|
||||
|
||||
if (getline(f, l)) {
|
||||
std::istringstream stream(l);
|
||||
|
||||
Joint j;
|
||||
|
||||
stream >> j;
|
||||
|
||||
js.push_back(j);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
void operator>>(std::istream& in, Face& q) {
|
||||
int i;
|
||||
for (i=0; i<15; i++) {
|
||||
int v;
|
||||
in >> v;
|
||||
q.n.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Face> parse_f(std::istringstream& s, std::ifstream& f) {
|
||||
int facescnt;
|
||||
s >> facescnt;
|
||||
std::cout << "f " << facescnt << std::endl;
|
||||
|
||||
std::vector<Face> faces;
|
||||
|
||||
int i;
|
||||
for (i=0; i<facescnt; i++) {
|
||||
std::string l;
|
||||
|
||||
if (getline(f, l)) {
|
||||
std::istringstream stream(l);
|
||||
|
||||
Face face;
|
||||
|
||||
stream >> face;
|
||||
|
||||
faces.push_back(face);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// 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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -245,7 +405,47 @@ void Model::loadAMO(const std::string& filename) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
} else if (prefix == "f") {
|
||||
/*
|
||||
std::vector<std::tuple<int,int,int,int,int,int,int,int,int,int,int,int,int,int,int>> faces;
|
||||
faces = parse_f(stream, file);
|
||||
for (const std::tuple<int,int,int,int,int,int,int,int,int,int,int,int,int,int,int>& i: faces) {
|
||||
std::cout << get<0>(i) << " "
|
||||
<< get<1>(i) << " "
|
||||
<< get<2>(i) << " "
|
||||
<< get<3>(i) << " "
|
||||
<< get<4>(i) << " "
|
||||
<< get<5>(i) << " "
|
||||
<< get<6>(i) << " "
|
||||
<< get<7>(i) << " "
|
||||
<< get<8>(i) << " "
|
||||
<< get<9>(i) << " "
|
||||
<< get<10>(i) << " "
|
||||
<< get<11>(i) << " "
|
||||
<< get<12>(i) << " "
|
||||
<< get<13>(i) << " "
|
||||
<< get<14>(i) << std::endl;
|
||||
}
|
||||
*/
|
||||
std::vector<Face> faces;
|
||||
faces = parse_f(stream, file);
|
||||
for (const Face& i: faces) {
|
||||
for (const int& ii: i.n) {
|
||||
std::cout << ii << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
} else if (prefix == "j") {
|
||||
std::vector<Joint> j;
|
||||
j = parse_j(stream, file);
|
||||
for (const Joint& i: j) {
|
||||
std::cout << i.name << " " << i.x << " ";
|
||||
for (const float& ii: i.n) {
|
||||
std::cout << ii << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user