animation parsing underway

This commit is contained in:
maxbyte9p
2024-05-21 15:46:59 -04:00
parent 87ce88c02a
commit 2fb62d38ce

View File

@@ -7,6 +7,149 @@
#include <J3ML/LinearAlgebra.h>
#include <Collage/types/model.h>
struct Frame {
int id;
std::vector<float> n;
};
void operator>>(std::istream& in, Frame& q) {
in >> q.id;
int i;
for (i=0; i<7; i++) {
float v;
in >> v;
q.n.push_back(v);
}
}
struct KeyFrame {
float start;
int frame_cnt;
};
void operator>>(std::istream& in, KeyFrame& q) {
// throw away prefix
std::string p;
in >> p;
in >> q.start;
in >> q.frame_cnt;
}
struct FrameSet {
KeyFrame k;
std::vector<Frame> f;
};
FrameSet parse_fs(std::istringstream& s, std::ifstream& f) {
FrameSet fs;
s >> fs.k;
int i;
for (i=0; i<fs.k.frame_cnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
Frame frame;
stream >> frame;
fs.f.push_back(frame);
} else {
break;
}
}
return fs;
}
/*
void operator>>(std::istream& in, FrameSet& q) {
in >> q.k;
int i;
for (i=0; i<q.k.frame_cnt; i++) {
Frame f;
in >> f;
q.f.push_back(f);
}
}
*/
struct Animation_Meta {
std::string name;
int duration;
int keyframe_cnt;
};
void operator>>(std::istream& in, Animation_Meta& q) {
// throw away prefix
std::string p;
in >> p;
in >> q.name;
in >> q.duration;
in >> q.keyframe_cnt;
}
struct Animation {
Animation_Meta meta;
std::vector<FrameSet> fs;
};
// Parse animations
std::vector<Animation> parse_a(std::istringstream& s, std::ifstream& f) {
int acnt;
s >> acnt;
std::cout << "a " << acnt << std::endl;
std::vector<Animation> a;
int i;
for (i=0; i<acnt; i++) {
std::string l;
if (getline(f, l)) {
std::istringstream stream(l);
Animation animation;
stream >> animation.meta;
int i;
for (i=0; i<animation.meta.keyframe_cnt; i++) {
std::string ll;
getline(f, ll);
std::istringstream stream(ll);
FrameSet frameset;
frameset = parse_fs(stream, f);
animation.fs.push_back(frameset);
}
a.push_back(animation);
} else {
break;
}
}
return a;
}
struct Joint {
std::string name;
int x;
@@ -391,8 +534,6 @@ void Model::loadAMO(const std::string& filename) {
}
std::cout << std::endl;
}
} else if (prefix == "f") {
std::vector<Face> faces;
faces = parse_f(stream, file);
@@ -412,8 +553,24 @@ void Model::loadAMO(const std::string& filename) {
}
std::cout << std::endl;
}
}
} else if (prefix == "a") {
std::vector<Animation> a;
a = parse_a(stream, file);
for (const Animation& i: a) {
std::cout << i.meta.name << " " << i.meta.duration << " " << i.meta.keyframe_cnt << std::endl;
for (const FrameSet& ii: i.fs) {
std::cout << "k " << ii.k.start << " " << ii.k.frame_cnt << std::endl;
/* for (const Frame& iii: ii.f) {
std::cout << iii.id << " ";
for (const float& iiii: iii.n) {
std::cout << iiii << " ";
}
std::cout << std::endl;
}*/
}
}
}
}
file.close();