wrote vn parser
This commit is contained in:
77
src/amo.cpp
77
src/amo.cpp
@@ -6,6 +6,69 @@
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <Collage/types/model.h>
|
||||
|
||||
// Parse Vertex Normals
|
||||
std::vector<std::tuple<float, float, float>> parse_vn(std::istringstream& s, std::ifstream& f) {
|
||||
// Get vertex normals 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;
|
||||
|
||||
// Parse until vncnt
|
||||
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});
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return vn;
|
||||
}
|
||||
|
||||
// Parse Vertex Textures
|
||||
std::vector<std::tuple<float, float>> parse_vt(std::istringstream& s, std::ifstream& f) {
|
||||
// Get vertex textures count
|
||||
int vtcnt;
|
||||
s >> vtcnt;
|
||||
std::cout << "vt " << vtcnt << std::endl;
|
||||
|
||||
// Store our vertex texture coords for returning later
|
||||
std::vector<std::tuple<float, float>> vt;
|
||||
|
||||
// Parse lines until vtcnt
|
||||
int i;
|
||||
for (i=0; i<vtcnt; i++) {
|
||||
std::string l;
|
||||
|
||||
if (getline(f, l)) {
|
||||
std::istringstream stream(l);
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
stream >> x >> y;
|
||||
// For debugging -> std::cout << l << std::endl;
|
||||
|
||||
vt.push_back({x, y});
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return vt;
|
||||
}
|
||||
|
||||
// Parse Vertices
|
||||
std::vector<std::tuple<float, float, float>> parse_v(std::istringstream& s, std::ifstream& f) {
|
||||
// Get vertices count
|
||||
@@ -27,7 +90,7 @@ std::vector<std::tuple<float, float, float>> parse_v(std::istringstream& s, std:
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
stream >> x >> y >> z;
|
||||
std::cout << l << std::endl;
|
||||
// For debugging -> std::cout << l << std::endl;
|
||||
|
||||
v.push_back({x, y, z});
|
||||
} else {
|
||||
@@ -91,6 +154,18 @@ void Model::loadAMO(const std::string& filename) {
|
||||
for (const std::tuple<float, float, float>& i : v) {
|
||||
std::cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << std::endl;
|
||||
}
|
||||
} else if (prefix == "vt") {
|
||||
std::vector<std::tuple<float, float>> vt;
|
||||
vt = parse_vt(stream, file);
|
||||
for (const std::tuple<float, float>& i: vt) {
|
||||
std::cout << get<0>(i) << " " << get<1>(i) << std::endl;
|
||||
}
|
||||
} else if (prefix == "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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user