fleshing out amo parser. Got v N parsable.
This commit is contained in:
101
src/amo.cpp
101
src/amo.cpp
@@ -1,8 +1,103 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <Collage/types/model.h>
|
||||
|
||||
// Parse Vertices
|
||||
std::vector<std::tuple<float, float, float>> parse_v(std::istringstream& s, std::ifstream& f) {
|
||||
// Get vertices count
|
||||
int vcnt;
|
||||
s >> vcnt;
|
||||
std::cout << "v " << vcnt << std::endl;
|
||||
|
||||
// Store our vertices return later
|
||||
std::vector<std::tuple<float, float, float>> v;
|
||||
|
||||
// Parse lines until vcnt
|
||||
int i;
|
||||
for (i=0; i<vcnt; 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;
|
||||
std::cout << l << std::endl;
|
||||
|
||||
v.push_back({x, y, z});
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
// Parse Animated Object
|
||||
std::tuple<std::string, int> parse_ao(std::istringstream& s) {
|
||||
std::string name;
|
||||
int statecnt;
|
||||
s >> name >> statecnt;
|
||||
return {name, statecnt};
|
||||
}
|
||||
|
||||
/*
|
||||
std::string nextline(std::ifstream& f) {
|
||||
std::string l;
|
||||
std::getline(f, l);
|
||||
return l;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void Model::loadAMO(const std::string& filename) {
|
||||
// Print filename
|
||||
std::cout << filename << std::endl;
|
||||
|
||||
// Create ifstream from AMO file
|
||||
std::ifstream file(filename);
|
||||
|
||||
/*
|
||||
// Get next line
|
||||
std::string line;
|
||||
line = nextline(file);
|
||||
std::cout << line << std::endl;
|
||||
|
||||
line = nextline(file);
|
||||
std::cout << line << std::endl;
|
||||
*/
|
||||
|
||||
std::string line;
|
||||
while (getline(file, line)) {
|
||||
//std::cout << line << std::endl;
|
||||
|
||||
// Get prefix
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
|
||||
if (prefix == "ao") {
|
||||
std::tuple<std::string, int> r;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
/*
|
||||
void Model::loadAMO(const std::string& filename) {
|
||||
std::cout << filename << std::endl;
|
||||
std::ifstream file(filename);
|
||||
@@ -26,6 +121,11 @@ void Model::loadAMO(const std::string& filename) {
|
||||
int vcnt;
|
||||
stream >> vcnt;
|
||||
std::cout << "v " << vcnt << std::endl;
|
||||
for (int i=0; i<=vcnt; i++) {
|
||||
Vector3 v;
|
||||
v = parse_v(stream);
|
||||
std::cout << v.x << " " << v.y << " " << v.z << std::endl;
|
||||
}
|
||||
// Vertex Texture Count
|
||||
} else if (prefix == "vt") {
|
||||
int vtcnt;
|
||||
@@ -82,3 +182,4 @@ void Model::loadAMO(const std::string& filename) {
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user